Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions handlers/admin_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"errors"
"time"

"github.com/ayush00git/cms-web/helpers"
"github.com/ayush00git/cms-web/models"
Expand All @@ -10,27 +11,26 @@ import (
"gorm.io/gorm"
)


// // Use AdminSignup only when registering admins to the database.
// // Not to be used as a public API.
// func (h *AdminHandler) AdminSignup (c *gin.Context) {
// var inputs models.Admin
// if err := c.ShouldBindJSON(&inputs); err != nil {
// c.JSON(400, gin.H{"error": "invalid request body"})
// return
// }
// // Not to be used as a public API.
func (h *AdminHandler) AdminSignup (c *gin.Context) {
var inputs models.Admin
if err := c.ShouldBindJSON(&inputs); err != nil {
c.JSON(400, gin.H{"error": "invalid request body"})
return
}

// hashedPass, err := bcrypt.GenerateFromPassword([]byte(inputs.Password), 10)
// if err != nil {
// c.JSON(500, gin.H{"error": "internal server error"})
// return
// }
// inputs.Password = string(hashedPass)
hashedPass, err := bcrypt.GenerateFromPassword([]byte(inputs.Password), 10)
if err != nil {
c.JSON(500, gin.H{"error": "internal server error"})
return
}
inputs.Password = string(hashedPass)

// inputs.CreatedAt = time.Now()
// _ = h.DB.Create(&inputs)
// c.JSON(201, gin.H{"success": "admin registered successfully!"})
// }
inputs.CreatedAt = time.Now()
_ = h.DB.Create(&inputs)
c.JSON(201, gin.H{"success": "admin registered successfully!"})
}

// Note that for admins as they are pre-set to the service the
// isVerified field is always by default true.
Expand Down
Loading