Compare commits
No commits in common. "63215bba4a654c273be940b5bc1fac24ac45ea5c" and "356ab8962b22282b21dd61a0427a67352a5658b3" have entirely different histories.
63215bba4a
...
356ab8962b
|
|
@ -17,7 +17,6 @@ type User struct {
|
||||||
Redis bool `gorm:"column:redis"`
|
Redis bool `gorm:"column:redis"`
|
||||||
Run bool `gorm:"column:run"`
|
Run bool `gorm:"column:run"`
|
||||||
Upload bool `gorm:"column:upload"`
|
Upload bool `gorm:"column:upload"`
|
||||||
Avatar string `gorm:"column:avatar"`
|
|
||||||
CreateTime string `gorm:"column:create_time"`
|
CreateTime string `gorm:"column:create_time"`
|
||||||
UpdateTime string `gorm:"column:update_time"`
|
UpdateTime string `gorm:"column:update_time"`
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +75,3 @@ func FindUserByEmail(email string) User {
|
||||||
func UpdateUserByID(id int, name, password, email string) {
|
func UpdateUserByID(id int, name, password, email string) {
|
||||||
DB.Model(&User{}).Where("id = ?", id).Updates(User{Name: name, Password: password, Email: email})
|
DB.Model(&User{}).Where("id = ?", id).Updates(User{Name: name, Password: password, Email: email})
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateUserByID2(id int, req proto.UpdateUserInfoReq) {
|
|
||||||
DB.Model(&User{}).Where("id = ?", id).Updates(User{Name: req.Username, Age: req.Age, Role: req.Role, Run: req.Run, Redis: req.Redis, Upload: req.Upload, Avatar: req.Avatar, Gender: req.Gender})
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ func SetUpUserGroup(router *gin.Engine) {
|
||||||
userGroup.POST("/confirm", ConfirmQRLogin)
|
userGroup.POST("/confirm", ConfirmQRLogin)
|
||||||
userGroup.POST("/search", SearchHandler)
|
userGroup.POST("/search", SearchHandler)
|
||||||
userGroup.POST("/info", GetUserInfo)
|
userGroup.POST("/info", GetUserInfo)
|
||||||
userGroup.POST("/update", UpdateUserInfo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RLReq struct {
|
type RLReq struct {
|
||||||
|
|
@ -46,53 +45,13 @@ type SearchReq struct {
|
||||||
Keyword string `json:"keyword" form:"keyword"`
|
Keyword string `json:"keyword" form:"keyword"`
|
||||||
ID int `json:"id" form:"id"`
|
ID int `json:"id" form:"id"`
|
||||||
}
|
}
|
||||||
type GetUserInfoReq struct {
|
|
||||||
ID int `json:"id" form:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetUserInfo(c *gin.Context) {
|
func GetUserInfo(c *gin.Context) {
|
||||||
var req_data GetUserInfoReq
|
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
user_id := int(id.(float64))
|
user_id := int(id.(float64))
|
||||||
if err := c.ShouldBind(&req_data); err == nil {
|
user := dao.FindUserByID2(user_id)
|
||||||
var user dao.User
|
user.Password = "" //不返回密码
|
||||||
if req_data.ID == user_id {
|
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": user})
|
||||||
user = dao.FindUserByID2(user_id)
|
|
||||||
user.Password = "" //不返回密码
|
|
||||||
} else {
|
|
||||||
//判断当前用户是否有权限查看
|
|
||||||
cur_user := dao.FindUserByID2(user_id)
|
|
||||||
if cur_user.Role == "admin" {
|
|
||||||
user = dao.FindUserByID2(req_data.ID)
|
|
||||||
user.Password = "" //不返回密码
|
|
||||||
} else {
|
|
||||||
c.JSON(200, gin.H{"code": proto.PermissionDenied, "message": "无权查看", "data": "2"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": user})
|
|
||||||
} else {
|
|
||||||
c.JSON(200, gin.H{"code": proto.ParameterError, "message": err, "data": "2"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateUserInfo(c *gin.Context) {
|
|
||||||
var req_data proto.UpdateUserInfoReq
|
|
||||||
id, _ := c.Get("id")
|
|
||||||
user_id := int(id.(float64))
|
|
||||||
if err := c.ShouldBind(&req_data); err == nil {
|
|
||||||
rid, err2 := service.UpdateUser(user_id, req_data)
|
|
||||||
if err2 != nil {
|
|
||||||
c.JSON(200, gin.H{"code": proto.OperationFailed, "message": "failed", "data": "2"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": rid})
|
|
||||||
} else {
|
|
||||||
c.JSON(200, gin.H{"code": proto.ParameterError, "message": err, "data": "2"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetScanUUID(c *gin.Context) {
|
func GetScanUUID(c *gin.Context) {
|
||||||
|
|
|
||||||
8
main.go
8
main.go
|
|
@ -86,11 +86,9 @@ func JWTAuthMiddleware() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果请求为login或register,则不需要验证token
|
//如果请求为login或register,则不需要验证token
|
||||||
for k, _ := range proto.Url_map {
|
if strings.Contains(c.Request.URL.Path, "/login") || strings.Contains(c.Request.URL.Path, "/register") || strings.Contains(c.Request.URL.Path, "/uuid") || strings.Contains(c.Request.URL.Path, "/gqr") || strings.Contains(c.Request.URL.Path, "/cid/callback") {
|
||||||
if strings.Contains(c.Request.URL.Path, k) {
|
c.Next()
|
||||||
c.Next()
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if tokenString == "" {
|
if tokenString == "" {
|
||||||
//c.AbortWithStatus(200)
|
//c.AbortWithStatus(200)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
var Config ConfigStruct
|
var Config ConfigStruct
|
||||||
var SigningKey = []byte{}
|
var SigningKey = []byte{}
|
||||||
var Url_map = map[string]bool{"/login": true, "/register": true, "/uuid": true, "/gqr": true, "/cid/callback": true}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MYSQL_USER = "video_t2"
|
MYSQL_USER = "video_t2"
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,8 @@ const (
|
||||||
TokenParseError = 19 // Token解析错误
|
TokenParseError = 19 // Token解析错误
|
||||||
|
|
||||||
// 用户名密码相关错误码
|
// 用户名密码相关错误码
|
||||||
UsernameOrPasswordError = 6 // 用户名或密码错误
|
UsernameOrPasswordError = 6 // 用户名或密码错误
|
||||||
UsernameExists = 7 // 用户名已存在
|
UsernameExists = 7 // 用户名已存在
|
||||||
PermissionDenied = 21 // 权限不足
|
|
||||||
|
|
||||||
// Redis相关错误码
|
// Redis相关错误码
|
||||||
RedisSetError = 8 // 设置redis错误
|
RedisSetError = 8 // 设置redis错误
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package proto
|
|
||||||
|
|
||||||
type UpdateUserInfoReq struct {
|
|
||||||
ID int `json:"id" form:"id"` //用户id
|
|
||||||
Username string `json:"username" form:"username"` //用户名
|
|
||||||
Age int `json:"age" form:"age"` //年龄
|
|
||||||
Role string `json:"role" form:"role"` //角色
|
|
||||||
Gender string `json:"gender" form:"gender"` //性别
|
|
||||||
Redis bool `json:"redis" form:"redis"` //是否刷新redis
|
|
||||||
Upload bool `json:"upload" form:"upload"` //是否上传头像
|
|
||||||
Run bool `json:"run" form:"run"` //是否运行
|
|
||||||
Avatar string `json:"avatar" form:"avatar"` //头像
|
|
||||||
}
|
|
||||||
|
|
@ -41,16 +41,3 @@ func GetUserByID(id int) []proto.User {
|
||||||
func GetUserByNameLike(name string) []proto.User {
|
func GetUserByNameLike(name string) []proto.User {
|
||||||
return dao.FindUserByNameLike(name)
|
return dao.FindUserByNameLike(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateUser(user_id int, req proto.UpdateUserInfoReq) (int, error) {
|
|
||||||
cur_user := dao.FindUserByID2(user_id)
|
|
||||||
if user_id == req.ID {
|
|
||||||
dao.UpdateUserByID2(user_id, req)
|
|
||||||
return user_id, nil
|
|
||||||
} else if cur_user.Role == "admin" {
|
|
||||||
dao.UpdateUserByID2(req.ID, req)
|
|
||||||
return req.ID, nil
|
|
||||||
} else {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -346,29 +346,3 @@ func GetRedisBitmap(key string, offset int64) int {
|
||||||
}
|
}
|
||||||
return int(val)
|
return int(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发布订阅者模式-发布消息
|
|
||||||
func Publish(channel string, message string, expire time.Duration) {
|
|
||||||
ctx := context.Background()
|
|
||||||
err := redisClient.Publish(ctx, channel, message).Err()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error publishing message: %v", err)
|
|
||||||
}
|
|
||||||
err = redisClient.Expire(ctx, channel, expire).Err()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error setting key: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发布订阅者模式-订阅消息
|
|
||||||
func Subscribe(channel string) []string {
|
|
||||||
ctx := context.Background()
|
|
||||||
pubsub := redisClient.Subscribe(ctx, channel)
|
|
||||||
ch := pubsub.Channel()
|
|
||||||
defer pubsub.Close()
|
|
||||||
var messages []string
|
|
||||||
for msg := range ch {
|
|
||||||
messages = append(messages, msg.Payload)
|
|
||||||
}
|
|
||||||
return messages
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue