Added /register handler
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -12,10 +15,14 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
AuthService = &Auth{}
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
db *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewAuthService(db *pgxpool.Pool) *Auth {
|
||||
return &Auth{db: db}
|
||||
}
|
||||
|
||||
func (a *Auth) Login(login, passwd string) (string, error) {
|
||||
@@ -32,6 +39,13 @@ func (a *Auth) Login(login, passwd string) (string, error) {
|
||||
}
|
||||
|
||||
func (a *Auth) Register(email, login, passwd string) (string, error) {
|
||||
var id string
|
||||
|
||||
return "user-uuid", nil
|
||||
sql := `INSERT INTO identity.users(email, username, password) VALUES($1, $2, $3) LIMIT 1 RETURNING id`
|
||||
err := a.db.QueryRow(context.Background(), sql, email, login, passwd).Scan(&id)
|
||||
if err != nil {
|
||||
return "", errors.New("Failed to create new user: " + err.Error())
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user