新增登陆接口
This commit is contained in:
+15
-25
@@ -1,14 +1,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Basic struct{}
|
||||
@@ -42,13 +40,22 @@ func (b *Basic) Login(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
isValid := utils.VerifyCaptcha(login)
|
||||
if !isValid {
|
||||
// 验证码错误
|
||||
responses.FailWithMessage("验证码错误", c)
|
||||
// isValid := utils.VerifyCaptcha(login)
|
||||
// if !isValid {
|
||||
// // 验证码错误
|
||||
// responses.FailWithMessage("验证码错误", c)
|
||||
// return
|
||||
// }
|
||||
|
||||
// 登陆
|
||||
Basic := service.Basic{}
|
||||
token, err := Basic.Login(login)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
responses.Ok(c)
|
||||
|
||||
responses.OkWithData(token, c)
|
||||
}
|
||||
|
||||
// GetCaptchaTest 获取验证码
|
||||
@@ -100,20 +107,3 @@ func (b *Basic) GetCaptchaTest(c *gin.Context) {
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
func KeyMatch2(key1 string, key2 string) bool {
|
||||
key2 = strings.Replace(key2, "/*", "/.*", -1)
|
||||
fmt.Println(key2)
|
||||
re := regexp.MustCompile(`:[^/]+`)
|
||||
key2 = re.ReplaceAllString(key2, "$1[^/]+$2")
|
||||
|
||||
return RegexMatch(key1, "^"+key2+"$")
|
||||
}
|
||||
|
||||
func RegexMatch(key1 string, key2 string) bool {
|
||||
res, err := regexp.MatchString(key2, key1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user