1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-09 02:01:31 +08:00

finish backend login

This commit is contained in:
源文雨
2023-03-17 18:29:02 +08:00
parent 5889f0e30a
commit cd571e9e25
12 changed files with 844 additions and 279 deletions

42
backend/api/user.go Normal file
View File

@@ -0,0 +1,42 @@
package api
import (
"errors"
"github.com/fumiama/paper-manager/backend/global"
)
var (
errInvalidToken = errors.New("invalid token")
)
type getUserInfoResult struct {
UserID int `json:"userId"`
Username string `json:"username"`
RealName string `json:"realName"`
Avatar string `json:"avatar"`
Desc string `json:"desc"`
HomePath string `json:"homePath"`
Roles []role `json:"roles"`
}
func getUserInfo(token string) (*getUserInfoResult, error) {
user := usertokens.Get(token)
if user == nil {
return nil, errInvalidToken
}
return &getUserInfoResult{
UserID: *user.ID,
Username: user.Name,
RealName: user.Nick,
Avatar: user.Avtr,
Desc: user.Desc,
HomePath: func() string {
if user.Role == global.RoleSuper {
return "/dashboard/analysis"
}
return "/dashboard/workbench"
}(),
Roles: []role{{RoleName: user.Role.Nick(), Value: user.Role.String()}},
}, nil
}