WIP: Start implementing the internal auth
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Signed-off-by: Nikolai Rodionov <allanger@badhouseplants.net>
This commit is contained in:
@@ -32,22 +32,24 @@ type JWT struct {
|
||||
type AccountParams struct{}
|
||||
|
||||
type AccountData struct {
|
||||
Username string
|
||||
Password string
|
||||
Email string
|
||||
UUID string
|
||||
}
|
||||
|
||||
func (c *AccountController) Create(ctx context.Context, data *AccountData) (string, error) {
|
||||
log := logger.FromContext(ctx)
|
||||
data.UUID = uuid.New().String()
|
||||
|
||||
passwordHash, err := hash.HashPassword(data.Password, int(c.HashCost))
|
||||
if err != nil {
|
||||
log.Error(err, "Couldn't crate the password hash")
|
||||
return "", nil
|
||||
}
|
||||
|
||||
query := "INSERT INTO users (uuid, username, email, password_hash) VALUES ($1, $2, $3, $4)"
|
||||
if _, err := c.DB.Query(query, data.UUID, data.Username, data.Email, passwordHash); err != nil {
|
||||
query := "INSERT INTO users (uuid, email, password_hash) VALUES ($1, $2, $3)"
|
||||
if _, err := c.DB.Query(query, data.UUID, data.Email, passwordHash); err != nil {
|
||||
log.Error(err, "Couldn't create a user in the database")
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user