12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package user
- import (
- "authService/model"
- "authService/response"
- "authService/service/auth"
- "authService/util"
- )
- // 登录
- func Login(account, password string) (string, int, *response.ErrCode) {
- var token = ""
- var expireIn = 0
- existUser := FindByAccount(account)
- if existUser == nil {
- return token, expireIn, &response.ErrCode{
- Code: response.ERROR,
- Msg: "账号或密码不正确",
- }
- }
- // 如果被禁用,禁止登录
- if existUser.Status == model.UserStatusDisable {
- return token, expireIn, response.ErrAccountForbid
- }
- if existUser.Password != util.Md5(password) {
- return token, expireIn, &response.ErrCode{
- Code: response.ERROR,
- Msg: "账号或密码不正确",
- }
- }
- formatedUser := Format(existUser)
- token, expireIn, err := auth.Generate(formatedUser)
- if err != nil {
- return token, expireIn, err
- }
- return token, expireIn, nil
- }
- // 退出登录
- func Logout(userId int64) {
- auth.Exit(userId)
- }
|