Add token unwrapping, admin concept and user creation endpoint

This commit is contained in:
Miguel de la Cruz 2021-09-13 14:52:00 +02:00
parent 7ebb14e431
commit 3c7c32423e
12 changed files with 141 additions and 16 deletions

View file

@ -57,7 +57,8 @@ CREATE TABLE IF NOT EXISTS users (
name VARCHAR(255) NOT NULL,
mail VARCHAR(255) UNIQUE NOT NULL,
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL
password VARCHAR(255) NOT NULL,
admin BOOLEAN NOT NULL
);
CREATE TABLE IF NOT EXISTS game (

View file

@ -8,7 +8,7 @@ import (
"git.ctrlz.es/mgdelacroix/craban/model"
)
var userColumns = []string{"id", "name", "mail", "username", "password"}
var userColumns = []string{"id", "name", "mail", "username", "password", "admin"}
type UserStore struct {
Conn *sql.DB
@ -34,6 +34,7 @@ func (us *UserStore) usersFromRows(rows *sql.Rows) ([]*model.User, error) {
&user.Mail,
&user.Username,
&user.Password,
&user.Admin,
)
if err != nil {
return nil, err
@ -94,7 +95,7 @@ func (us *UserStore) GetByUsername(username string) (*model.User, error) {
func (us *UserStore) Create(user *model.User) (*model.User, error) {
query := us.Q().Insert("users").
Columns(userColumns[1:]...).
Values(user.Name, user.Mail, user.Username, user.Password)
Values(user.Name, user.Mail, user.Username, user.Password, user.Admin)
res, err := query.Exec()
if err != nil {