Adds MustChangePassword to user create/edit API, defaults to true (#6193)

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
John Olheiser 2019-02-27 13:37:57 -06:00 committed by Lauris BH
parent b1ffe7e47b
commit 7548037a64
3 changed files with 18 additions and 10 deletions

4
Gopkg.lock generated
View File

@ -11,11 +11,11 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:784d7948aaae61b9fe50aa15c69a62fb277268a47ed006748a7e25fa61b841c9" digest = "1:59b2036a2d4b51fc91018adebd33ec4a893aa2b11af3a606445fe8df5640f514"
name = "code.gitea.io/sdk" name = "code.gitea.io/sdk"
packages = ["gitea"] packages = ["gitea"]
pruneopts = "NUT" pruneopts = "NUT"
revision = "4a15722a627a9cf62a203a066e724e82556b3845" revision = "9c4f6485997bcff568e30cfe45165018ac5772c1"
[[projects]] [[projects]]
digest = "1:5d72bbcc9c8667b11c3dc3cbe681c5a6f71e5096744c0bf7726ab5c6425d5dc4" digest = "1:5d72bbcc9c8667b11c3dc3cbe681c5a6f71e5096744c0bf7726ab5c6425d5dc4"

View File

@ -56,12 +56,16 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
u := &models.User{ u := &models.User{
Name: form.Username, Name: form.Username,
FullName: form.FullName, FullName: form.FullName,
Email: form.Email, Email: form.Email,
Passwd: form.Password, Passwd: form.Password,
IsActive: true, MustChangePassword: true,
LoginType: models.LoginPlain, IsActive: true,
LoginType: models.LoginPlain,
}
if form.MustChangePassword != nil {
u.MustChangePassword = *form.MustChangePassword
} }
parseLoginSource(ctx, u, form.SourceID, form.LoginName) parseLoginSource(ctx, u, form.SourceID, form.LoginName)
@ -135,6 +139,10 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
u.HashPassword(form.Password) u.HashPassword(form.Password)
} }
if form.MustChangePassword != nil {
u.MustChangePassword = *form.MustChangePassword
}
u.LoginName = form.LoginName u.LoginName = form.LoginName
u.FullName = form.FullName u.FullName = form.FullName
u.Email = form.Email u.Email = form.Email

View File

@ -23,7 +23,7 @@ type CreateUserOption struct {
Email string `json:"email" binding:"Required;Email;MaxSize(254)"` Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
// required: true // required: true
Password string `json:"password" binding:"Required;MaxSize(255)"` Password string `json:"password" binding:"Required;MaxSize(255)"`
MustChangePassword bool `json:"must_change_password"` MustChangePassword *bool `json:"must_change_password"`
SendNotify bool `json:"send_notify"` SendNotify bool `json:"send_notify"`
} }
@ -46,7 +46,7 @@ type EditUserOption struct {
// swagger:strfmt email // swagger:strfmt email
Email string `json:"email" binding:"Required;Email;MaxSize(254)"` Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
Password string `json:"password" binding:"MaxSize(255)"` Password string `json:"password" binding:"MaxSize(255)"`
MustChangePassword bool `json:"must_change_password"` MustChangePassword *bool `json:"must_change_password"`
Website string `json:"website" binding:"MaxSize(50)"` Website string `json:"website" binding:"MaxSize(50)"`
Location string `json:"location" binding:"MaxSize(50)"` Location string `json:"location" binding:"MaxSize(50)"`
Active *bool `json:"active"` Active *bool `json:"active"`