@@ -51,11 +51,14 @@ func (controller *Controller) Users(c echo.Context) error {
5151 return c .Redirect (http .StatusFound , fmt .Sprintf ("/users/read/%v" , user .ID ))
5252 }
5353
54- var users []models.User
55- var err error
54+ var (
55+ users []models.User
56+ err error
57+
58+ // typing: all, admin and user
59+ typing string
60+ )
5661
57- // typing: all, admin and user
58- var typing string
5962 if c .QueryParam ("admin" ) == "all" {
6063 log .Infof (`for GET to users admin models.User{}.FindAll(db, "admin")` )
6164 typing = "Admin"
@@ -305,7 +308,7 @@ func (controller *Controller) ReadUser(c echo.Context) error {
305308 "for GET to read user without models.User{}.FirstByID() errors: `%v`" , err ,
306309 )
307310 log .Warn ("END request method GET for read user: [-]failure" )
308- // HTTP response status: 405 Method Not Allowed
311+ // HTTP response status: 406 Method Not Acceptable
309312 return c .HTML (http .StatusNotAcceptable , err .Error ())
310313 }
311314
@@ -370,7 +373,11 @@ func (controller *Controller) UpdateUser(c echo.Context) error {
370373 // admin: yes
371374 // (IsUser and (not user.Username)): 403 Forbidden
372375 if middleware .IsUser (is_auth_type ) && (user .Username != session .Values ["username" ]) {
373- log .Warn ("IsUser and (not user.Username): 403 Forbidden" )
376+ log .Warnf (
377+ "IsUser (%v) and [not user.Username (%v)]: 403 Forbidden" ,
378+ middleware .IsUser (is_auth_type ),
379+ (user .Username != session .Values ["username" ]),
380+ )
374381 log .Warn ("END request method GET for update user: [-]failure" )
375382 return c .HTML (http .StatusForbidden , "403 Forbidden" )
376383 }
@@ -508,15 +515,13 @@ func (controller *Controller) UpdateUserByPassword(c echo.Context) error {
508515 controller .DB , id , session .Values ["username" ].(string ),
509516 )
510517
511- if ! middleware .IsAdmin (is_auth_type ) {
512- if err != nil {
513- log .Warnf (
514- "for GET to update user by password without models.User{}.FirstByIDAndUsername() errors: `%v`" , err ,
515- )
516- log .Warn ("END request method GET for update user by password: [-]failure" )
517- // HTTP response status: 403 Forbidden
518- return c .HTML (http .StatusForbidden , err .Error ())
519- }
518+ if middleware .IsUser (is_auth_type ) && err != nil {
519+ log .Warnf (
520+ "for GET to update user by password without models.User{}.FirstByIDAndUsername() errors: `%v`" , err ,
521+ )
522+ log .Warn ("END request method GET for update user by password: [-]failure" )
523+ // HTTP response status: 403 Forbidden
524+ return c .HTML (http .StatusForbidden , err .Error ())
520525 }
521526
522527 if c .Request ().Method == "POST" {
@@ -527,8 +532,11 @@ func (controller *Controller) UpdateUserByPassword(c echo.Context) error {
527532 ConfirmNewPassword : c .FormValue ("confirm_new_password" ),
528533 }
529534
530- if ! middleware .IsAdmin (is_auth_type ) && ! middleware .CheckHashPassword (user .Password , _newPasswordForm .OldPassword ) {
531- log .Warnf ("for POST to update user by password without !middleware.CheckHashPassword() errors: `%v`" , err )
535+ if ! middleware .CheckHashPassword (user .Password , _newPasswordForm .OldPassword ) {
536+ log .Warnf (
537+ "for POST to update user by password without check hash password (%v): 403 Forbidden" ,
538+ middleware .CheckHashPassword (user .Password , _newPasswordForm .OldPassword ),
539+ )
532540 middleware .SetFlashError (c , "check hash password is wrong!" )
533541 log .Warn ("END request method POST for update user by password: [-]failure" )
534542 return c .Render (http .StatusForbidden , "user-view-password.html" , echo.Map {
0 commit comments