作者 yangfu

用户中心 修改手机号 注销登录

... ... @@ -467,6 +467,47 @@ func (c *CompanyController) EditCompanyForUCenter() {
return
}
//UserChangePhone
//@router /ucenter/user/changePhone [post]
func (c *CompanyController) UserChangePhone() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Paremeter struct {
Ucid int64 `json:"id"` //统一用户中心id
Phone string `json:"phone"` //新手机号
}
var param Paremeter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
data, err := servecompany.ChangePhoneForUCenter(param.Ucid, param.Phone)
msg = protocol.NewReturnResponse(data, err)
}
//UserRevoke
//@router /ucenter/user/uerRevoke [post]
func (c *CompanyController) UserRevoke() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Paremeter struct {
Ucid int64 `json:"id"` //统一用户中心id
}
var param Paremeter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
data, err := servecompany.RevokeForUCenter(param.Ucid)
msg = protocol.NewReturnResponse(data, err)
}
//获取用户详情
//@router /user/info
func (c *CompanyController) UserDetail() {
... ...
... ... @@ -112,3 +112,16 @@ func GetUserAuthByUser(userId int64) (*UserAuth, error) {
}
return nil, err
}
func GetUserAuthByDeviceTye(userId int64, devType int8) (*UserAuth, error) {
o := orm.NewOrm()
uAuth := &UserAuth{
UserId: userId,
DeviceType: devType,
}
err := o.Read(uAuth, "UserId", "DeviceType")
if err == nil {
return uAuth, nil
}
return nil, err
}
... ...
... ... @@ -105,6 +105,8 @@ func init() {
beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"),
beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"),
beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"),
beego.NSRouter("/user/revoke", &controllers.CompanyController{}, "post:UserRevoke"),
beego.NSRouter("/user/changePhone", &controllers.CompanyController{}, "post:UserChangePhone"),
)
beego.AddNamespace(nsV1)
... ...
... ... @@ -5,6 +5,8 @@ import (
"oppmg/models"
"oppmg/protocol"
"oppmg/services/ucenter"
"oppmg/utils"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -488,3 +490,55 @@ func CompanyInfoForUCenter(uCenterid int64) (protocol.ResponseCenterCompany, err
}
return resp, nil
}
//统一用户中心 修改手机号
func ChangePhoneForUCenter(ucid int64, phone string) (rsp interface{}, err error) {
var (
user *models.User
)
if user, err = models.GetUserByUCenter(ucid); err != nil {
if err == orm.ErrNoRows {
return rsp, nil
}
return nil, protocol.NewErrWithMessage("1")
}
if user.Phone == strings.TrimSpace(phone) {
return
}
if err = utils.UpdateTableByMap(user, map[string]interface{}{"Phone": strings.TrimSpace(phone)}); err != nil {
log.Error(err.Error())
return
}
return
}
//统一用户中心 注销手机登录
func RevokeForUCenter(ucid int64) (rsp interface{}, err error) {
var (
user *models.User
userAuth *models.UserAuth
updateMap = make(map[string]interface{})
)
if user, err = models.GetUserByUCenter(ucid); err != nil {
if err == orm.ErrNoRows {
return rsp, nil
}
return nil, protocol.NewErrWithMessage("1")
}
if userAuth, err = models.GetUserAuthByDeviceTye(user.Id, 1); err != nil {
if err == orm.ErrNoRows {
return rsp, nil
}
return nil, protocol.NewErrWithMessage("1")
}
{
updateMap["AccessToken"] = ""
updateMap["RefreshToken"] = ""
updateMap["AuthCode"] = ""
}
if err = utils.UpdateTableByMap(userAuth, updateMap); err != nil {
log.Error(err.Error())
return
}
return
}
... ...