package admin_api_controllers

import (
	"Xcx_New/enums"
	"Xcx_New/service"
)

type LoginAPIController struct {
	AdminBaseAPIController
}

// /admin/api/login/pwd [post] LoginByPwd
// @param account:string
// @param password:string
func (this *LoginAPIController) LoginByPwd() {
	account := this.GetString("account")
	password := this.GetString("password")

	admin, getAdminErr := service.GetAdminAccount(account, password)
	if getAdminErr != nil {
		this.ErrorLog("获取管理员信息失败:%v", getAdminErr)
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
		return
	} else if admin == nil {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
		return
	}

	this.SetSession("admin_info", &AdminInfo{
		Admin: admin,
	})
	this.ServeSuccessJSON(map[string]interface{}{
		"admin": admin,
	})
}
