...
|
...
|
@@ -182,7 +182,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
}
|
|
|
userdata, err = models.GetUserByUCenter(uclientReturn.Data.Id)
|
|
|
if err != nil {
|
|
|
log.Debug("GetUserByPhone(%s) err:%s", account, err)
|
|
|
log.Debug("GetUserByUCenter(%d) err:%s", uclientReturn.Data.Id, err)
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
if ok := userdata.IsDelete(); ok {
|
...
|
...
|
@@ -231,7 +231,7 @@ type companybase struct { |
|
|
}
|
|
|
|
|
|
//getUserCompanyReal 获取用户有效的公司id
|
|
|
func getUserCompanyReal(userid int64) ([]companybase, error) {
|
|
|
func getUserCompanyReal(userId int64) ([]companybase, error) {
|
|
|
const (
|
|
|
datasql0 string = `SELECT b.company_id FROM user_company AS b
|
|
|
WHERE b.delete_at=0 AND b.enable = 1 AND b.user_id=?`
|
...
|
...
|
@@ -243,7 +243,7 @@ func getUserCompanyReal(userid int64) ([]companybase, error) { |
|
|
ids []string
|
|
|
err error
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&ids, datasql0, userid)
|
|
|
err = utils.ExecuteQueryAll(&ids, datasql0, userId)
|
|
|
if err != nil {
|
|
|
log.Error("EXECUTE SQL err:%s", err)
|
|
|
return nil, err
|
...
|
...
|
@@ -326,3 +326,75 @@ func GetUserHasMenu(userid, companyid int64) ([]protocol.PermissionItem, error) |
|
|
}
|
|
|
return list, nil
|
|
|
}
|
|
|
|
|
|
func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, error) {
|
|
|
var (
|
|
|
err error
|
|
|
logintoken protocol.LoginAuthToken
|
|
|
companys []companybase
|
|
|
companyid int64
|
|
|
userdata *models.User
|
|
|
)
|
|
|
var uclientReturn *ucenter.ResponseLoginSms
|
|
|
uclientReturn, err = ucenter.RequestUCenterLoginSms(phone, code)
|
|
|
if err != nil {
|
|
|
return logintoken, protocol.NewErrWithMessage("10028")
|
|
|
}
|
|
|
userdata, err = models.GetUserByUCenter(uclientReturn.Data.Cuid)
|
|
|
if err != nil {
|
|
|
log.Debug("GetUserByUCenter(%s) err:%s", uclientReturn.Data.Cuid, err)
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
if ok := userdata.IsDelete(); ok {
|
|
|
log.Debug("userdata.IsDelete()==true")
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
if ok := userdata.IsEnable(); !ok {
|
|
|
log.Debug("userdata.IsEnable()==false")
|
|
|
return logintoken, protocol.NewErrWithMessage("10022")
|
|
|
}
|
|
|
if companys, err = getUserCompanyReal(userdata.Id); err != nil {
|
|
|
log.Error("getUserCompanyReal err:%s", err)
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
if len(companys) == 0 {
|
|
|
log.Debug("no company")
|
|
|
return logintoken, protocol.NewErrWithMessage("10022")
|
|
|
}
|
|
|
//获取上一次登录的公司
|
|
|
uAuth, err := models.GetUserAuthByUser(userdata.Id)
|
|
|
if err == nil {
|
|
|
companyid = uAuth.CurrentCompanyId
|
|
|
} else {
|
|
|
companyid = companys[0].Id
|
|
|
}
|
|
|
|
|
|
//更新用户数据
|
|
|
userdata.Accid = uclientReturn.Data.CsAccountID
|
|
|
userdata.Icon = uclientReturn.Data.Image.Path
|
|
|
userdata.ImToken = uclientReturn.Data.Imtoken
|
|
|
userdata.NickName = uclientReturn.Data.Uname
|
|
|
userdata.LastLoginTime = time.Now()
|
|
|
err = models.UpdateUserById(userdata, []string{"Accid", "Icon", "ImToken", "NickName", "LastLoginTime"})
|
|
|
if err != nil {
|
|
|
log.Error("更新用户数据失败:%s", err)
|
|
|
}
|
|
|
logintoken, _ = GenerateAuthToken(userdata.Id, companyid)
|
|
|
return logintoken, err
|
|
|
}
|
|
|
|
|
|
func LoginSmsCodeSend(phone string) error {
|
|
|
var (
|
|
|
err error
|
|
|
)
|
|
|
_, err = models.GetUserByPhone(phone)
|
|
|
if err != nil {
|
|
|
log.Error("GetUserByPhone(%s) err:%s", phone, err)
|
|
|
return protocol.NewErrWithMessage("10027")
|
|
|
}
|
|
|
err = ucenter.RequestUCenterSmsCode(phone)
|
|
|
if err != nil {
|
|
|
return protocol.NewErrWithMessage("10029")
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|