修改返回值结构,新增角色菜单接口
This commit is contained in:
parent
b9b5d726e7
commit
7e4c9b4a30
@ -3,4 +3,5 @@ package controller
|
||||
// Api api接口
|
||||
type Api struct {
|
||||
Basic // 基础数据
|
||||
Role // 角色数据
|
||||
}
|
||||
|
||||
@ -40,12 +40,12 @@ func (b *Basic) Login(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
// isValid := utils.VerifyCaptcha(login)
|
||||
// if !isValid {
|
||||
// // 验证码错误
|
||||
// responses.FailWithMessage("验证码错误", c)
|
||||
// return
|
||||
// }
|
||||
isValid := utils.VerifyCaptcha(login)
|
||||
if !isValid {
|
||||
// 验证码错误
|
||||
responses.FailWithMessage("验证码错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 登陆
|
||||
Basic := service.Basic{}
|
||||
|
||||
10
api/controller/role.go
Normal file
10
api/controller/role.go
Normal file
@ -0,0 +1,10 @@
|
||||
package controller
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type Role struct{}
|
||||
|
||||
// GetRoleMenuList 获取角色菜单列表
|
||||
func (r *Role) GetRoleMenuList(c *gin.Context) {
|
||||
|
||||
}
|
||||
@ -7,7 +7,7 @@ type Basic struct {
|
||||
// Login 登陆
|
||||
type Login struct {
|
||||
Access string `json:"access" form:"access" validate:"required" label:"用户名"` // 用户名
|
||||
Password string `json:"password" form:"password" validate:"required"` // 密码
|
||||
Captcha string `json:"captcha" form:"captcha" validate:"required"` // 验证码
|
||||
Password string `json:"password" form:"password" validate:"required" label:"密码"` // 密码
|
||||
Captcha string `json:"captcha" form:"captcha" validate:"required" label:"验证码"` // 验证码
|
||||
CaptchaId string `json:"captchaId" form:"captchaId" validate:"required"` // 验证码ID
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package responses
|
||||
package basicResponse
|
||||
|
||||
import "hospital-admin-api/config"
|
||||
|
||||
@ -68,9 +68,11 @@ func publicRouter(r *gin.Engine, api controller.Api) {
|
||||
// privateRouter 私有路由
|
||||
func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
adminGroup := r.Group("/admin")
|
||||
base1Group := adminGroup.Group("/basic")
|
||||
|
||||
// 角色
|
||||
base1Group := adminGroup.Group("/role")
|
||||
{
|
||||
// 验证码
|
||||
base1Group.GET("captcha-test/:id", api.Basic.GetCaptchaTest)
|
||||
// 获取角色菜单列表
|
||||
base1Group.GET("menu", api.Role.GetRoleMenuList)
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,19 +6,19 @@ import (
|
||||
"errors"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/responses/basicResponse"
|
||||
"hospital-admin-api/utils"
|
||||
)
|
||||
|
||||
type Basic struct{}
|
||||
|
||||
// Login 登陆
|
||||
func (b *Basic) Login(login requests.Login) (responses.Login, error) {
|
||||
func (b *Basic) Login(login requests.Login) (basicResponse.Login, error) {
|
||||
// 获取用户信息
|
||||
AdminUserDao := dao.AdminUser{}
|
||||
adminUser, err := AdminUserDao.GetAdminUserFirstByAccess(login.Access)
|
||||
if err != nil || adminUser.UserID == 0 {
|
||||
return responses.Login{}, errors.New("用户名或密码错误")
|
||||
return basicResponse.Login{}, errors.New("用户名或密码错误")
|
||||
}
|
||||
|
||||
// 检测用户密码
|
||||
@ -27,16 +27,16 @@ func (b *Basic) Login(login requests.Login) (responses.Login, error) {
|
||||
passwordString := hex.EncodeToString(password[:])
|
||||
|
||||
if passwordString != adminUser.Password {
|
||||
return responses.Login{}, errors.New("用户名或密码错误")
|
||||
return basicResponse.Login{}, errors.New("用户名或密码错误")
|
||||
}
|
||||
|
||||
// 检测用户状态
|
||||
if adminUser.IsDeleted == 1 {
|
||||
return responses.Login{}, errors.New("非法用户")
|
||||
return basicResponse.Login{}, errors.New("非法用户")
|
||||
}
|
||||
|
||||
if adminUser.IsDisabled == 1 {
|
||||
return responses.Login{}, errors.New("您的账号已被禁用,请联系管理员处理")
|
||||
return basicResponse.Login{}, errors.New("您的账号已被禁用,请联系管理员处理")
|
||||
}
|
||||
|
||||
token := &utils.Token{
|
||||
@ -48,11 +48,11 @@ func (b *Basic) Login(login requests.Login) (responses.Login, error) {
|
||||
|
||||
jwt, err := token.NewJWT()
|
||||
if err != nil {
|
||||
return responses.Login{}, errors.New("登陆失败")
|
||||
return basicResponse.Login{}, errors.New("登陆失败")
|
||||
}
|
||||
|
||||
// 生成jwt
|
||||
result := responses.Login{
|
||||
result := basicResponse.Login{
|
||||
UserId: adminUser.UserID,
|
||||
NickName: adminUser.NickName,
|
||||
Avatar: adminUser.Avatar,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user