init(db): add user login and auth funcs

This commit is contained in:
Masahiko AMANO 2025-01-17 18:49:49 +03:00
parent ec90dfb9dc
commit 6f675b843c

View File

@ -27,3 +27,20 @@ func InitDB(connString string) error {
}
return nil
}
//#region Users
func UserLogin(ctx context.Context, login, password string) (user_id string, err error) {
row := connPool.QueryRow(ctx, "SELECT id FROM users WHERE login=$1 AND password=crypt($2, password)", login, password)
err = row.Scan(&user_id)
return
}
func UserAuth(ctx context.Context, user_id string) (ok, editor bool) {
row := connPool.QueryRow(ctx, "SELECT editor FROM users WHERE id=$1", user_id)
err := row.Scan(&editor)
ok = (err == nil)
return
}
//#endregion Users