CGI-FR / CGI-FR/SIGO

[FEAT][API] Add reset password API

Open
#52 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api octopize
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 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.