Feat: user activation by Email

pull/247/head
HFO4 5 years ago
parent 81d6988a50
commit 7027a96258

@ -151,6 +151,17 @@ func User2FALogin(c *gin.Context) {
}
}
// UserActivate 用户激活
func UserActivate(c *gin.Context) {
var service user.SettingService
if err := c.ShouldBindUri(&service); err == nil {
res := service.Activate(c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}
// UserQQLogin 初始化QQ登录
func UserQQLogin(c *gin.Context) {
// 新建绑定

@ -105,8 +105,14 @@ func InitMasterRouter() *gin.Engine {
user.POST("session", controllers.UserLogin)
// 用户注册
user.POST("", middleware.IsFunctionEnabled("register_enabled"), controllers.UserRegister)
// 用户登录
// 用二步验证户登录
user.POST("2fa", controllers.User2FALogin)
// 邮件激活
user.GET("activate/:id",
middleware.SignRequired(),
middleware.HashID(hashid.UserID),
controllers.UserActivate,
)
// 初始化QQ登录
user.POST("qq", controllers.UserQQLogin)
// WebAuthn登陆初始化

@ -91,3 +91,23 @@ func (service *UserRegisterService) Register(c *gin.Context) serializer.Response
return serializer.Response{}
}
// Activate 激活用户
func (service *SettingService) Activate(c *gin.Context) serializer.Response {
// 查找待激活用户
uid, _ := c.Get("object_id")
user, err := model.GetUserByID(uid.(uint))
if err != nil {
return serializer.Err(serializer.CodeNotFound, "用户不存在", err)
}
// 检查状态
if user.Status != model.NotActivicated {
return serializer.Err(serializer.CodeNoPermissionErr, "该用户无法被激活", nil)
}
// 激活用户
user.SetStatus(model.Active)
return serializer.Response{Data: user.Email}
}

Loading…
Cancel
Save