@@ -270,6 +270,48 @@ func accountView(app *config.Application) http.HandlerFunc {
270
270
}
271
271
}
272
272
273
+ type accountPasswordUpdateForm struct {
274
+ CurrentPassword string `form:"password"`
275
+ NewPassword string `form:"password"`
276
+ NewPasswordConfirmation string `form:"password"`
277
+ validator.Validator `form:"-"`
278
+ }
279
+
280
+ func accountPasswordUpdate (app * config.Application ) http.HandlerFunc {
281
+ return func (w http.ResponseWriter , r * http.Request ) {
282
+ data := app .NewTemplateData (r )
283
+ data .Form = accountPasswordUpdateForm {}
284
+ app .Render (w , http .StatusOK , "password.tmpl" , data )
285
+ }
286
+ }
287
+
288
+ func accountPasswordUpdatePost (app * config.Application ) http.HandlerFunc {
289
+ return func (w http.ResponseWriter , r * http.Request ) {
290
+ var form accountPasswordUpdateForm
291
+
292
+ err := app .DecodePostForm (r , & form )
293
+ if err != nil {
294
+ app .ClientError (w , http .StatusBadRequest )
295
+ return
296
+ }
297
+
298
+ form .CheckField (validator .NotBlank (form .CurrentPassword ), "currentPassword" , "This field cannot be blank" )
299
+ form .CheckField (validator .NotBlank (form .NewPassword ), "newPassword" , "This field cannot be blank" )
300
+ form .CheckField (validator .NotBlank (form .NewPasswordConfirmation ), "newPasswordConfirmation" , "This field cannot be blank" )
301
+ form .CheckField (validator .MinChars (form .CurrentPassword , 8 ), "currentPassword" , "This field must be at least 8 characters" )
302
+ form .CheckField (validator .MinChars (form .NewPassword , 8 ), "newPassword" , "This field must must be at least 8 characters" )
303
+ form .CheckField (validator .MinChars (form .NewPasswordConfirmation , 8 ), "newPasswordConfirmation" , "This field must be at least 8 characters" )
304
+
305
+ if ! form .Valid () {
306
+ data := app .NewTemplateData (r )
307
+ data .Form = form
308
+ app .Render (w , http .StatusUnprocessableEntity , "password.tmpl" , data )
309
+ return
310
+ }
311
+
312
+ }
313
+ }
314
+
273
315
func ping (w http.ResponseWriter , r * http.Request ) {
274
316
w .Write ([]byte ("OK" ))
275
317
}
0 commit comments