-
Notifications
You must be signed in to change notification settings - Fork 0
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
Be 03/04/07/feat(forget password) forgot, set password, and migration #13
Conversation
- 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.
f7b8830
to
1d7778b
Compare
7bf0c4d
to
daf75ac
Compare
- 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.
daf75ac
to
fae1f49
Compare
@@ -86,6 +92,13 @@ type ( | |||
Email string `json:"email" ` | |||
Role string `json:"role"` | |||
} | |||
|
|||
ForgotPassword struct { | |||
Email string `json:"email,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apakah ini harus required?
There was a problem hiding this comment.
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
- 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
4319e02
to
c41b12c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good
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