直接完成
此提交包含在:
30
service/user.go
一般檔案
30
service/user.go
一般檔案
@@ -0,0 +1,30 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"integrity-checkin/pkg/app"
|
||||
"integrity-checkin/pkg/httpclient"
|
||||
"integrity-checkin/pkg/util"
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
}
|
||||
|
||||
func (u UserService) Login(aw *app.Wrapper) app.Result {
|
||||
type LoginReq struct {
|
||||
Username string `form:"username" binding:"required"`
|
||||
Password string `form:"password" binding:"required"`
|
||||
}
|
||||
var req LoginReq
|
||||
if err := aw.Ctx.ShouldBind(&req); err != nil {
|
||||
return aw.Error(err.Error())
|
||||
}
|
||||
sduLoginData, err := httpclient.SDULogin(req.Username, req.Password)
|
||||
if err != nil {
|
||||
return aw.Error(err.Error())
|
||||
}
|
||||
user := userDAO.FindUserByUsername(sduLoginData.Username)
|
||||
if user == nil {
|
||||
user = userDAO.CreateUser(sduLoginData.Username, sduLoginData.RealName)
|
||||
}
|
||||
return aw.Success(util.GenerateJWT(user.ID, user.RoleID))
|
||||
}
|
新增問題並參考
封鎖使用者