Files
easywish/backend/internal/models/auth.go
Nikolai Papin 333817c9e1 refactor: moved hashing logic into application layer for security;
fix: error handling in auth service for database;
refactor: removed redundant taken email check;
chore: removed todos that were completed/not needed;
fix: leaking transactions in complete registration and login on error;
refactor: got rid of txless requests during transactions;
2025-07-06 13:01:08 +03:00

60 lines
1.8 KiB
Go

// Copyright (c) 2025 Nikolai Papin
//
// This file is part of Easywish
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
// the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package models
type Tokens struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}
type RegistrationBeginRequest struct {
Username string `json:"username" binding:"required" validate:"username"`
Email *string `json:"email" binding:"email"`
Password string `json:"password" binding:"required" validate:"password"`
}
type RegistrationCompleteRequest struct {
Username string `json:"username" binding:"required" validate:"username"`
VerificationCode string `json:"verification_code" binding:"required"`
Name string `json:"name" binding:"required" validate:"name"`
Birthday *string `json:"birthday"`
}
type RegistrationCompleteResponse struct {
Tokens
}
type LoginRequest struct {
Username string `json:"username" binding:"required,min=3,max=20" validate:"username"`
Password string `json:"password" binding:"required,max=100"`
TOTP *string `json:"totp"`
}
type LoginResponse struct {
Tokens
}
// TODO: length check
type RefreshRequest struct {
RefreshToken string `json:"refresh_token" binding:"required"`
}
type RefreshResponse struct {
Tokens
}