wip: 24/10/28
This commit is contained in:
11
model/authorization.go
Normal file
11
model/authorization.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
type AuthorizationRecord struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
CreatedAt int64 `json:"created_at" gorm:"column:created_at;autoCreateTime:milli"`
|
||||
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at;autoUpdateTime:milli"`
|
||||
DeletedAt int64 `json:"deleted_at" gorm:"index;column:deleted_at;default:0"`
|
||||
|
||||
UserId uint64 `json:"user_id" gorm:"column:user_id"`
|
||||
ClientId uint64 `json:"client_id" gorm:"column:client_id"`
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package model
|
||||
|
||||
type Platform struct {
|
||||
type Client struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
CreatedAt int64 `json:"created_at" gorm:"column:created_at;autoCreateTime:milli"`
|
||||
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at;autoUpdateTime:milli"`
|
30
model/init.go
Normal file
30
model/init.go
Normal file
@ -0,0 +1,30 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"uauth/internal/tool"
|
||||
)
|
||||
|
||||
func Init(tx *gorm.DB) error {
|
||||
var err error
|
||||
if err = tx.AutoMigrate(
|
||||
&User{},
|
||||
&Client{},
|
||||
&AuthorizationRecord{},
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = tx.Clauses(clause.OnConflict{DoNothing: true}).
|
||||
Create(&User{Username: "admin", Nickname: "admin", Password: tool.NewPassword("Foobar123")}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = tx.Clauses(clause.OnConflict{DoNothing: true}).
|
||||
Create(&Client{ClientId: "test", ClientSecret: "test", Name: "测试", Icon: "https://picsum.photos/200"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -22,6 +22,7 @@ type User struct {
|
||||
Status Status `json:"status" gorm:"column:status;default:0"`
|
||||
|
||||
Nickname string `json:"nickname" gorm:"column:nickname;type:varchar(64)"`
|
||||
Avatar string `json:"avatar" gorm:"column:avatar;type:varchar(256)"`
|
||||
Comment string `json:"comment" gorm:"column:comment"`
|
||||
|
||||
CreatedById uint64 `json:"created_by_id" gorm:"column:created_by_id"`
|
||||
@ -37,6 +38,7 @@ func (u *User) JwtEncode() (token string, err error) {
|
||||
jwtToken := jwt.NewWithClaims(jwt.SigningMethodHS512, jwt.MapClaims{
|
||||
"id": u.Id,
|
||||
"username": u.Username,
|
||||
"nickname": u.Nickname,
|
||||
"status": u.Status,
|
||||
"login_at": now.UnixMilli(),
|
||||
})
|
||||
|
Reference in New Issue
Block a user