mirror of
https://github.com/go-gitea/gitea
synced 2025-07-18 00:08:35 +00:00
committed by
Lunny Xiao
parent
0acaa6bd00
commit
ba12463175
@@ -110,6 +110,28 @@ func (ctx *APIContext) RequireCSRF() {
|
||||
}
|
||||
}
|
||||
|
||||
// CheckForOTP validateds OTP
|
||||
func (ctx *APIContext) CheckForOTP() {
|
||||
otpHeader := ctx.Req.Header.Get("X-Gitea-OTP")
|
||||
twofa, err := models.GetTwoFactorByUID(ctx.Context.User.ID)
|
||||
if err != nil {
|
||||
if models.IsErrTwoFactorNotEnrolled(err) {
|
||||
return // No 2FA enrollment for this user
|
||||
}
|
||||
ctx.Context.Error(500)
|
||||
return
|
||||
}
|
||||
ok, err := twofa.ValidateTOTP(otpHeader)
|
||||
if err != nil {
|
||||
ctx.Context.Error(500)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
ctx.Context.Error(401)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// APIContexter returns apicontext as macaron middleware
|
||||
func APIContexter() macaron.Handler {
|
||||
return func(c *Context) {
|
||||
|
Reference in New Issue
Block a user