@@ -15,6 +15,26 @@ import (
1515 "github.com/google/uuid"
1616)
1717
18+ // ErrorBadRequestResponse represents the standard error format for bad request API responses.
19+ //
20+ // @name ErrorBadRequestResponse
21+ // @description Standard error response format returned by all bad request API endpoints
22+ type ErrorBadRequestResponse struct {
23+ Success bool `json:"success" example:"false"`
24+ Message string `json:"message" example:"It show error from err.Error()"`
25+ Status int `json:"status" example:"400"`
26+ }
27+
28+ // ErrorInternalServerResponse represents the standard error format for internal server API responses.
29+ //
30+ // @name ErrorInternalServerResponse
31+ // @description Standard error response format returned by all internal server error API endpoints
32+ type ErrorInternalServerResponse struct {
33+ Success bool `json:"success" example:"false"`
34+ Message string `json:"message" example:"the server encountered a problem"`
35+ Status int `json:"status" example:"500"`
36+ }
37+
1838type RegisterUserPayload struct {
1939 FirstName string `json:"first_name" validate:"required,max=50"`
2040 LastName string `json:"last_name" validate:"required,max=50"`
@@ -32,14 +52,16 @@ type UserWithToken struct {
3252// registerUserHandler godoc
3353//
3454// @Summary Registers a user
35- // @Description Registers a user
55+ // @Description Registers a user via Mobile App, Server will send activation url on email and need to click there to verify its your email
3656// @Tags authentication
3757// @Accept json
3858// @Produce json
39- // @Param payload body RegisterUserPayload true "User credentials"
40- // @Success 201 {object} UserWithToken "User registered"
41- // @Failure 400 {object} error
42- // @Failure 500 {object} error
59+ // @Param payload body RegisterUserPayload true "User credentials"
60+ // @Success 201 {object} UserWithToken "User registered"
61+ //
62+ // @Failure 400 {object} ErrorBadRequestResponse "Bad request"
63+ // @Failure 500 {object} ErrorInternalServerResponse "Internal Server Error"
64+ //
4365// @Router /authentication/user [post]
4466func (app * application ) registerUserHandler (w http.ResponseWriter , r * http.Request ) {
4567 var payload RegisterUserPayload
@@ -89,7 +111,7 @@ func (app *application) registerUserHandler(w http.ResponseWriter, r *http.Reque
89111 Token : plainToken ,
90112 }
91113
92- activationURL := fmt .Sprintf ("%s/confirm/ %s" , app .config .frontendURL , plainToken )
114+ activationURL := fmt .Sprintf ("%s/confirm?token= %s" , app .config .frontendURL , plainToken )
93115
94116 isProdEnv := app .config .env == "production"
95117 vars := struct {
@@ -396,7 +418,7 @@ func (app *application) requestResetPasswordHandler(w http.ResponseWriter, r *ht
396418 }
397419
398420 // Send reset email
399- resetURL := fmt .Sprintf ("%s/reset-password/%s" , app .config .frontendURL , resetToken )
421+ resetURL := fmt .Sprintf ("%s/reset-password/?token= %s" , app .config .frontendURL , resetToken )
400422
401423 vars := struct {
402424 Username string
@@ -416,7 +438,10 @@ func (app *application) requestResetPasswordHandler(w http.ResponseWriter, r *ht
416438
417439 app .logger .Infow ("Reset password email sent" , "status code" , status )
418440
419- if err := app .jsonResponse (w , http .StatusOK , map [string ]string {"message" : "Reset token sent" }); err != nil {
441+ if err := app .jsonResponse (w , http .StatusOK , map [string ]string {
442+ "message" : "Reset token sent" ,
443+ "resetToken" : resetToken , // unhashed token
444+ }); err != nil {
420445 app .internalServerError (w , r , err )
421446 }
422447}
@@ -455,6 +480,7 @@ func (app *application) resetPasswordHandler(w http.ResponseWriter, r *http.Requ
455480 // Hash the token to compare with the stored hash
456481 hash := sha256 .Sum256 ([]byte (payload .Token ))
457482 hashToken := hex .EncodeToString (hash [:])
483+ fmt .Printf ("this is hashToken: %s" , hashToken )
458484
459485 // Get user by reset token
460486 user , err := app .store .Users .GetByResetToken (ctx , hashToken )
@@ -464,6 +490,7 @@ func (app *application) resetPasswordHandler(w http.ResponseWriter, r *http.Requ
464490 return
465491 }
466492 app .internalServerError (w , r , err )
493+ fmt .Println (err )
467494 return
468495 }
469496
@@ -490,6 +517,7 @@ func (app *application) resetPasswordHandler(w http.ResponseWriter, r *http.Requ
490517 // Save the updated user
491518 if err := app .store .Users .Update (ctx , user ); err != nil {
492519 app .internalServerError (w , r , err )
520+ fmt .Println (err )
493521 return
494522 }
495523
0 commit comments