Files
easywish/backend/internal/models/auth.go
Nikolai Papin cbcfb8a286 feat: middleware for request body parsing, validation and authentication;
feat: helper function for getting request info from gin context
2025-06-24 17:31:48 +03:00

63 lines
1.9 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,min=3,max=20"`
Email *string `json:"email" binding:"email"`
Password string `json:"password" binding:"required"` // TODO: password checking
}
// TODO: length check
type RegistrationCompleteRequest struct {
Username string `json:"username" binding:"required"`
VerificationCode string `json:"verification_code" binding:"required"`
Name string `json:"name" binding:"required,max=75"`
Birthday *string `json:"birthday"`
AvatarUrl *string `json:"avatar_url" binding:"http_url,max=255"`
}
type RegistrationCompleteResponse struct {
Tokens
}
// TODO: length check
type LoginRequest struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
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
}