[FEAT][API] Add reset password API
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Description
Add an API to reset the password.
Request
Method
POST
URL
/login/reset_password
Request Parameters
| Parameter | Description | Required | Example |
|---|---|---|---|
| Email address of the user | Yes | username@example.com | |
| new_password | New password of the user | Yes | newpassword |
| new_password_repeated | Repeated new password of the user | Yes | newpassword |
| token | Token received in email | Yes | 123456 |
Request Body
None
Result
Result parameters
None
Result Body
Empty response body
Example Curl Request
$ curl -X POST http://localhost:8080/login/reset_password \
-H "Content-Type: application/json" \
-d '{"email": "username@example.com", "new_password": "newpassword", "new_password_repeated": "newpassword", "token": "123456"}'
Curl Response
HTTP/1.1 200 OK
Content-Length: 0
Go server
Struct
type ResetPasswordRequest struct {
Email string `json:"email"`
NewPassword string `json:"new_password"`
NewPasswordRepeated string `json:"new_password_repeated"`
Token string `json:"token"`
}
Handler
func (s *Server) resetPassword(w http.ResponseWriter, r *http.Request) {
var req ResetPasswordRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := s.srv.ResetPassword(r.Context(), req.Email, req.NewPassword, req.NewPasswordRepeated, req.Token); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.WriteHeader(http.StatusOK)
}
```s *service) resetPassword(w http.ResponseWriter, r *http.Request) {
var req ResetPasswordRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}
if err := s.usr.ResetPassword(req.Email, req.NewPassword, req.NewPasswordRepeated, req.Token); err != nil {
switch err {
case usr.ErrUserNotFound, usr.ErrInvalidToken:
http.Error(w, "User not found or invalid token", http.StatusUnauthorized)
case usr.ErrPasswordTooShort, usr.ErrPasswordsDoNotMatch:
http.Error(w, "Invalid password", http.StatusBadRequest)
default:
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
return
}
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(map[string]bool{"success": true}); err != nil {
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
}
Links
Automated Issue Details
Dear visitor,
This issue has been automatically generated from the Octopize project avatar-python to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.
Best regards,
The SIGO Team
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the requested POST /login/reset_password contract with the linked avatar-python Auth.reset_password implementation. Then locate the Go server handler, ResetPasswordRequest, and service call shown in the issue. Done means the endpoint validates the listed fields and token, applies the documented error statuses, and matches the agreed success response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, authentication
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100