reg +-
This commit is contained in:
parent
f8f10b7c15
commit
55415fb5e2
11
cmd/main.go
11
cmd/main.go
@ -10,11 +10,12 @@ import (
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
ps := plugin.NewPluginStore()
|
||||
pl := plugin.MustNewPluginLoader(ctx, 8081, ps)
|
||||
pl.Run(ctx)
|
||||
|
||||
pg := postgres.New(ctx, "postgres://draincloud:draincloud_secret@localhost:5432/draincloud?sslmode=disable")
|
||||
plugin.MustNewPluginLoader(ctx, 8081, plugin.NewPluginStore()).
|
||||
Run(ctx)
|
||||
|
||||
app.New(pg).Run(context.TODO())
|
||||
pg := postgres.New(ctx, "postgres://draincloud:draincloud@localhost:5432/draincloud?sslmode=disable")
|
||||
|
||||
app.New(pg).
|
||||
Run(ctx)
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ services:
|
||||
ports:
|
||||
- 5432:5432
|
||||
environment:
|
||||
POSTGRES_USERNAME: draincloud
|
||||
POSTGRES_DB: draincloud
|
||||
POSTGRES_PASSWORD: draincloud_secret
|
||||
- POSTGRES_USER=draincloud
|
||||
- POSTGRES_PASSWORD=draincloud
|
||||
- POSTGRES_DB=draincloud
|
||||
volumes:
|
||||
- draincloud-db-data:/var/lib/postgresql/data
|
||||
|
||||
|
@ -82,16 +82,16 @@ func (d *DrainCloud) register(ctx *gin.Context, req *domain.RegisterRequest) (*r
|
||||
return nil, fmt.Errorf("invalid creds: %w", err)
|
||||
}
|
||||
|
||||
_, err := bcrypt.GenerateFromPassword([]byte(req.Password), 10)
|
||||
passwordHash, err := bcrypt.GenerateFromPassword([]byte(req.Password), 10)
|
||||
if err != nil {
|
||||
logger.Error(ctx, "[register] failed to generate password", logger.Err(err))
|
||||
return nil, fmt.Errorf("failed to generate password: %w", err)
|
||||
}
|
||||
|
||||
// _, err = d.datadase.AddUser(ctx, req.Login, req.Login, passwordHash)
|
||||
// if err != nil {
|
||||
// return nil, fmt.Errorf("failed to add new user: %w", err)
|
||||
// }
|
||||
_, err = d.datadase.AddUser(ctx, req.Login, req.Login, passwordHash)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to add new user: %w", err)
|
||||
}
|
||||
|
||||
sessionToken, err := generateSessionToken(100)
|
||||
if err != nil {
|
||||
@ -107,15 +107,17 @@ func (d *DrainCloud) register(ctx *gin.Context, req *domain.RegisterRequest) (*r
|
||||
|
||||
ctx.SetCookie("__Csrf_token", csrfToken, int((time.Hour * 24).Seconds()), "_path", "_domain", true, false)
|
||||
|
||||
// TODO save session into database
|
||||
|
||||
return ®isterResult{}, nil
|
||||
}
|
||||
|
||||
func validateLoginAndPassword(login, password string) error {
|
||||
if len(login) < 8 {
|
||||
if len(login) < 4 {
|
||||
return fmt.Errorf("login must be longer than 8 chars")
|
||||
}
|
||||
|
||||
if len(password) < 8 {
|
||||
if len(password) < 6 {
|
||||
return fmt.Errorf("password must be longer than 8 chars")
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ func (d *Database) GetUserByLogin(ctx context.Context, login string) (*models.Us
|
||||
|
||||
func addUser(ctx context.Context, conn dbtx, login string, username string, passwordHash []byte) (uint64, error) {
|
||||
const stmt = `INSERT INTO users (login,username,password)
|
||||
VALUES ($1,$2,$3,$4) RETURNING id`
|
||||
VALUES ($1,$2,$3) RETURNING id`
|
||||
|
||||
row := conn.QueryRow(ctx, stmt, login, username, passwordHash)
|
||||
|
||||
|
@ -8,10 +8,6 @@ create table if not exists users (
|
||||
updated_at timestamptz default current_timestamp
|
||||
);
|
||||
|
||||
alter table users add constraint users_username_len check(length(username) > 250) not valid;
|
||||
|
||||
alter table users add constraint users_login_len check(length(username) > 250) not valid;
|
||||
|
||||
create index idx_users_login on users (login);
|
||||
|
||||
create index idx_users_username on users (username);
|
||||
|
Loading…
Reference in New Issue
Block a user