dongfeng-pay/legend/controllers/loginController.go
2021-04-27 15:33:49 +08:00

63 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controllers
import (
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
"legend/service"
)
type LoginController struct {
web.Controller
}
/**
**展示登录页面
*/
func (c *LoginController) LoginPage() {
c.TplName = "login.html"
}
/**
** 处理登录逻辑
*/
func (c *LoginController) Login() {
userName := c.GetString("username")
password := c.GetString("password")
logs.Info("username"+userName, ";password: "+password)
loginService := new(service.LoginService)
loginJsonData := loginService.Login(userName, password)
if loginJsonData.Code == 200 {
_ = c.SetSession("userName", userName)
}
c.Data["json"] = loginJsonData
err := c.ServeJSON()
if err != nil {
logs.Error("错误:", err)
}
}
/**
** 更新登录密码
*/
func (c *LoginController) PersonPassword() {
oldPassword := c.GetString("oldpass")
newPassword := c.GetString("newpass")
repeatPassword := c.GetString("repass")
logs.Debug("用户跟换密码,旧密码:%s, 新密码:%s确认密码%s", oldPassword, newPassword, repeatPassword)
userNname := c.GetSession("userName").(string)
loginService := new(service.LoginService)
loginJsonData := loginService.PersonPassword(newPassword, oldPassword, repeatPassword, userNname)
c.Data["json"] = loginJsonData
_ = c.ServeJSON()
}