Added buyer seller bolean
This commit is contained in:
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -115,7 +116,7 @@ func UpdatePassword(c *gin.Context) {
|
||||
}
|
||||
|
||||
func Login(c *gin.Context) {
|
||||
var req models.User
|
||||
var req models.LoginRequest
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Bad request"})
|
||||
return
|
||||
@@ -130,12 +131,13 @@ func Login(c *gin.Context) {
|
||||
if usr.CheckPassword(user.Password, req.Password) {
|
||||
if user.IsActive && user.LoginAttempts < 10 {
|
||||
// Proceed with creating JWT token and resetting login attempts
|
||||
// if len(user.Companies) == 0 {
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"error": "User is not connected to a company"})
|
||||
// return
|
||||
// }
|
||||
log.Printf("Companies length %v", len(user.Companies))
|
||||
if len(user.Companies) == 0 {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "User is not connected to a company"})
|
||||
return
|
||||
}
|
||||
|
||||
token, err := usr.CreateSessionToken(user.ID, 2)
|
||||
token, err := usr.CreateSessionToken(user.ID, user.Companies[0].ID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not create JWT token"})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user