auth_controller.go 5.9 KB
package controllers

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/auth/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/auth/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/auth/service"
)

type AuthController struct {
	BaseController
}

func (controller *AuthController) Login() {
	authService := service.AuthService{}
	loginCmd := &command.LoginCommand{}
	Must(controller.Unmarshal(loginCmd))
	data, err := authService.AuthLogin(loginCmd)
	controller.Response(data, err)
}

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)
}

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)
}

func (controller *AuthController) SendSmsCode() {
	authService := service.AuthService{}
	cmd := &command.SendSmsCodeCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	err = authService.SendSmsCaptcha(cmd)
	controller.Response(nil, err)
}

func (controller *AuthController) GetAuthAccessToken() {
	authService := service.AuthService{}
	accessTokenCommand := &command.AccessTokenCommand{}
	err := controller.Unmarshal(accessTokenCommand)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	data, err := authService.GetAuthAccessToken(accessTokenCommand)
	controller.Response(data, err)
}

func (controller *AuthController) RefreshAuthAccessToken() {
	authService := service.AuthService{}
	refreshTokenCmd := &command.RefreshTokenCommand{}
	err := controller.Unmarshal(refreshTokenCmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	data, err := authService.RefreshAuthAccessToken(refreshTokenCmd)
	controller.Response(data, err)
}

func (controller *AuthController) GetUserInfo() {
	authService := service.AuthService{}
	userInfoCommand := &command.UserInfoCommand{}
	err := controller.Unmarshal(userInfoCommand)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	userInfoCommand.Operator = controller.GetOperator()
	data, err := authService.GetUserInfo(userInfoCommand)
	controller.Response(data, err)
}

func (controller *AuthController) GetUserMenus() {
	authService := service.AuthService{}
	userMenusCommand := &command.UserMenusCommand{}
	err := controller.Unmarshal(userMenusCommand)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	userMenusCommand.Operator = controller.GetOperator()
	data, err := authService.GetUserMenus(userMenusCommand)
	controller.Response(data, err)
}

func (controller *AuthController) GetUserOrg() {
	authService := service.AuthService{}
	userOrgCommand := &command.UserOrgCommand{}
	err := controller.Unmarshal(userOrgCommand)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	userOrgCommand.Operator = controller.GetOperator()
	data, err := authService.GetUserOrg(userOrgCommand)
	controller.Response(data, err)
}

func (controller *AuthController) CompanySignUp() {
	authService := service.AuthService{}
	userOrgCommand := &command.CompanySignUpCommand{}
	err := controller.Unmarshal(userOrgCommand)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	//userOrgCommand.Operator = controller.GetOperator()
	data, err := authService.CompanySignUp(userOrgCommand)
	controller.Response(data, err)
}

func (controller *AuthController) ResetPassword() {
	authService := service.AuthService{}
	userOrgCommand := &command.ResetPasswordCommand{}
	err := controller.Unmarshal(userOrgCommand)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	//userOrgCommand.Operator = controller.GetOperator()
	data, err := authService.ResetPassword(userOrgCommand)
	controller.Response(data, err)
}

func (controller *AuthController) OrgSwitch() {
	authService := service.AuthService{}
	cmd := &command.SwitchOrgCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	cmd.Operator = controller.GetOperator()
	data, err := authService.OrgSwitch(cmd)
	controller.Response(data, err)
}

func (controller *AuthController) GetCompanyOrgsByUser() {
	authService := service.AuthService{}
	cmd := &query.GetCompanyOrgsByUserQuery{}
	Must(controller.Unmarshal(cmd))

	cmd.Operator = controller.GetOperator()
	data, err := authService.GetCompanyOrgsByUser(cmd)
	controller.Response(data, err)
}

func (controller *AuthController) GetQrcode() {
	authService := service.AuthService{}
	data, err := authService.GetQrcode()
	controller.Response(data, err)
}

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{}
	Must(controller.Unmarshal(cmd))
	data, err := authService.CheckSmsCode(cmd)
	controller.Response(data, err)
}

func (controller *AuthController) CaptchaInit() {
	authService := service.AuthService{}
	cmd := &query.CaptchaInitRequest{}
	Must(controller.Unmarshal(cmd))
	cmd.UserIp = controller.Ctx.Request.RemoteAddr
	data, err := authService.CaptchaInit(cmd)
	controller.Response(data, err)
}