Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
xuzhenhao
/
xuzhenhao-dev-icesimbapolysdklogin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit bbbdfe36
authored
Dec 11, 2017
by
xuzhenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了检查用户登录信息的接口
1 parent
bc10a748
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
0 deletions
src/loginserver/apis/loginserver.go
src/loginserver/models/user.go
src/loginserver/router.go
src/loginserver/apis/loginserver.go
View file @
bbbdfe3
...
...
@@ -18,6 +18,23 @@ import (
"time"
)
func
CheckUserLoginStateApi
(
c
*
gin
.
Context
)
{
token
,
err
:=
c
.
Cookie
(
"icesimbaToken"
)
if
err
!=
nil
{
log
.
Println
(
err
)
ReturnRespones
(
c
,
"104000"
,
err
)
return
}
r
,
err
:=
CheckRequestToken
(
token
)
if
err
!=
nil
{
log
.
Println
(
err
)
ReturnRespones
(
c
,
r
.
(
string
),
err
)
return
}
ReturnRespones
(
c
,
"0"
,
"success"
)
return
}
//登录接口
func
UserLoginApi
(
c
*
gin
.
Context
)
{
// buf := make([]byte, 1024)
...
...
src/loginserver/models/user.go
View file @
bbbdfe3
...
...
@@ -210,3 +210,16 @@ func MD5(str string) string {
return
str
}
func
CheckRequestToken
(
token
string
)
(
result
interface
{},
err
error
)
{
sql
:=
` select user_id from icesimba_user_token where user_token = ? limit 1`
r
,
err
:=
db
.
Engine
.
Query
(
sql
,
token
)
if
err
!=
nil
{
return
"104002"
,
err
}
if
len
(
r
)
==
0
{
err
=
errors
.
New
(
"token已失效"
)
return
""
,
nil
}
return
string
(
r
[
0
][
"user_id"
]),
nil
}
src/loginserver/router.go
View file @
bbbdfe3
...
...
@@ -16,5 +16,6 @@ func initRouter() *gin.Engine {
router
.
POST
(
"user/register"
,
UserRegisterApi
)
router
.
POST
(
"user/checkusername"
,
CheckUserNameRepeatApi
)
router
.
POST
(
"user/changepassword"
,
ChangeUserPasswordApi
)
router
.
GET
(
"/checkloginstate"
,
CheckUserLoginStateApi
)
return
router
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment