feat/role based access (#50)
* feat: add roles based access * feat: update roles env + todo * feat: add roles to update profile * feat: add role based oauth * feat: validate role for a given token
This commit is contained in:
@@ -24,6 +24,7 @@ type Manager interface {
|
||||
GetVerificationRequests() ([]VerificationRequest, error)
|
||||
GetVerificationByEmail(email string) (VerificationRequest, error)
|
||||
DeleteUser(email string) error
|
||||
SaveRoles(roles []Role) error
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
@@ -53,7 +54,7 @@ func InitDB() {
|
||||
if err != nil {
|
||||
log.Fatal("Failed to init db:", err)
|
||||
} else {
|
||||
db.AutoMigrate(&User{}, &VerificationRequest{})
|
||||
db.AutoMigrate(&User{}, &VerificationRequest{}, &Role{})
|
||||
}
|
||||
|
||||
Mgr = &manager{db: db}
|
||||
|
19
server/db/roles.go
Normal file
19
server/db/roles.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package db
|
||||
|
||||
import "log"
|
||||
|
||||
type Role struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Role string
|
||||
}
|
||||
|
||||
// SaveRoles function to save roles
|
||||
func (mgr *manager) SaveRoles(roles []Role) error {
|
||||
res := mgr.db.Create(&roles)
|
||||
if res.Error != nil {
|
||||
log.Println(`Error saving roles`)
|
||||
return res.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@@ -17,6 +17,7 @@ type User struct {
|
||||
CreatedAt int64 `gorm:"autoCreateTime"`
|
||||
UpdatedAt int64 `gorm:"autoUpdateTime"`
|
||||
Image string
|
||||
Roles string
|
||||
}
|
||||
|
||||
// SaveUser function to add user even with email conflict
|
||||
|
Reference in New Issue
Block a user