Add CheckUserPassword() API.

This commit is contained in:
Yang Luo 2021-08-15 21:57:36 +08:00
parent 8674b4853a
commit 398ba19fa5
5 changed files with 19 additions and 3 deletions

View File

@ -185,7 +185,7 @@ func (c *ApiController) Login() {
}
} else {
password := form.Password
user, msg = object.CheckUserLogin(form.Organization, form.Username, password)
user, msg = object.CheckUserPassword(form.Organization, form.Username, password)
}
if msg != "" {

View File

@ -231,3 +231,18 @@ func (c *ApiController) SetPassword() {
c.Data["json"] = Response{Status: "ok"}
c.ServeJSON()
}
func (c *ApiController) CheckUserPassword() {
var user object.User
err := json.Unmarshal(c.Ctx.Input.RequestBody, &user)
if err != nil {
panic(err)
}
_, msg := object.CheckUserPassword(user.Owner, user.Name, user.Password)
if msg == "" {
c.ResponseOk()
} else {
c.ResponseError(msg)
}
}

View File

@ -101,7 +101,7 @@ func CheckPassword(user *User, password string) string {
}
}
func CheckUserLogin(organization string, username string, password string) (*User, string) {
func CheckUserPassword(organization string, username string, password string) (*User, string) {
user := GetUserByFields(organization, username)
if user == nil {
return nil, "the user does not exist, please sign up first"

View File

@ -83,7 +83,7 @@ func AutoSigninFilter(ctx *context.Context) {
password := queryMap.Get("password")
if userId != "" && password != "" {
owner, name := util.GetOwnerAndNameFromId(userId)
_, msg := object.CheckUserLogin(owner, name, password)
_, msg := object.CheckUserPassword(owner, name, password)
if msg != "" {
returnRequest(ctx, msg)
return

View File

@ -61,6 +61,7 @@ func initAPI() {
beego.Router("/api/delete-user", &controllers.ApiController{}, "POST:DeleteUser")
beego.Router("/api/set-password", &controllers.ApiController{}, "POST:SetPassword")
beego.Router("/api/check-user-password", &controllers.ApiController{}, "POST:CheckUserPassword")
beego.Router("/api/get-email-and-phone", &controllers.ApiController{}, "POST:GetEmailAndPhone")
beego.Router("/api/send-verification-code", &controllers.ApiController{}, "POST:SendVerificationCode")
beego.Router("/api/reset-email-or-phone", &controllers.ApiController{}, "POST:ResetEmailOrPhone")