From 7548037a64fd42bf11ad0d11a49fc3ae8dc731ff Mon Sep 17 00:00:00 2001
From: John Olheiser <42128690+jolheiser@users.noreply.github.com>
Date: Wed, 27 Feb 2019 13:37:57 -0600
Subject: [PATCH] Adds MustChangePassword to user create/edit API, defaults to
 true (#6193)

Signed-off-by: jolheiser <john.olheiser@gmail.com>
---
 Gopkg.lock                                   |  4 ++--
 routers/api/v1/admin/user.go                 | 20 ++++++++++++++------
 vendor/code.gitea.io/sdk/gitea/admin_user.go |  4 ++--
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/Gopkg.lock b/Gopkg.lock
index 9c53d8af35..05d54a2332 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -11,11 +11,11 @@
 
 [[projects]]
   branch = "master"
-  digest = "1:784d7948aaae61b9fe50aa15c69a62fb277268a47ed006748a7e25fa61b841c9"
+  digest = "1:59b2036a2d4b51fc91018adebd33ec4a893aa2b11af3a606445fe8df5640f514"
   name = "code.gitea.io/sdk"
   packages = ["gitea"]
   pruneopts = "NUT"
-  revision = "4a15722a627a9cf62a203a066e724e82556b3845"
+  revision = "9c4f6485997bcff568e30cfe45165018ac5772c1"
 
 [[projects]]
   digest = "1:5d72bbcc9c8667b11c3dc3cbe681c5a6f71e5096744c0bf7726ab5c6425d5dc4"
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index e35beffc92..cf52d649ad 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -56,12 +56,16 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
 	//   "422":
 	//     "$ref": "#/responses/validationError"
 	u := &models.User{
-		Name:      form.Username,
-		FullName:  form.FullName,
-		Email:     form.Email,
-		Passwd:    form.Password,
-		IsActive:  true,
-		LoginType: models.LoginPlain,
+		Name:               form.Username,
+		FullName:           form.FullName,
+		Email:              form.Email,
+		Passwd:             form.Password,
+		MustChangePassword: true,
+		IsActive:           true,
+		LoginType:          models.LoginPlain,
+	}
+	if form.MustChangePassword != nil {
+		u.MustChangePassword = *form.MustChangePassword
 	}
 
 	parseLoginSource(ctx, u, form.SourceID, form.LoginName)
@@ -135,6 +139,10 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
 		u.HashPassword(form.Password)
 	}
 
+	if form.MustChangePassword != nil {
+		u.MustChangePassword = *form.MustChangePassword
+	}
+
 	u.LoginName = form.LoginName
 	u.FullName = form.FullName
 	u.Email = form.Email
diff --git a/vendor/code.gitea.io/sdk/gitea/admin_user.go b/vendor/code.gitea.io/sdk/gitea/admin_user.go
index a87ae89d44..a4df703b17 100644
--- a/vendor/code.gitea.io/sdk/gitea/admin_user.go
+++ b/vendor/code.gitea.io/sdk/gitea/admin_user.go
@@ -23,7 +23,7 @@ type CreateUserOption struct {
 	Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
 	// required: true
 	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"`
 }
 
@@ -46,7 +46,7 @@ type EditUserOption struct {
 	// swagger:strfmt email
 	Email                   string `json:"email" binding:"Required;Email;MaxSize(254)"`
 	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)"`
 	Location                string `json:"location" binding:"MaxSize(50)"`
 	Active                  *bool  `json:"active"`