This commit is contained in:
jiayuqi7813
2022-06-01 20:10:56 +08:00
parent 7cb171bc90
commit a9b48ea175
2 changed files with 26 additions and 33 deletions

View File

@@ -19,9 +19,6 @@ func Link() {
}
}
func Login(c *gin.Context) {
var request LoginRequest
var user User
@@ -80,7 +77,6 @@ func Login(c * gin.Context) {
}
func Register(c *gin.Context) {
var request RegisterRequest
var user User
@@ -147,10 +143,10 @@ func Register(c *gin.Context) {
}
c.JSON(200, gin.H{
"code": 200,
"success": "注册成功",
})
}
// Logout 实现用户注销登陆
@@ -178,6 +174,7 @@ func Logout(c *gin.Context) {
fmt.Sprintf("[%s] logout success!", user.Username)
c.JSON(200, gin.H{"code": 200, "msg": "Logout success!"})
}
//GetInfoByUserId 获取用户信息
func GetInfoByUserId(c *gin.Context) {
var info PublicInfoResponse
@@ -191,7 +188,6 @@ func GetInfoByUserId(c *gin.Context) {
}
//检查id是否合法
if !tools.CheckID(id) {
c.JSON(400, gin.H{"code": 400, "msg": "ID format error!"})
return
@@ -205,10 +201,8 @@ func GetInfoByUserId(c *gin.Context) {
}
c.JSON(200, gin.H{"code": 200, "data": info})
}
// checkUsername 验证用户名是否符合中文数字字母下划线横杠长度1到10位返回true或false
func checkUsername(username string) bool {
if !(utf8.RuneCountInString(username) > 0) || !(utf8.RuneCountInString(username) < 11) {
@@ -226,7 +220,6 @@ func checkEmail(email string) bool {
return reg.MatchString(email)
}
// checkPassword 验证密码是否符合长度6到20位返回true或false
func checkPassword(password string) bool {
if !(utf8.RuneCountInString(password) > 5) || !(utf8.RuneCountInString(password) < 21) {
@@ -234,6 +227,7 @@ func checkPassword(password string) bool {
}
return true
}
// isNameExisted 判断用户名是否已经被占用被占用返回true未被占用则返回false
func isNameExisted(user User, username string) bool {
Link()
@@ -245,6 +239,7 @@ func isNameExisted(user User, username string) bool {
return true
}
// isNameExisted 判断邮箱是否已经被占用被占用返回true未被占用则返回false
func isEmailExisted(user User, email string) bool {
Link()
@@ -268,8 +263,6 @@ func Session(c *gin.Context) {
c.JSON(200, gin.H{"code": 200, "data": user})
}
//下面是身份认证用 AUTH部分
// AuthRequired 用于普通用户权限控制的中间件
func AuthRequired() gin.HandlerFunc {

BIN
snctf.db

Binary file not shown.