Fixed qor admin companies users #25
@@ -130,7 +130,12 @@ 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
|
||||
token, err := usr.CreateSessionToken(user.ID, user.CompanyID)
|
||||
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, user.Companies[0].ID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not create JWT token"})
|
||||
return
|
||||
|
||||
2
main.go
2
main.go
@@ -44,7 +44,7 @@ func main() {
|
||||
Admin.AddResource(&models.User{})
|
||||
Admin.AddResource(&models.Device{})
|
||||
Admin.AddResource(&models.ProductTemplate{})
|
||||
company.Meta(&admin.Meta{Name: "Users", Config: &admin.SelectManyConfig{SelectMode: "select"}})
|
||||
company.Meta(&admin.Meta{Name: "Users", Config: &admin.SelectManyConfig{SelectMode: "bottom_sheet"}})
|
||||
company.Meta(&admin.Meta{Name: "Devices", Config: &admin.SelectManyConfig{SelectMode: "bottom_sheet"}})
|
||||
// // Initialize HTTP request multiplexe
|
||||
mux := http.NewServeMux()
|
||||
|
||||
@@ -18,7 +18,7 @@ type Company struct {
|
||||
Address string `json:"address"`
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
Users []User `json:"users"`
|
||||
Users []User `gorm:"many2many:user_companies;"`
|
||||
Devices []Device `json:"devices"`
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ type SessionToken struct {
|
||||
UserID uint `json:"userId"`
|
||||
Token string `json:"token"`
|
||||
IsActive bool `json:"isActive"`
|
||||
CompanyID uint `json:"userId"`
|
||||
CompanyID uint `json:"companyID"`
|
||||
}
|
||||
|
||||
func (SessionToken) Update() (bool, error) {
|
||||
|
||||
@@ -2,13 +2,15 @@ package models
|
||||
|
||||
type User struct {
|
||||
BaseModel
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Email string `json:"email"`
|
||||
Avatar string `json:"avatar"`
|
||||
IsActive bool `json:"isActive" gorm:"default:false"`
|
||||
CompanyID uint `json:"companyId"`
|
||||
LoginAttempts int `gorm:"default:0"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Email string `json:"email"`
|
||||
Avatar string `json:"avatar"`
|
||||
IsActive bool `json:"isActive" gorm:"default:false"`
|
||||
// CompanyID uint `json:"companyId"`
|
||||
// Company Company
|
||||
Companies []Company `gorm:"many2many:user_companies;"`
|
||||
LoginAttempts int `gorm:"default:0"`
|
||||
}
|
||||
|
||||
type ResetPasswordRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user