refactored
This commit is contained in:
42
dbhandler/user_pass_auth.go
Normal file
42
dbhandler/user_pass_auth.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package dbhandler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.acooldomain.co/server-manager/backend/models"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func HashPassword(password string) (string, error) {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
return string(bytes), err
|
||||
}
|
||||
|
||||
type InviteToken struct {
|
||||
Email string
|
||||
Permissions models.Permission
|
||||
Token string
|
||||
}
|
||||
|
||||
type UserSignupRequest struct {
|
||||
Token InviteToken
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type UserPassAuthanticationDbHandler interface {
|
||||
// Read Only
|
||||
AuthenticateUser(ctx context.Context, username string, password string) (*models.User, error)
|
||||
ListUsers(ctx context.Context) ([]models.User, error)
|
||||
|
||||
// Write
|
||||
CreateUser(ctx context.Context, username string, password string, permissions models.Permission, email string, maxOwnedServers uint) error
|
||||
RemoveUser(ctx context.Context, username string) error
|
||||
SetPermissions(ctx context.Context, username string, permissions models.Permission) error
|
||||
SetPassword(ctx context.Context, username string, password string) error
|
||||
}
|
||||
|
||||
type InviteTokenDbHandler interface {
|
||||
SaveInviteToken(ctx context.Context, email string, permissions models.Permission) (string, error)
|
||||
GetInviteToken(ctx context.Context, token string) (*InviteToken, error)
|
||||
}
|
||||
Reference in New Issue
Block a user