mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-07 18:15:47 +08:00
Add account management web pages (#694)
Added internal/frontend/account to implement account management code. Added user registration templates and handlers. Set up a sqlite and postgres database in package main.
This commit is contained in:
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"crawshaw.io/sqlite"
|
||||
"crawshaw.io/sqlite/sqlitex"
|
||||
)
|
||||
|
||||
@@ -42,7 +44,7 @@ func (d *SQLite) CreateUser(ctx context.Context, username, email, password strin
|
||||
stmt.SetBytes("$salt", u.Salt)
|
||||
stmt.SetText("$confirmationHash", *u.ConfirmationHash)
|
||||
if _, err := stmt.Step(); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("store created user in sqlite: %w", checkSqlite(err))
|
||||
}
|
||||
|
||||
stmt = conn.Prep(`SELECT created_at, updated_at FROM users WHERE id = $id`)
|
||||
@@ -87,3 +89,20 @@ func (d *SQLite) ConfirmUser(ctx context.Context, confirmation string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkSqlite(err error) error {
|
||||
var sErr sqlite.Error
|
||||
if !errors.As(err, &sErr) {
|
||||
return err
|
||||
}
|
||||
|
||||
switch sErr.Code {
|
||||
case sqlite.SQLITE_CONSTRAINT_CHECK:
|
||||
c := strings.Split(sErr.Msg, ": ")
|
||||
if kv, ok := constraints[c[len(c)-1]]; ok {
|
||||
return Error{invalid: kv}
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("user: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user