Skip to content

Be 03/04/07/feat(forget password) forgot, set password, and migration #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Kocannn
Copy link
Collaborator

@Kocannn Kocannn commented May 12, 2025

  • add migration + seeding with goose combine with cobra command
    usage migrate

  • go run main.go migrate:create name_migration // for create new file migration

  • go run main.go migrate:up // for up migration

  • go run main.go migrate:down // for down migration
    usage for seeding

  • go run main.go seed:create name_seed // for create new file seed

  • go run main.go seed:up // run seeding file

  • add feature to reset password

Kocannn added 6 commits May 6, 2025 20:25
- Implement forgot password handler to generate reset token and link
- Add reset password form to validate and update user password
- Create HTML templates for reset password and email confirmation
- Update routes to include forgot and reset password endpoints
- Add usecase methods for token verification and password reset
Add reset password functionality across repository, usecase, and handler
layers. This includes:

- Repository method to update user password in the database.
- Usecase logic to verify token, hash password, and call repository.
- HTTP handler to handle reset password requests.

Also updated the domain model to include token and password fields in
ForgotPassword struct and added the necessary interface methods.

BREAKING CHANGE: The reset password endpoint now requires a token and
password in the request body.
- Updated `ForgotPassword` use case to pass reset link to the email
template.
- Fixed email template rendering using `html/template` package.
- Adjusted reset link to point to the correct frontend URL.
- Improved error handling for email sending process.

This ensures users receive a functional reset password link in their
email.
Added new migration commands `migrate:create`, `migrate:up`, and
`migrate:down` using the goose library. Updated dependencies for
cobra and pflag to their latest versions. Removed unused imports
and legacy migration code.

BREAKING CHANGE: The `dbMigrate` command has been replaced with
new migration commands.
- Updated `ForgotPassword` to use frontend base URL for reset link.
- Added email and password validation in `ResetPassword` handler.
- Introduced `ConfirmPassword` field in `ForgotPassword` struct.
- Removed unused `ShowResetPasswordForm` and related assets.
- Added seeding commands (`seed:create`, `seed:up`, `seed:down`).
- Modified token generation to accept custom expiration time.
- Updated migration command to include table prefix.
- Fixed token validation logic to correctly handle used tokens.
- Improved GORM queries by using pointer semantics for better
performance.
- Enhanced error logging with `WithError` for better debugging context.
- Removed redundant `Model()` call in the initial token query.
- Improved code readability with named variables and consistent
formatting.

These changes enhance code clarity, maintainability, and runtime
efficiency.
@Kocannn Kocannn force-pushed the be-03/04/07/feat(forget-password)-forgot&set-password branch from f7b8830 to 1d7778b Compare May 12, 2025 09:30
@Kocannn Kocannn closed this May 12, 2025
@Kocannn Kocannn reopened this May 12, 2025
@Kocannn Kocannn closed this May 12, 2025
@Kocannn Kocannn reopened this May 12, 2025
@Kocannn Kocannn force-pushed the be-03/04/07/feat(forget-password)-forgot&set-password branch 3 times, most recently from 7bf0c4d to daf75ac Compare May 12, 2025 10:47
- Updated `cmd.go` to remove unused `seedDown` command.
- Adjusted `migrate.go` commands to align with `goose` CLI changes.
- Added new database migration files for `users`, `logout`, `events`,
  `registration_events`, `event_pays`, `event_speakers`, `event_tags`,
  `images`, and `testing` tables.
- Ensured proper foreign key constraints and sequence handling.

These changes improve database schema management and command usability.
@Kocannn Kocannn force-pushed the be-03/04/07/feat(forget-password)-forgot&set-password branch from daf75ac to fae1f49 Compare May 13, 2025 03:33
@@ -86,6 +92,13 @@ type (
Email string `json:"email" `
Role string `json:"role"`
}

ForgotPassword struct {
Email string `json:"email,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apakah ini harus required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soalnya untuk struct ForgotPassowrdnya masih saya pake buat ba set passwordnya yang cuma butuh token, password sama confirm passwordnya dari struct nya jadi sa taruh omitempty saja, tapi untuk forgot passwordnya sudh saya taruh validator untuk ba atasi kalo email yang dia masukkan kosong

@Kocannn Kocannn requested a review from AfandyW May 16, 2025 03:21
- Change HTTP methods for forgot_password and set_password endpoints to
PUT
- Add email format validation using regex in ForgotPassword handler
- Refactor ForgotPassword usecase and repository to return only error
- Improve error messages for request body read/unmarshal failures
- Fix password validation logic and error message in ResetPassword
handler
- Update JWT token generation to use 30 minutes for reset token
- Refactor variable naming for consistency in repository methods
- Update domain interfaces to match new ForgotPassword signature
@Kocannn Kocannn force-pushed the be-03/04/07/feat(forget-password)-forgot&set-password branch from 4319e02 to c41b12c Compare May 17, 2025 08:42
Copy link
Contributor

@AfandyW AfandyW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

@AfandyW AfandyW merged commit 2ad85ce into development May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants