注册
This commit is contained in:
@@ -1,2 +1,43 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-print/dao"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetUsers(c *gin.Context, name, mobile, userID string) (users []*model.User, err error) {
|
||||
return dao.GetUsers(globals.GetDB(), userID, name, mobile)
|
||||
}
|
||||
|
||||
func RegisterUser(c *gin.Context, name, password string) (err error) {
|
||||
var (
|
||||
db = globals.GetDB()
|
||||
user = model.User{}
|
||||
now = time.Now()
|
||||
)
|
||||
if users, _ := dao.GetUsers(db, "", name, ""); len(users) > 0 {
|
||||
return fmt.Errorf("用户名重复!")
|
||||
}
|
||||
user.UserID = utils.GetUUID()
|
||||
user.Name = name
|
||||
user.Password = fmt.Sprintf("%x", md5.Sum([]byte(model.RegisterKey+password)))
|
||||
user.CreatedAt = &now
|
||||
user.UpdatedAt = &now
|
||||
user.DeletedAt = &utils.DefaultTimeValue
|
||||
err = dao.Insert(db, user)
|
||||
return err
|
||||
}
|
||||
|
||||
func Login(c *gin.Context, name, password, code string) (user *model.User, err error) {
|
||||
//var (
|
||||
// db = globals.GetDB()
|
||||
//)
|
||||
|
||||
return user, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user