mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-09 10:21:00 +08:00
finish upload avatar
This commit is contained in:
@@ -2,10 +2,16 @@ package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fumiama/paper-manager/backend/global"
|
||||
)
|
||||
|
||||
const (
|
||||
chineseDateLayout = "2006年01月02日15时04分05秒"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidToken = errors.New("invalid token")
|
||||
)
|
||||
@@ -18,6 +24,9 @@ type getUserInfoResult struct {
|
||||
Desc string `json:"desc"`
|
||||
HomePath string `json:"homePath"`
|
||||
Roles []role `json:"roles"`
|
||||
Date string `json:"date"`
|
||||
Last string `json:"last"`
|
||||
Contact string `json:"contact"`
|
||||
}
|
||||
|
||||
func getUserInfo(token string) (*getUserInfoResult, error) {
|
||||
@@ -25,6 +34,16 @@ func getUserInfo(token string) (*getUserInfoResult, error) {
|
||||
if user == nil {
|
||||
return nil, errInvalidToken
|
||||
}
|
||||
cont := user.Cont
|
||||
if len(cont) > 7 {
|
||||
sb := strings.Builder{}
|
||||
sb.WriteString(cont[:3])
|
||||
for i := 0; i < len(cont)-7; i++ {
|
||||
sb.WriteByte('*')
|
||||
}
|
||||
sb.WriteString(cont[len(cont)-4:])
|
||||
cont = sb.String()
|
||||
}
|
||||
return &getUserInfoResult{
|
||||
UserID: *user.ID,
|
||||
Username: user.Name,
|
||||
@@ -37,6 +56,19 @@ func getUserInfo(token string) (*getUserInfoResult, error) {
|
||||
}
|
||||
return "/dashboard/workbench"
|
||||
}(),
|
||||
Roles: []role{{RoleName: user.Role.Nick(), Value: user.Role.String()}},
|
||||
Roles: []role{{RoleName: user.Role.Nick(), Value: user.Role.String()}},
|
||||
Date: time.Unix(user.Date, 0).Format(chineseDateLayout),
|
||||
Last: time.Unix(user.Last, 0).Format(chineseDateLayout),
|
||||
Contact: cont,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func logout(token string) error {
|
||||
user := usertokens.Get(token)
|
||||
if user == nil {
|
||||
return errInvalidToken
|
||||
}
|
||||
loginstatus.Delete(user.Name)
|
||||
usertokens.Delete(token)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user