(c *context.Context)
| 205 | } |
| 206 | |
| 207 | func LoginTwoFactorPost(c *context.Context) { |
| 208 | userID, ok := c.Session.Get("twoFactorUserID").(int64) |
| 209 | if !ok { |
| 210 | c.NotFound() |
| 211 | return |
| 212 | } |
| 213 | |
| 214 | t, err := database.Handle.TwoFactors().GetByUserID(c.Req.Context(), userID) |
| 215 | if err != nil { |
| 216 | c.Error(err, "get two factor by user ID") |
| 217 | return |
| 218 | } |
| 219 | |
| 220 | passcode := c.Query("passcode") |
| 221 | valid, err := t.ValidateTOTP(passcode) |
| 222 | if err != nil { |
| 223 | c.Error(err, "validate TOTP") |
| 224 | return |
| 225 | } else if !valid { |
| 226 | c.Flash.Error(c.Tr("settings.two_factor_invalid_passcode")) |
| 227 | c.RedirectSubpath("/user/login/two_factor") |
| 228 | return |
| 229 | } |
| 230 | |
| 231 | u, err := database.Handle.Users().GetByID(c.Req.Context(), userID) |
| 232 | if err != nil { |
| 233 | c.Error(err, "get user by ID") |
| 234 | return |
| 235 | } |
| 236 | |
| 237 | // Prevent same passcode from being reused |
| 238 | if c.Cache.IsExist(userutil.TwoFactorCacheKey(u.ID, passcode)) { |
| 239 | c.Flash.Error(c.Tr("settings.two_factor_reused_passcode")) |
| 240 | c.RedirectSubpath("/user/login/two_factor") |
| 241 | return |
| 242 | } |
| 243 | if err = c.Cache.Put(userutil.TwoFactorCacheKey(u.ID, passcode), 1, 60); err != nil { |
| 244 | log.Error("Failed to put cache 'two factor passcode': %v", err) |
| 245 | } |
| 246 | |
| 247 | afterLogin(c, u, c.Session.Get("twoFactorRemember").(bool)) |
| 248 | } |
| 249 | |
| 250 | func LoginTwoFactorRecoveryCode(c *context.Context) { |
| 251 | _, ok := c.Session.Get("twoFactorUserID").(int64) |
nothing calls this directly
no test coverage detected