8000 updated · wpcodevo/golang-gorm-postgres@ed3e66a · GitHub
[go: up one dir, main page]

Skip to content

Commit ed3e66a

Browse files
committed
updated
1 parent e011847 commit ed3e66a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

controllers/auth.controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewAuthController(DB *gorm.DB) AuthController {
2121
return AuthController{DB}
2222
}
2323

24-
// SignUp User
24+
// [...] SignUp User
2525
func (ac *AuthController) SignUpUser(ctx *gin.Context) {
2626
var payload *models.SignUpInput
2727

@@ -91,6 +91,7 @@ func (ac *AuthController) SignUpUser(ctx *gin.Context) {
9191
ctx.JSON(http.StatusCreated, gin.H{"status": "success", "message": message})
9292
}
9393

94+
// [...] SignIn User
9495
func (ac *AuthController) SignInUser(ctx *gin.Context) {
9596
var payload *models.SignInInput
9697

@@ -106,6 +107,11 @@ func (ac *AuthController) SignInUser(ctx *gin.Context) {
106107
return
107108
}
108109

110+
if !user.Verified {
111+
ctx.JSON(http.StatusForbidden, gin.H{"status": "fail", "message": "Please verify your email"})
112+
return
113+
}
114+
109115
if err := utils.VerifyPassword(user.Password, payload.Password); err != nil {
110116
ctx.JSON(http.StatusBadRequest, gin.H{"status": "fail", "message": "Invalid email or Password"})
111117
return
@@ -125,11 +131,13 @@ func (ac *AuthController) SignInUser(ctx *gin.Context) {
125131
ctx.JSON(http.StatusOK, gin.H{"status": "success", "token": token})
126132
}
127133

134+
// [...] SignOut User
128135
func (ac *AuthController) LogoutUser(ctx *gin.Context) {
129136
ctx.SetCookie("token", "", -1, "/", "localhost", false, true)
130137
ctx.JSON(http.StatusOK, gin.H{"status": "success"})
131138
}
132139

140+
// [...] Verify Email
133141
func (ac *AuthController) VerifyEmail(ctx *gin.Context) {
134142

135143
code := ctx.Params.ByName("verificationCode")

readMe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
### 1. How to Setup Golang GORM RESTful API Project with Postgres
44

55
[How to Setup Golang GORM RESTful API Project with Postgres](https://codevoweb.com/setup-golang-gorm-restful-api-project-with-postgres/)
6+
7+
### 2. API with Golang + GORM + PostgreSQL: Access & Refresh Tokens
8+
9+
[API with Golang + GORM + PostgreSQL: Access & Refresh Tokens](https://codevoweb.com/golang-gorm-postgresql-user-registration-with-refresh-tokens)
10+
11+
### 3. Golang and GORM - User Registration and Email Verification
12+
13+
[Golang and GORM - User Registration and Email Verification](https://codevoweb.com/golang-and-gorm-user-registration-email-verification)

0 commit comments

Comments
 (0)
0