2024-10-10 19:41:49 +00:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
2024-10-10 20:27:01 +00:00
|
|
|
"errors"
|
|
|
|
|
2024-10-10 19:41:49 +00:00
|
|
|
"git.tek.govt.hu/dowerx/szoe-pontok/database"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
)
|
|
|
|
|
|
|
|
func LoggedIn(token string) (string, error) {
|
|
|
|
rdb, ctx := database.GetRDB()
|
|
|
|
result, err := rdb.Get(ctx, token).Result()
|
|
|
|
|
|
|
|
if err == redis.Nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsAdmin(neptun string) error {
|
2024-10-10 20:27:01 +00:00
|
|
|
db := database.GetDB()
|
|
|
|
|
|
|
|
rows, err := db.NamedQuery(`select count(*) from "admin" inner join "user" on "user"."id" = "admin"."user" where "user"."neptun" = :neptun`,
|
|
|
|
map[string]interface{}{
|
|
|
|
"neptun": neptun,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var count int
|
|
|
|
if !rows.Next() {
|
|
|
|
return errors.New("not an admin")
|
|
|
|
}
|
|
|
|
|
|
|
|
rows.Scan(&count)
|
|
|
|
|
|
|
|
if count != 1 {
|
|
|
|
return errors.New("not an admin")
|
|
|
|
}
|
2024-10-10 19:41:49 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|