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

Method Login

controllers/AcountController.go:228–307  ·  view source on GitHub ↗

Login 用户登录.

()

Source from the content-addressed store, hash-verified

226
227// Login 用户登录.
228func (this *AccountController) Login() {
229 var (
230 remember CookieRemember
231 captchaOn bool //是否开启了验证码
232 )
233
234 this.TplName = "account/login.html"
235
236 //如果开启了验证码
237 if v, ok := this.Option["ENABLED_CAPTCHA"]; ok && strings.EqualFold(v, "true") {
238 captchaOn = true
239 this.Data["CaptchaOn"] = captchaOn
240 }
241
242 oauthLogin := false
243 if v, ok := this.Option["LOGIN_QQ"]; ok && strings.EqualFold(v, "true") {
244 this.Data["LoginQQ"] = true
245 oauthLogin = true
246 }
247 if v, ok := this.Option["LOGIN_GITHUB"]; ok && strings.EqualFold(v, "true") {
248 this.Data["LoginGitHub"] = true
249 oauthLogin = true
250 }
251 if v, ok := this.Option["LOGIN_GITEE"]; ok && strings.EqualFold(v, "true") {
252 this.Data["LoginGitee"] = true
253 oauthLogin = true
254 }
255 this.Data["OauthLogin"] = oauthLogin
256
257 //如果Cookie中存在登录信息
258 if cookie, ok := this.GetSecureCookie(conf.GetAppKey(), "login"); ok {
259 if err := utils.Decode(cookie, &remember); err == nil {
260 if err = this.loginByMemberId(remember.MemberId); err == nil {
261 this.Redirect(beego.URLFor("HomeController.Index"), 302)
262 return
263 }
264 }
265 }
266
267 if this.Ctx.Input.IsPost() {
268 account := this.GetString("account")
269 password := this.GetString("password")
270
271 if captchaOn && !cpt.VerifyReq(this.Ctx.Request) {
272 this.JsonResult(1, "验证码不正确")
273 }
274
275 member, err := models.NewMember().Login(account, password)
276
277 //如果没有数据
278 if err != nil {
279 beego.Error("用户登录 =>", err)
280 this.JsonResult(500, "账号或密码错误", nil)
281 }
282 member.LastLoginTime = time.Now()
283 member.Update()
284 this.SetMember(*member)
285 remember.MemberId = member.MemberId

Callers 3

BindMethod · 0.45
DeleteMethod · 0.45
DeleteBookMethod · 0.45

Calls 9

GetAppKeyFunction · 0.92
DecodeFunction · 0.92
NewMemberFunction · 0.92
EncodeFunction · 0.92
loginByMemberIdMethod · 0.80
JsonResultMethod · 0.80
SetMemberMethod · 0.80
GetSeoByPageMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected