MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Login

Method Login

controllers/HomeControllers/UserController.go:252–304  ·  view source on GitHub ↗

用户登录

()

Source from the content-addressed store, hash-verified

250
251//用户登录
252func (this *UserController) Login() {
253
254 if this.IsLogin > 0 {
255 this.Redirect("/user", 302)
256 return
257 }
258
259 // GET 请求
260 if this.Ctx.Request.Method == "GET" {
261 this.Data["Seo"] = models.NewSeo().GetByPage("PC-Login", "会员登录", "会员登录", "会员登录", this.Sys.Site)
262 this.Data["IsUser"] = true
263 this.Data["PageId"] = "wenku-reg"
264 this.TplName = "login.html"
265 return
266 }
267
268 type Post struct {
269 Email, Password string
270 }
271
272 var post struct {
273 Email, Password string
274 }
275
276 this.ParseForm(&post)
277 valid := validation.Validation{}
278 res := valid.Email(post.Email, "Email")
279 if !res.Ok {
280 this.ResponseJson(false, "登录失败,邮箱格式不正确")
281 }
282
283 ModelUser := models.NewUser()
284 users, rows, err := ModelUser.UserList(1, 1, "", "", "u.`email`=? and u.`password`=?", post.Email, helper.MD5Crypt(post.Password))
285 if rows == 0 || err != nil {
286 if err != nil {
287 helper.Logger.Error(err.Error())
288 }
289 this.ResponseJson(false, "登录失败,邮箱或密码不正确")
290 }
291
292 user := users[0]
293 this.IsLogin = helper.Interface2Int(user["Id"])
294
295 if this.IsLogin > 0 {
296 //查询用户有没有被封禁
297 if info := ModelUser.UserInfo(this.IsLogin); info.Status == false { //被封禁了
298 this.ResponseJson(false, "登录失败,您的账号已被管理员禁用")
299 }
300 this.BaseController.SetCookieLogin(this.IsLogin)
301 this.ResponseJson(true, "登录成功")
302 }
303 this.ResponseJson(false, "登录失败,未知错误!")
304}
305
306//用户退出登录
307func (this *UserController) Logout() {

Callers

nothing calls this directly

Calls 6

UserListMethod · 0.95
UserInfoMethod · 0.95
GetByPageMethod · 0.80
ParseFormMethod · 0.80
SetCookieLoginMethod · 0.80
ResponseJsonMethod · 0.45

Tested by

no test coverage detected