修复bug

This commit is contained in:
jiayuqi7813
2022-07-16 02:16:31 +08:00
parent e70bde7bd4
commit 0cd63a7111
4 changed files with 52 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ func Login(c *gin.Context) {
//code 1用户名或密码错误
err := DB.Take(&user, "username = ?", request.Username).Error
if err != nil {
c.JSON(200, gin.H{
"Error": true,
@@ -193,7 +194,7 @@ func GetInfoByUserId(c *gin.Context) {
return
}
err := DB.Debug().Raw("SELECT username,affiliation,country,team_id FROM user WHERE id = ? LIMIT 1", id).Scan(&info).Error
err := DB.Debug().Raw("SELECT username,affiliation,country,team_id,website FROM user WHERE id = ? LIMIT 1", id).Scan(&info).Error
//err := DB.Where("id = ?", id).First(user).Error
if err != nil {
c.JSON(400, gin.H{"code": 400, "msg": "Get info error!"})
@@ -203,6 +204,44 @@ func GetInfoByUserId(c *gin.Context) {
}
// UpdateUserInfo 更新用户信息
func UpdateUserInfo(c *gin.Context) {
var user User
var request UpdateUserInfoRequest
if err := c.ShouldBindJSON(&request); err != nil {
c.JSON(400, gin.H{"code": 400, "msg": "Request format wrong!"})
return
}
Link()
DB := db.DBsnctf
session, err := Store.Get(c.Request, "SNCTFSESSID")
if err != nil {
c.JSON(200, gin.H{"code": 400, "msg": "Get SNCTFSESSID error"})
}
user, ok := session.Values["user"].(User)
if !ok {
c.JSON(200, gin.H{"code": 400, "msg": "No session"})
}
//获取用户id
userid := user.ID
//获取传入数据
username := request.Name
affiliation := request.Affiliation
country := request.Country
website := request.Website
email := request.Email
//数据库更新数据
err = DB.Model(&user).Where("id = ?", userid).Update("username", username).Update("affiliation", affiliation).Update("country", country).Update("website", website).Update("email", email).Error
if err != nil {
c.JSON(200, gin.H{"code": 400, "msg": "Update info error!"})
return
}
//更新session
session.Values["user"] = user
c.JSON(200, gin.H{"code": 200, "msg": "Update info success!"})
}
// GetAllUserInfo 获取所有用户信息
func GetAllUserInfo(c *gin.Context) {
var info PublicAllInfoResponse