53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"yitao/ecode"
|
|
"yitao/model"
|
|
"yitao/util"
|
|
)
|
|
|
|
type UserService struct{}
|
|
|
|
func (u *UserService) AuthLogin(username string, password string) (user *model.UserModel, e *ecode.Ecode) {
|
|
e = ecode.Common(ecode.AUTH_OK)
|
|
// 验证用户名密码,返回 jwt
|
|
user = new(model.UserModel)
|
|
model.DB.Where("username=?", username).First(user)
|
|
if util.MD5(user.Secret+password+user.Secret) != user.Passhash {
|
|
// 密码错误
|
|
return user, ecode.Auth(ecode.PASSWORD_ERROR)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (u *UserService) AuthSignup(username string, password string) (user *model.UserModel, e *ecode.Ecode) {
|
|
e = ecode.Common(ecode.AUTH_OK)
|
|
// 验证用户名密码,返回 jwt
|
|
user = new(model.UserModel)
|
|
var c int64
|
|
model.DB.Where("username=?", username).Count(&c)
|
|
if c > 0 {
|
|
// 用户名已存在
|
|
return user, ecode.Auth(ecode.USERNAME_EXIST)
|
|
}
|
|
user.Username = username
|
|
user.Secret = util.RandString(16)
|
|
user.Passhash = util.MD5(user.Secret + password + user.Secret)
|
|
user.Status = model.UserStatusComfirmed
|
|
model.DB.Create(user)
|
|
return
|
|
}
|
|
|
|
func (u *UserService) RegisterationCheck(invite bool, max_user_check bool, ip_check bool, edu bool) (e *ecode.Ecode) {
|
|
common_service := new(CommonService)
|
|
setting := common_service.GetSetting("main")
|
|
if invite {
|
|
// 邀请注册,查看是否开启了可被邀请注册
|
|
invitesystem := setting["invitesystem"] == "true"
|
|
fmt.Printf("invitesystem: %v\n", invitesystem)
|
|
}
|
|
return ecode.OK()
|
|
}
|