代码拉取完成,页面将自动刷新
/*
* @Author: drowningwhale 351231768@qq.com
* @Date: 2023-09-30 13:50:19
* @LastEditors: drowningwhale 351231768@qq.com
* @LastEditTime: 2023-10-02 18:51:56
* @FilePath: \bluebell\dao\mysql\user.go
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
package mysql
import (
"crypto/md5"
"encoding/hex"
"fmt"
"gitee.com/mq-go/bluebell/dao"
"gitee.com/mq-go/bluebell/global"
"gitee.com/mq-go/bluebell/models"
"go.uber.org/zap"
)
// 创建盐值
var secret = "https://gitee.com/mq-go/bluebell"
// HavingUser 查询用户是否存在
func HavingUser(username string) error {
user := models.User{
UserName: username,
}
result := global.DB.Where(&models.User{UserName: username}).First(&user)
if result.Error != nil {
zap.L().Error("select user failed : ", zap.Error(result.Error))
return result.Error
}
return nil
}
// SignUpUser 创建用户
func SignUpUser(param *models.ParamSignUp) error {
user := models.User{
UserId: int(dao.GenID()),
UserName: param.UserName,
PassWord: param.PassWord,
}
user.PassWord = encryptPassword(user.PassWord)
result := global.DB.Create(&user)
if result.Error != nil {
zap.L().Error("create user failed : ", zap.Error(result.Error))
return result.Error
}
return nil
}
// ComparePassWord 密码验证
func ComparePassWord(user *models.User) error {
password := encryptPassword(user.PassWord)
result := global.DB.Where(&models.User{UserName: user.UserName}).First(&user)
if result.RowsAffected == 0 {
return fmt.Errorf("record not found")
}
if result.Error != nil {
zap.L().Error("select error : ", zap.Error(result.Error))
return result.Error
}
//比对
if user.PassWord != password {
return fmt.Errorf("password error")
}
return nil
}
func GetUserById(id int)(User models.User, err error){
result := global.DB.Where(&models.User{UserId: id}).First(&User)
if result.Error != nil{
err = result.Error
return
}
return
}
// 密码加密
func encryptPassword(password string) string {
h := md5.New()
h.Write([]byte(secret))
password = hex.EncodeToString(h.Sum([]byte(password)))
return hex.EncodeToString(h.Sum([]byte(password)))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。