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 15c300e5
authored
Dec 12, 2017
by
xuzhenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正了跨域问题
1 parent
a6b95a8c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
9 deletions
src/loginserver/apis/loginserver.go
src/loginserver/models/user.go
src/loginserver/router.go
src/loginserver/apis/loginserver.go
View file @
15c300e
...
...
@@ -13,7 +13,7 @@ import (
// "net/url"
// "os"
// "reflect"
//
"strconv"
"strconv"
// "strings"
"time"
)
...
...
@@ -120,15 +120,27 @@ func CheckUserNameRepeatApi(c *gin.Context) {
//修改密码接口
func
ChangeUserPasswordApi
(
c
*
gin
.
Context
)
{
userName
:=
c
.
Request
.
FormValue
(
"user_name"
)
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
}
userId
,
err
:=
strconv
.
Atoi
(
r
.
(
string
))
userOriginPassword
:=
c
.
Request
.
FormValue
(
"user_origin_password"
)
userNewPassword
:=
c
.
Request
.
FormValue
(
"user_new_password"
)
if
user
Name
==
""
||
user
OriginPassword
==
""
||
userNewPassword
==
""
{
log
.
Println
(
"user
Name:"
,
userName
,
"userOriginPassword:"
,
userOriginPassword
,
"userNewPassword:"
,
userNewPassword
)
if
userOriginPassword
==
""
||
userNewPassword
==
""
{
log
.
Println
(
"user
Id:"
,
userId
,
"userOriginPassword:"
,
userOriginPassword
,
"userNewPassword:"
,
userNewPassword
)
ReturnRespones
(
c
,
"104002"
,
"参数错误"
)
return
}
result
,
err
:=
ChangeUserPassword
(
user
Name
,
userOriginPassword
,
userNewPassword
)
result
,
err
:=
ChangeUserPassword
(
user
Id
,
userOriginPassword
,
userNewPassword
)
if
err
!=
nil
{
log
.
Println
(
err
)
ReturnRespones
(
c
,
result
.
(
string
),
err
.
Error
())
...
...
src/loginserver/models/user.go
View file @
15c300e
...
...
@@ -111,9 +111,26 @@ func GetUserInfoByUserName(userName string) (result interface{}, err error) {
}
//获取用户信息
func
GetUserInfoByUserId
(
userId
int
)
(
result
interface
{},
err
error
)
{
u
:=
make
([]
UserInfo
,
0
)
sql
:=
` select id,user_name,user_password from icesimba_polysdk_user where id = ? limit 1`
err
=
db
.
Engine
.
Sql
(
sql
,
userId
)
.
Find
(
&
u
)
if
err
!=
nil
{
return
"104001"
,
err
}
if
len
(
u
)
==
0
{
err
=
errors
.
New
(
"不存在的用户id"
)
return
"105003"
,
err
}
return
u
[
0
],
nil
}
//修改用户密码
func
ChangeUserPassword
(
user
Name
string
,
originPassword
string
,
newPassword
string
)
(
result
interface
{},
err
error
)
{
r
,
err
:=
GetUserInfoByUser
Name
(
userName
)
func
ChangeUserPassword
(
user
Id
int
,
originPassword
string
,
newPassword
string
)
(
result
interface
{},
err
error
)
{
r
,
err
:=
GetUserInfoByUser
Id
(
userId
)
if
err
!=
nil
{
return
r
,
err
}
...
...
@@ -127,8 +144,8 @@ func ChangeUserPassword(userName string, originPassword string, newPassword stri
return
"105002"
,
err
}
password
=
MD5
(
newPassword
)
sql
:=
` update icesimba_polysdk_user set user_password = ? where
user_name
= ?`
_
,
err
=
db
.
Engine
.
Exec
(
sql
,
password
,
user
Name
)
sql
:=
` update icesimba_polysdk_user set user_password = ? where
id
= ?`
_
,
err
=
db
.
Engine
.
Exec
(
sql
,
password
,
user
Id
)
if
err
!=
nil
{
return
"104001"
,
err
}
...
...
src/loginserver/router.go
View file @
15c300e
...
...
@@ -13,6 +13,7 @@ func initRouter() *gin.Engine {
router
:=
gin
.
Default
()
config
:=
cors
.
DefaultConfig
()
config
.
AllowOrigins
=
[]
string
{
"http://127.0.0.1:8000"
}
config
.
AllowCredentials
=
true
router
.
Use
(
cors
.
New
(
config
))
router
.
POST
(
"user/login"
,
UserLoginApi
)
router
.
POST
(
"user/register"
,
UserRegisterApi
)
...
...
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