- 添加用户最后登录信息
This commit is contained in:
@@ -65,6 +65,7 @@ type IUserProvider interface {
|
||||
UpdateUserMobile(userID string, mobile string) (err error)
|
||||
UpdateUserEmail(userID string, email string) (err error)
|
||||
UpdateUserType(userID string, userTypeMask int8, updateType int) (err error)
|
||||
UpdateLastLogin(userID string, lastLoginType, fromIP string) (err error)
|
||||
// CreateUser(userID2, mobile, email, name string) (user IUser, err error)
|
||||
}
|
||||
|
||||
@@ -222,7 +223,7 @@ func SendVerifyCode(authToken, captchaID, captchaValue, authID string) (err erro
|
||||
// 公众号登录:authIDTypeD是UserIDEmpty,authSecret是code(这个函数是被微信的回调调用,不是直接被客户端调用)
|
||||
// 微信登录:authIDType是UserIDEmpty,authSecret是code(这个函数是被微信的回调调用,不是直接被客户端调用)
|
||||
// 小程序登录:authIDType是UserIDEmpty,authSecret是jsCode
|
||||
func Login(authType, authID, authIDType, authSecret string) (authInfo *AuthInfo, err error) {
|
||||
func Login(ctx *Context, authType, authID, authIDType, authSecret string) (authInfo *AuthInfo, err error) {
|
||||
authType = strings.ToLower(authType)
|
||||
authIDType = strings.ToLower(authIDType)
|
||||
if handler := authers[authType]; handler != nil {
|
||||
@@ -266,6 +267,9 @@ func Login(authType, authID, authIDType, authSecret string) (authInfo *AuthInfo,
|
||||
}
|
||||
}
|
||||
authInfo = createAuthInfo(user, authBindEx)
|
||||
if user != nil && user.GetID() != "" {
|
||||
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = ErrIllegalAuthType
|
||||
|
||||
@@ -3,6 +3,7 @@ package cms
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
|
||||
@@ -87,6 +88,17 @@ func (*UserProvider) UpdateUserType(userID string, userTypeMask int8, updateType
|
||||
return err
|
||||
}
|
||||
|
||||
func (*UserProvider) UpdateLastLogin(userID string, lastLoginType, fromIP string) (err error) {
|
||||
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
"LastLoginAt": utils.Time2Pointer(time.Now()),
|
||||
"LastLoginType": lastLoginType,
|
||||
"LastLoginIP": fromIP,
|
||||
}, model.AdminName, map[string]interface{}{
|
||||
"UserID": userID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// func (*UserProvider) CreateUser(userID2, mobile, email, name string) (user auth2.IUser, err error) {
|
||||
// realUser := &model.User{
|
||||
// UserID2: userID2,
|
||||
@@ -102,7 +114,7 @@ func init() {
|
||||
}
|
||||
|
||||
func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVerifyCode string, inAuthInfo *auth2.AuthInfo) (outAuthInfo *auth2.AuthInfo, err error) {
|
||||
mobileAuth, err2 := auth2.Login(auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
mobileAuth, err2 := auth2.Login(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
if err = err2; err == nil {
|
||||
if !mobileAuth.IsUserEmpty() {
|
||||
return nil, jsonerr.New(mobileAuth, model.ErrCodeJsonUserAlreadyExist)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package model
|
||||
|
||||
import "git.rosy.net.cn/baseapi/utils"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
UserStatusNormal = 1
|
||||
@@ -40,6 +44,10 @@ type User struct {
|
||||
|
||||
IDCardNo string `orm:"size(18);column(id_card_no)" json:"idCardNo" compact:"idCardNo"` // 身份证号
|
||||
Remark string `orm:"size(255)" json:"remark"`
|
||||
|
||||
LastLoginAt *time.Time `orm:"null" json:"lastLoginAt"`
|
||||
LastLoginIP string `orm:"size(64);column(last_login_ip)" json:"lastLoginIP"`
|
||||
LastLoginType string `orm:"size(16)" json:"lastLoginType"`
|
||||
}
|
||||
|
||||
func (*User) TableUnique() [][]string {
|
||||
|
||||
@@ -88,7 +88,8 @@ func (c *Auth2Controller) Login() {
|
||||
if params.AuthType == weixin.AuthTypeMini {
|
||||
params.AuthSecret = GetComposedCode(&c.Controller, params.AuthSecret)
|
||||
}
|
||||
retVal, err = auth2.Login(params.AuthType, params.AuthID, params.AuthIDType, params.AuthSecret)
|
||||
ctx := auth2.NewContext(c.Ctx.ResponseWriter, c.Ctx.Request)
|
||||
retVal, err = auth2.Login(ctx, params.AuthType, params.AuthID, params.AuthIDType, params.AuthSecret)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -127,7 +128,8 @@ func (c *Auth2Controller) WeixinOAuth2() {
|
||||
callResult *CallResult
|
||||
)
|
||||
c.callWeixinOAuth2(func(params *tAuth2WeixinOAuth2Params) (retVal interface{}, errCode string, err error) {
|
||||
authInfo, err := auth2.Login(weixin.AuthTypeWeixin, params.State, "", params.Code)
|
||||
ctx := auth2.NewContext(c.Ctx.ResponseWriter, c.Ctx.Request)
|
||||
authInfo, err := auth2.Login(ctx, weixin.AuthTypeWeixin, params.State, "", params.Code)
|
||||
if err == nil {
|
||||
callResult = &CallResult{
|
||||
Code: model.ErrCodeSuccess,
|
||||
@@ -160,7 +162,8 @@ func (c *Auth2Controller) WeixinMPOAuth2() {
|
||||
callResult *CallResult
|
||||
)
|
||||
c.callWeixinMPOAuth2(func(params *tAuth2WeixinMPOAuth2Params) (retVal interface{}, errCode string, err error) {
|
||||
authInfo, err := auth2.Login(weixin.AuthTypeMP, params.State, "", params.Code)
|
||||
ctx := auth2.NewContext(c.Ctx.ResponseWriter, c.Ctx.Request)
|
||||
authInfo, err := auth2.Login(ctx, weixin.AuthTypeMP, params.State, "", params.Code)
|
||||
if err == nil {
|
||||
callResult = &CallResult{
|
||||
Code: model.ErrCodeSuccess,
|
||||
@@ -197,7 +200,8 @@ func (c *Auth2Controller) DingDingOAuth2() {
|
||||
params.Block = params.State
|
||||
params.State = ""
|
||||
}
|
||||
authInfo, err := auth2.Login(dingding.AuthTypeQRCode, params.State, "", params.Code)
|
||||
ctx := auth2.NewContext(c.Ctx.ResponseWriter, c.Ctx.Request)
|
||||
authInfo, err := auth2.Login(ctx, dingding.AuthTypeQRCode, params.State, "", params.Code)
|
||||
if err == nil {
|
||||
callResult = &CallResult{
|
||||
Code: model.ErrCodeSuccess,
|
||||
|
||||
Reference in New Issue
Block a user