refactor: login & refresh token

This commit is contained in:
naiba
2024-10-20 14:05:43 +08:00
parent 41391989e7
commit 53f1abb7c8
10 changed files with 137 additions and 97 deletions

View File

@@ -23,17 +23,17 @@ func (r ServiceItemResponse) TotalUptime() float32 {
}
type LoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
}
type CommonError struct {
Code int `json:"code"`
Args map[string]string `json:"args"`
type CommonResponse[T any] struct {
Success bool `json:"success,omitempty"`
Data T `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
type CommonResponse struct {
Success bool `json:"success"`
Data interface{} `json:"data"`
Error CommonError `json:"error"`
type LoginResponse struct {
Token string `json:"token,omitempty"`
Expire string `json:"expire,omitempty"`
}

View File

@@ -7,15 +7,12 @@ import (
)
const CtxKeyAuthorizedUser = "ckau"
const CtxKeyViewPasswordVerified = "ckvpv"
const CtxKeyPreferredTheme = "ckpt"
const CacheKeyOauth2State = "p:a:state"
type Common struct {
ID uint64 `gorm:"primaryKey"`
CreatedAt time.Time `gorm:"index;<-:create"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
DeletedAt gorm.DeletedAt `gorm:"index"`
ID uint64 `gorm:"primaryKey" json:"id,omitempty"`
CreatedAt time.Time `gorm:"index;<-:create" json:"created_at,omitempty"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at,omitempty"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
type Response struct {

View File

@@ -117,6 +117,9 @@ func (c *Config) Read(path string) error {
return err
}
if c.ListenPort == 0 {
c.ListenPort = 8008
}
if c.Language == "" {
c.Language = "zh-CN"
}

View File

@@ -2,6 +2,6 @@ package model
type User struct {
Common
Username string
Password string
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty" gorm:"type:char(72)"`
}