auth_controller.go 2.2 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/auth/command"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/auth/query"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/auth/service"
)

type AuthController struct {
	beego.BaseController
}

func (controller *AuthController) Login() {
	authService := service.NewAuthService(nil)
	loginQuery := &query.LoginQuery{}
	controller.Unmarshal(loginQuery)
	data, err := authService.Login(loginQuery)
	controller.Response(data, err)
}

func (controller *AuthController) LoginByCompany() {
	authService := service.NewAuthService(nil)
	loginByCompanyCommand := &command.LoginByCompanyCommand{}
	controller.Unmarshal(loginByCompanyCommand)
	data, err := authService.LoginByCompany(loginByCompanyCommand)
	controller.Response(data, err)
}

func (controller *AuthController) AccessToken() {
	authService := service.NewAuthService(nil)
	accessTokenCommand := &command.AccessTokenCommand{}
	controller.Unmarshal(accessTokenCommand)
	data, err := authService.AccessToken(accessTokenCommand)
	controller.Response(data, err)
}

func (controller *AuthController) RefreshToken() {
	authService := service.NewAuthService(nil)
	refreshTokenCommand := &command.RefreshTokenCommand{}
	controller.Unmarshal(refreshTokenCommand)
	data, err := authService.RefreshToken(refreshTokenCommand)
	controller.Response(data, err)
}

func (controller *AuthController) SendSmsCode() {
	authService := service.NewAuthService(nil)
	sendSmsCodeCommand := &command.SendSmsCodeCommand{}
	controller.Unmarshal(sendSmsCodeCommand)
	data, err := authService.SendSmsCode(sendSmsCodeCommand)
	controller.Response(data, err)
}

func (controller *AuthController) Revoke() {
	authService := service.NewAuthService(nil)
	revokeCommand := &command.RevokeCommand{}
	controller.Unmarshal(revokeCommand)
	data, err := authService.Revoke(revokeCommand)
	controller.Response(data, err)
}

func (controller *AuthController) ChangePassword() {
	authService := service.NewAuthService(nil)
	changePasswordCommand := &command.ChangePasswordCommand{}
	controller.Unmarshal(changePasswordCommand)
	data, err := authService.ChangePassword(changePasswordCommand)
	controller.Response(data, err)
}