Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
member-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
member-api
Commits
729e0e2e
Commit
729e0e2e
authored
Sep 29, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加会员登陆
parent
e32f2d82
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
0 deletions
+129
-0
MemberLoginController.java
...main/java/com/egolm/film/login/MemberLoginController.java
+49
-0
MemberTokenService.java
...java/com/egolm/film/login/service/MemberTokenService.java
+7
-0
MemberTokenServiceImpl.java
...egolm/film/login/service/impl/MemberTokenServiceImpl.java
+73
-0
No files found.
src/main/java/com/egolm/film/login/MemberLoginController.java
0 → 100644
View file @
729e0e2e
package
com
.
egolm
.
film
.
login
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.MemberTokenService
;
import
com.egolm.film.model.LoginToken
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
@Api
@Controller
@RequestMapping
(
"member"
)
public
class
MemberLoginController
{
@Autowired
private
MemberTokenService
tokenService
;
@ResponseBody
@PostMapping
(
"login"
)
@ApiOperation
(
"fc_user登陆"
)
public
Object
login
(
String
username
,
String
password
)
{
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
"用户已登录"
,
200
);
}
else
{
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
if
(
token
!=
null
)
{
return
Rjx
.
jsonOk
().
setData
(
token
);
}
else
{
throw
new
XException
(
"用户名或密码错误"
);
}
}
}
@ResponseBody
@PostMapping
(
"logout"
)
@ApiOperation
(
"fc_user退出"
)
public
Object
logout
()
{
tokenService
.
doLogout
();
return
Rjx
.
jsonOk
();
}
}
src/main/java/com/egolm/film/login/service/MemberTokenService.java
0 → 100644
View file @
729e0e2e
package
com
.
egolm
.
film
.
login
.
service
;
public
interface
MemberTokenService
extends
TokenService
{
final
String
TOKEN_NAME
=
"FILM_MEMBER_LOGIN_TOKEN_NAME"
;
}
src/main/java/com/egolm/film/login/service/impl/MemberTokenServiceImpl.java
0 → 100644
View file @
729e0e2e
package
com
.
egolm
.
film
.
login
.
service
.
impl
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.egolm.common.StringUtil
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.MemberTokenService
;
import
com.egolm.film.model.LoginToken
;
@Service
public
class
MemberTokenServiceImpl
implements
MemberTokenService
{
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Override
public
LoginToken
getToken
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
LoginToken
token
=
(
LoginToken
)
session
.
getAttribute
(
TOKEN_NAME
);
return
token
;
}
@Override
public
LoginToken
doLogin
(
String
username
,
String
password
)
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
String
md5String
=
StringUtil
.
toMD5HexString
(
password
);
String
loginSql
=
"select * from fc_member where username = ? and password = ?"
;
List
<
Map
<
String
,
Object
>>
list
=
this
.
jdbcTemplate
.
queryForList
(
loginSql
,
username
,
md5String
);
if
(
list
!=
null
)
{
if
(
list
.
size
()
==
1
)
{
Map
<
String
,
Object
>
map
=
list
.
get
(
0
);
Integer
state
=
(
Integer
)
map
.
get
(
"state"
);
if
(
state
==
1
)
{
Integer
adminid
=
(
Integer
)
map
.
get
(
"adminid"
);
LoginToken
token
=
new
LoginToken
(
adminid
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
return
token
;
}
else
if
(
state
==
2
)
{
throw
new
XException
(
"用户已禁用"
);
}
else
{
throw
new
XException
(
"用户状态未知"
);
}
}
else
if
(
list
.
size
()
==
0
)
{
throw
new
XException
(
"用户名或密码错误"
);
}
else
{
throw
new
XException
(
"用户登陆信息重复,请联系管理员"
);
}
}
else
{
throw
new
XException
(
"用户名或密码错误"
);
}
}
@Override
public
void
doLogout
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
session
.
removeAttribute
(
TOKEN_NAME
);
session
.
invalidate
();
}
@Override
public
boolean
isLogin
()
{
return
this
.
getToken
()
!=
null
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment