Skip to content

Commit

Permalink
admin. check authorized routes
Browse files Browse the repository at this point in the history
  • Loading branch information
edospadoni committed Mar 13, 2024
1 parent e6aec90 commit 654d6ad
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,26 @@ func UpdateAccount(accountID string, account models.Account) error {
}

func IsAdmin(accountUsername string) (bool, string) {
// check if is admin
if accountUsername == configuration.Config.AdminUsername {
return true, ""
}

// get db
db := Instance()

// define query
var id string
query := "SELECT id FROM accounts where username = ? LIMIT 1"
err := db.QueryRow(query, accountUsername).Scan(&id)

// check error
if err != nil {
logs.Logs.Println("[ERR][STORAGE][GET_PASSWORD] error in query execution:" + err.Error())
}

// return password
return id == "1", id
// check if user it's me
return false, id
}

func GetAccounts() ([]models.Account, error) {
Expand Down

0 comments on commit 654d6ad

Please sign in to comment.