作者 tangxuhui

添加 登录注册功能

package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type CompanySignUpCommand struct {
CompanyName string
Contacts string
IndustryCategory string
Password string
Phone string
Scale string
CompanyName string `json:"companyName"`
Contacts string `json:"contacts"`
IndustryCategory string `json:"industryCategory"`
Password string `json:"password"`
Phone string `json:"phone"`
Scale string `json:"scale"`
SmsCode string `json:"smsCode"`
}
func (orgAddCommand *CompanySignUpCommand) Valid(validation *validation.Validation) {
}
func (orgAddCommand *CompanySignUpCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgAddCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -29,6 +29,10 @@ func (srv *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDicti
//CompanySignUp 公司注册
func (srv *CommonService) CompanySignUp(signUpCommand *command.CompanySignUpCommand) (interface{}, error) {
if err := signUpCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//校验验证码
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(0, 0, 0)
_, err := creationUserGateway.AuthCompanySignUp(allied_creation_user.ReqAuthCompanySignUp{
CompanyName: signUpCommand.CompanyName,
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type LoginCommand struct {
Phone string `json:"phone"`
GrantType string `json:"grantType"` //登录方式(signInPassword 密码登录、signInCaptcha 验证码登录)
Phone string `json:"phone" valid:"Required"`
GrantType string `json:"grantType" valid:"Required"` //登录方式(signInPassword 密码登录、signInCaptcha 验证码登录)
Password string `json:"password"`
Captcha string `json:"captcha"`
}
func (orgAddCommand *LoginCommand) Valid(validation *validation.Validation) {
}
func (orgAddCommand *LoginCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgAddCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -140,7 +140,8 @@ loopUser1:
}
}
}
//记录上一次的登录公司组织信息不可用 ,重登录置记录
//记录上一次的登录公司组织信息不可用 ,重置登录记录
//使用找到的第一个可用的公司组织
if !currentOrgIsOK {
loopUser2:
for _, v := range userSeachResult.Users {
... ... @@ -181,6 +182,7 @@ loopUser1:
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//后处理redis缓存
tokenCache := cache.LoginTokenCache{}
tokenCache.RemoveAccessToken(currentAccess.Account, domain.LoginPlatformApp)
tokenCache.RemoveRefreshToken(currentAccess.Account, domain.LoginPlatformApp)
... ... @@ -291,6 +293,7 @@ loopUser1:
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//后处理redis缓存
tokenCache := cache.LoginTokenCache{}
tokenCache.RemoveAccessToken(currentAccess.Account, domain.LoginPlatformApp)
tokenCache.RemoveRefreshToken(currentAccess.Account, domain.LoginPlatformApp)
... ...
... ... @@ -2,6 +2,7 @@ package common_controller
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/service"
)
... ... @@ -17,3 +18,11 @@ func (controller *CommonController) GetDictionaryByCode() {
data, err := commonService.GetDictionaryByCode(&queryParm)
controller.Response(data, err)
}
func (controller *CommonController) CompanySignUp() {
commonService := service.NewCommonService(nil)
queryParm := command.CompanySignUpCommand{}
_ = controller.Unmarshal(queryParm)
data, err := commonService.CompanySignUp(&queryParm)
controller.Response(data, err)
}
... ...
... ... @@ -2,10 +2,12 @@ package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/common_controller"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
)
func init() {
web.Router("/v1/app/users/regist/company", &common_controller.CommonController{}, "Post:CompanySignUp")
web.Router("/v1/app/auth/login", &mobile_client.AuthController{}, "Post:Login")
web.Router("/v1/app/auth/access-token", &mobile_client.AuthController{}, "Post:GetAuthAccessToken")
web.Router("/v1/app/auth/refresh-token", &mobile_client.AuthController{}, "Post:RefreshAuthAccessToken")
... ...