作者 yangfu

登录流程修改

package command
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type QrcodeBindingCommand struct {
//操作人
Operator domain.Operator `json:"-"`
Key string `json:"key"`
}
... ...
... ... @@ -77,6 +77,7 @@ func (svr AuthService) AuthLoginPwd(loginCommand *command.LoginPwdCommand) (inte
Phone: loginCommand.Username,
Password: loginCommand.Password,
SessionMode: loginCommand.SessionMode,
DeviceType: loginCommand.DeviceType,
}
if len(loginCommand.CaptchaChallenge) > 0 {
geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
... ... @@ -98,6 +99,7 @@ func (svr AuthService) AuthLoginSms(loginCommand *command.LoginSmsCommand) (inte
Phone: loginCommand.Phone,
Captcha: loginCommand.Code,
SessionMode: loginCommand.SessionMode,
DeviceType: loginCommand.DeviceType,
}
return svr.AuthLogin(login)
}
... ... @@ -105,14 +107,23 @@ func (svr AuthService) AuthLoginSms(loginCommand *command.LoginSmsCommand) (inte
//AuthLoginQrcode 扫码登录
func (svr AuthService) AuthLoginQrcode(queryParam *query.QrcodeLoginStatusQuery) (interface{}, error) {
qrmsg := domain.QrcodeMessage{}
failLoginData := map[string]interface{}{
"isLogin": false,
"access": struct{}{},
}
err := qrmsg.ParseToken(queryParam.Key)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "二维码已失效")
}
qrCache := cache.LoginQrcodeCache{}
qrmsgCache, err := qrCache.Get(qrmsg.Id)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "二维码已失效")
}
if !qrmsgCache.IsLogin {
return failLoginData, nil
}
loginToken := domain.LoginToken{
UserId: qrmsgCache.UserId,
... ... @@ -126,6 +137,7 @@ func (svr AuthService) AuthLoginQrcode(queryParam *query.QrcodeLoginStatusQuery)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
qrCache.Remove(qrmsgCache.Id)
_ = accessToken
result, err := svr.getToken(loginToken)
data := map[string]interface{}{
... ... @@ -135,6 +147,28 @@ func (svr AuthService) AuthLoginQrcode(queryParam *query.QrcodeLoginStatusQuery)
return data, nil
}
//AuthLoginQrcodeBind 扫码登录-绑定
func (svr AuthService) AuthLoginQrcodeBinding(bindingCmd *command.QrcodeBindingCommand) (interface{}, error) {
qrmsg := domain.QrcodeMessage{}
err := qrmsg.ParseToken(bindingCmd.Key)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "二维码已失效,请重试")
}
qrCache := cache.LoginQrcodeCache{}
qrmsgCache, err := qrCache.Get(qrmsg.Id)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := qrmsgCache.BindUser(bindingCmd.Operator); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := qrCache.Save(*qrmsgCache); err != nil {
log.Logger.Error(err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录失败,请重试")
}
return struct{}{}, nil
}
//SendSmsCaptcha 发送验证码短信
func (svr AuthService) SendSmsCaptcha(smsCodeCommand *command.SendSmsCodeCommand) error {
smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
... ... @@ -199,6 +233,7 @@ func (svr AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
loginToken.Platform = accessTokenCommand.LoginPlatform
loginToken.SessionMode = accessTokenCommand.SessionMode
result, err := svr.getToken(*loginToken)
return result["token"], err
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
type OrgService struct {
}
//DepartmentsUsers 部门用户列表
func (srv OrgService) DepartmentsUsers(departmentsUsersQuery *query.DepartmentsUsersQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
departmentsUsersQuery.Operator)
orgs, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{
OrgId: departmentsUsersQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
users, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
//Offset: 0,
//Limit: 999,
CompanyId: departmentsUsersQuery.Operator.CompanyId,
OrganizationId: departmentsUsersQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
departmentUsersDto := &dto.DepartmentUsersDto{}
if err := departmentUsersDto.LoadDto(departmentsUsersQuery.Type, orgs, users); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return departmentUsersDto, nil
}
func NewOrgService(options map[string]interface{}) *OrgService {
newOrgService := &OrgService{}
return newOrgService
}
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
type DepartmentUsersDto struct {
Departments []*Department `json:"departments,omitempty"`
... ... @@ -12,6 +15,7 @@ type Department struct {
DepartmentName string `json:"departmentName"`
Users []User `json:"users"`
}
type User struct {
UserID int `json:"userId"`
UserCode string `json:"userCode"`
... ... @@ -34,6 +38,7 @@ func (dto *DepartmentUsersDto) LoadDto(dataType int, subDepartment *allied_creat
mapDepartment[-1] = &Department{
DepartmentID: -1,
DepartmentName: "共创部门",
Users: make([]User, 0),
}
for i := range subDepartment.Orgs {
... ... @@ -57,7 +62,7 @@ func (dto *DepartmentUsersDto) LoadDto(dataType int, subDepartment *allied_creat
"phone": user.UserInfo.Phone,
},
}
if user.Department == nil {
if (user.UserType & domain.UserTypeCooperation) > 0 {
mapDepartment[-1].Users = append(mapDepartment[-1].Users, u)
continue
}
... ...
... ... @@ -4,6 +4,8 @@ import (
"github.com/google/uuid"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
... ... @@ -135,3 +137,30 @@ func (srv UserService) DestroyAccount(destroyAccountCommand *command.DestroyAcco
}
return result, err
}
//DepartmentsUsers 部门用户列表
func (srv UserService) DepartmentsUsers(departmentsUsersQuery *query.DepartmentsUsersQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
departmentsUsersQuery.Operator)
orgs, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{
OrgId: departmentsUsersQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
users, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
//Offset: 0,
//Limit: 999,
CompanyId: departmentsUsersQuery.Operator.CompanyId,
OrganizationId: departmentsUsersQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
departmentUsersDto := &dto.DepartmentUsersDto{}
if err := departmentUsersDto.LoadDto(departmentsUsersQuery.Type, orgs, users); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return departmentUsersDto, nil
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
type DepartmentUsersDto struct {
Departments []*Department `json:"departments"`
}
type Department struct {
DepartmentID int64 `json:"departmentId,string"`
DepartmentName string `json:"departmentName"`
Users []User `json:"users"`
}
type User struct {
UserID int `json:"userId,string"`
UserCode string `json:"userCode"`
UserInfo map[string]interface{} `json:"userInfo"`
}
func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error {
var mapDepartment = make(map[int64]*Department)
mapDepartment[-1] = &Department{
DepartmentID: -1,
DepartmentName: "共创部门",
Users: make([]User, 0),
}
dto.Departments = append(dto.Departments, mapDepartment[-1])
for i := range subDepartment.Orgs {
org := subDepartment.Orgs[i]
dep := &Department{
DepartmentID: int64(org.OrgID),
DepartmentName: org.OrgName,
Users: make([]User, 0),
}
dto.Departments = append(dto.Departments, dep)
mapDepartment[dep.DepartmentID] = dep
}
for i := range userSearch.Users {
user := userSearch.Users[i]
u := User{
UserID: user.UserId,
UserCode: user.UserCode,
UserInfo: map[string]interface{}{
"userName": user.UserInfo.UserName,
"phone": user.UserInfo.Phone,
},
}
if (user.UserType & domain.UserTypeCooperation) > 0 {
mapDepartment[-1].Users = append(mapDepartment[-1].Users, u)
continue
}
if v, ok := mapDepartment[int64(user.Department.DepartmentId)]; ok {
v.Users = append(v.Users, u)
}
}
return nil
}
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
//获取自定义菜单列表
type DepartmentsUsersQuery struct {
//操作人
Operator domain.Operator `json:"-"`
}
func (departmentsUsersQuery *DepartmentsUsersQuery) Valid(validation *validation.Validation) {
}
func (departmentsUsersQuery *DepartmentsUsersQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(departmentsUsersQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ... @@ -147,33 +147,6 @@ func (orgsService *OrgsService) OrgGetSubDepartment(orgGetQuery *query.OrgGetSub
}, nil
}
//DepartmentsUsers 部门用户列表
func (orgsService OrgsService) DepartmentsUsers(departmentsUsersQuery *query.DepartmentsUsersQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
departmentsUsersQuery.Operator)
orgs, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{
OrgId: departmentsUsersQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
users, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
//Offset: 0,
//Limit: 999,
CompanyId: departmentsUsersQuery.Operator.CompanyId,
OrganizationId: departmentsUsersQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
departmentUsersDto := &dto.DepartmentUsersDto{}
if err := departmentUsersDto.LoadDto(orgs, users); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return departmentUsersDto, nil
}
func NewOrgsService(options map[string]interface{}) *OrgsService {
newOrgsService := &OrgsService{}
return newOrgsService
... ...
... ... @@ -79,3 +79,16 @@ func (qrmsg *QrcodeMessage) ParseToken(str string) error {
}
return nil
}
func (qrmsg *QrcodeMessage) BindUser(operator Operator) error {
if qrmsg.IsLogin {
return fmt.Errorf("登录中")
}
qrmsg.UserId = operator.UserId
qrmsg.OrgId = operator.OrgId
qrmsg.CompanyId = operator.CompanyId
qrmsg.UserBaseId = operator.UserBaseId
qrmsg.Account = operator.Phone
qrmsg.IsLogin = true
return nil
}
... ...
... ... @@ -20,7 +20,7 @@ func (lq LoginQrcodeCache) Save(qrcode domain.QrcodeMessage) error {
nowTime := time.Now().Unix()
exp := qrcode.ExpiresAt - nowTime
if exp <= 0 {
exp = 60 * 60 * 2
exp = 60 * 5
}
key := lq.keyString(qrcode.Id)
bt, _ := json.Marshal(qrcode)
... ...
... ... @@ -7,6 +7,7 @@ import (
func TransformToLoginAccessDomainModelFromPgModels(loginAccessModel *models.LoginAccess) (*domain.LoginAccess, error) {
return &domain.LoginAccess{
LoginAccessId: loginAccessModel.LoginAccessId,
Account: loginAccessModel.Account,
Platform: loginAccessModel.Platform,
CompanyId: loginAccessModel.CompanyId,
... ...
... ... @@ -22,6 +22,7 @@ func (controller *AuthController) LoginPwd() {
authService := service.AuthService{}
loginCmd := &command.LoginPwdCommand{}
Must(controller.Unmarshal(loginCmd))
loginCmd.DeviceType = controller.GetDeviceType()
data, err := authService.AuthLoginPwd(loginCmd)
controller.Response(data, err)
}
... ... @@ -30,6 +31,7 @@ func (controller *AuthController) LoginSms() {
authService := service.AuthService{}
loginCmd := &command.LoginSmsCommand{}
Must(controller.Unmarshal(loginCmd))
loginCmd.DeviceType = controller.GetDeviceType()
data, err := authService.AuthLoginSms(loginCmd)
controller.Response(data, err)
}
... ... @@ -164,14 +166,24 @@ func (controller *AuthController) GetQrcode() {
controller.Response(data, err)
}
func (controller *AuthController) QrcodeLoginStatus() {
func (controller *AuthController) LoginQrcode() {
authService := service.AuthService{}
cmd := &query.QrcodeLoginStatusQuery{}
Must(controller.Unmarshal(cmd))
cmd.DeviceType = controller.GetDeviceType()
data, err := authService.AuthLoginQrcode(cmd)
controller.Response(data, err)
}
func (controller *AuthController) QrcodeBinding() {
authService := service.AuthService{}
cmd := &command.QrcodeBindingCommand{}
Must(controller.Unmarshal(cmd))
cmd.Operator = controller.GetOperator()
data, err := authService.AuthLoginQrcodeBinding(cmd)
controller.Response(data, err)
}
func (controller *AuthController) CheckSmsCode() {
authService := service.AuthService{}
cmd := &command.CheckSmsCodeCommand{}
... ...
... ... @@ -98,6 +98,10 @@ func (controller *BaseController) GetOperator() domain.Operator {
return op
}
func (controller *BaseController) GetDeviceType() string {
return controller.Ctx.Input.Header("x-mmm-devicetype")
}
func Must(err error) {
if err != nil {
log.Logger.Error(err.Error())
... ...
package mobile_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/service"
)
type OrgController struct {
baseController
}
func (controller *OrgController) DepartmentUsers() {
orgService := service.OrgService{}
departmentsUsersQuery := &query.DepartmentsUsersQuery{}
err := controller.Unmarshal(departmentsUsersQuery)
if err != nil {
controller.Response(nil, err)
return
}
departmentsUsersQuery.Operator = controller.GetOperator()
data, err := orgService.DepartmentsUsers(departmentsUsersQuery)
controller.Response(data, err)
}
... ... @@ -2,6 +2,7 @@ package mobile_client
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/service"
)
... ... @@ -84,3 +85,16 @@ func (controller *UserController) DestroyAccount() {
data, err := authService.DestroyAccount(cmd)
controller.Response(data, err)
}
func (controller *UserController) DepartmentUsers() {
orgService := service.UserService{}
departmentsUsersQuery := &query.DepartmentsUsersQuery{}
err := controller.Unmarshal(departmentsUsersQuery)
if err != nil {
controller.Response(nil, err)
return
}
departmentsUsersQuery.Operator = controller.GetOperator()
data, err := orgService.DepartmentsUsers(departmentsUsersQuery)
controller.Response(data, err)
}
... ...
... ... @@ -82,16 +82,3 @@ func (controller *OrgsController) OrgGetSubDepartment() {
data, err := orgsService.OrgGetSubDepartment(orgGetSubDepartmentQuery)
controller.Response(data, err)
}
func (controller *OrgsController) DepartmentUsers() {
orgService := service.OrgsService{}
departmentsUsersQuery := &query.DepartmentsUsersQuery{}
err := controller.Unmarshal(departmentsUsersQuery)
if err != nil {
controller.Response(nil, err)
return
}
departmentsUsersQuery.Operator = controller.GetOperator()
data, err := orgService.DepartmentsUsers(departmentsUsersQuery)
controller.Response(data, err)
}
... ...
... ... @@ -9,7 +9,8 @@ func init() {
//web.Router("/v1/auth/login", &controllers.AuthController{}, "Post:Login")
web.Router("/v1/auth/login/pwd", &controllers.AuthController{}, "Post:LoginPwd")
web.Router("/v1/auth/login/sms", &controllers.AuthController{}, "Post:LoginSms")
web.Router("/v1/auth/login/qrcode", &controllers.AuthController{}, "Post:QrcodeLoginStatus")
web.Router("/v1/auth/login/qrcode", &controllers.AuthController{}, "Post:LoginQrcode")
web.Router("/v1/auth/login/qrcode-binding", &controllers.AuthController{}, "Post:QrcodeBinding")
web.Router("/v1/auth/captcha-init", &controllers.AuthController{}, "Get:CaptchaInit")
web.Router("/v1/auth/qrcode-init", &controllers.AuthController{}, "Post:GetQrcode")
web.Router("/v1/auth/sms-code", &controllers.AuthController{}, "Post:SendSmsCode")
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
)
func init() {
web.Router("/v1/app/orgs/department-users", &mobile_client.OrgController{}, "Post:DepartmentUsers")
}
... ... @@ -17,4 +17,9 @@ func init() {
web.Router("/v1/user/change-phone", &mobile_client.UserController{}, "Post:ChangePhone")
web.Router("/v1/user/personal", &mobile_client.UserController{}, "Post:UpdateUserInfo")
web.Router("/v1/user/destroy-account", &mobile_client.UserController{}, "Post:DestroyAccount")
web.Router("/v1/user/department-users", &mobile_client.UserController{}, "Post:DepartmentUsers")
// 特殊处理
web.Router("/v1/app/orgs/department-users", &mobile_client.UserController{}, "Post:DepartmentUsers")
web.Router("/v1/web/orgs/department-users", &mobile_client.UserController{}, "Post:DepartmentUsers")
}
... ...
... ... @@ -12,5 +12,4 @@ func init() {
web.Router("/v1/web/orgs/:orgId", &web_client.OrgsController{}, "Get:OrgGet")
web.Router("/v1/web/orgs/enable", &web_client.OrgsController{}, "Post:OrgEnable")
web.Router("/v1/web/orgs/departments", &web_client.OrgsController{}, "Post:OrgGetSubDepartment")
web.Router("/v1/web/orgs/department-users", &web_client.OrgsController{}, "Post:DepartmentUsers")
}
... ...