MCPcopy Create free account
hub / github.com/gogs/gogs / SettingsTwoFactorEnablePost

Function SettingsTwoFactorEnablePost

internal/route/user/setting.go:449–472  ·  view source on GitHub ↗
(c *context.Context)

Source from the content-addressed store, hash-verified

447}
448
449func SettingsTwoFactorEnablePost(c *context.Context) {
450 secret, ok := c.Session.Get("twoFactorSecret").(string)
451 if !ok {
452 c.NotFound()
453 return
454 }
455
456 if !totp.Validate(c.Query("passcode"), secret) {
457 c.Flash.Error(c.Tr("settings.two_factor_invalid_passcode"))
458 c.RedirectSubpath("/user/settings/security/two_factor_enable")
459 return
460 }
461
462 if err := database.Handle.TwoFactors().Create(c.Req.Context(), c.UserID(), conf.Security.SecretKey, secret); err != nil {
463 c.Flash.Error(c.Tr("settings.two_factor_enable_error", err))
464 c.RedirectSubpath("/user/settings/security/two_factor_enable")
465 return
466 }
467
468 _ = c.Session.Delete("twoFactorSecret")
469 _ = c.Session.Delete("twoFactorURL")
470 c.Flash.Success(c.Tr("settings.two_factor_enable_success"))
471 c.RedirectSubpath("/user/settings/security/two_factor_recovery_codes")
472}
473
474func SettingsTwoFactorRecoveryCodes(c *context.Context) {
475 if !database.Handle.TwoFactors().IsEnabled(c.Req.Context(), c.User.ID) {

Callers

nothing calls this directly

Calls 11

TrMethod · 0.80
RedirectSubpathMethod · 0.80
TwoFactorsMethod · 0.80
UserIDMethod · 0.80
DeleteMethod · 0.80
SuccessMethod · 0.80
GetMethod · 0.65
NotFoundMethod · 0.65
ValidateMethod · 0.45
ErrorMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected