用户登录
()
| 250 | |
| 251 | //用户登录 |
| 252 | func (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 | //用户退出登录 |
| 307 | func (this *UserController) Logout() { |
nothing calls this directly
no test coverage detected