mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-06 05:30:05 +00:00
Web 服务
This commit is contained in:
52
model/user.go
Normal file
52
model/user.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-github/v28/github"
|
||||
"github.com/naiba/com"
|
||||
)
|
||||
|
||||
// User ...
|
||||
type User struct {
|
||||
Common `json:"common,omitempty"`
|
||||
Login string `gorm:"UNIQUE_INDEX" json:"login,omitempty"` // 登录名
|
||||
AvatarURL string `json:"avatar_url,omitempty"` // 头像地址
|
||||
Name string `json:"name,omitempty"` // 昵称
|
||||
Blog string `json:"blog,omitempty"` // 网站链接
|
||||
Email string `json:"email,omitempty"` // 邮箱
|
||||
Hireable bool `json:"hireable,omitempty"`
|
||||
Bio string `json:"bio,omitempty"` // 个人简介
|
||||
|
||||
Token string `gorm:"UNIQUE_INDEX" json:"-"` // 认证 Token
|
||||
TokenExpired time.Time `json:"token_expired,omitempty"` // Token 过期时间
|
||||
SuperAdmin bool `json:"super_admin,omitempty"` // 超级管理员
|
||||
|
||||
TeamsID []uint64 `gorm:"-"`
|
||||
}
|
||||
|
||||
// NewUserFromGitHub ..
|
||||
func NewUserFromGitHub(gu *github.User) User {
|
||||
var u User
|
||||
u.ID = uint64(gu.GetID())
|
||||
u.Login = gu.GetLogin()
|
||||
u.AvatarURL = gu.GetAvatarURL()
|
||||
u.Name = gu.GetName()
|
||||
// 昵称为空的情况
|
||||
if u.Name == "" {
|
||||
u.Name = u.Login
|
||||
}
|
||||
u.Blog = gu.GetBlog()
|
||||
u.Blog = gu.GetBlog()
|
||||
u.Email = gu.GetEmail()
|
||||
u.Hireable = gu.GetHireable()
|
||||
u.Bio = gu.GetBio()
|
||||
return u
|
||||
}
|
||||
|
||||
// IssueNewToken ...
|
||||
func (u *User) IssueNewToken() {
|
||||
u.Token = com.MD5(fmt.Sprintf("%d%d%s", time.Now().UnixNano(), u.ID, u.Login))
|
||||
u.TokenExpired = time.Now().AddDate(0, 0, 14)
|
||||
}
|
||||
Reference in New Issue
Block a user