Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
beauty_ssm
提交
e6dc4a62
B
beauty_ssm
项目概览
爱吃血肠
/
beauty_ssm
通知
9
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beauty_ssm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e6dc4a62
编写于
3月 25, 2018
作者:
爱吃血肠
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化注册模块
上级
d7b2911a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
91 addition
and
5 deletion
+91
-5
src/main/java/com/yingjun/ssm/dao/UserDao.java
src/main/java/com/yingjun/ssm/dao/UserDao.java
+7
-0
src/main/java/com/yingjun/ssm/service/UserService.java
src/main/java/com/yingjun/ssm/service/UserService.java
+7
-0
src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
...in/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
+25
-4
src/main/java/com/yingjun/ssm/util/Md5Util.java
src/main/java/com/yingjun/ssm/util/Md5Util.java
+42
-0
src/main/resources/mapper/UserMapper.xml
src/main/resources/mapper/UserMapper.xml
+9
-0
src/main/webapp/WEB-INF/jsp/user/userResgiter.jsp
src/main/webapp/WEB-INF/jsp/user/userResgiter.jsp
+1
-1
未找到文件。
src/main/java/com/yingjun/ssm/dao/UserDao.java
浏览文件 @
e6dc4a62
...
...
@@ -71,4 +71,11 @@ public interface UserDao {
* @return
*/
public
User
checkUserLogin
(
User
user
);
/**
* 根据邮箱查询当前登录用户
* @param email
* @return
*/
public
User
queryUserByEmail
(
String
email
);
}
\ No newline at end of file
src/main/java/com/yingjun/ssm/service/UserService.java
浏览文件 @
e6dc4a62
...
...
@@ -81,4 +81,11 @@ public interface UserService {
* @param user
*/
public
void
userRegister
(
User
user
,
String
code
,
HttpSession
session
);
/**
* 检查用户是否已经注册
* @param email
* @return
*/
public
User
queryUserByEmail
(
String
email
);
}
\ No newline at end of file
src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
浏览文件 @
e6dc4a62
...
...
@@ -4,6 +4,7 @@ import com.yingjun.ssm.dao.UserDao;
import
com.yingjun.ssm.entity.User
;
import
com.yingjun.ssm.exception.BizException
;
import
com.yingjun.ssm.service.UserService
;
import
com.yingjun.ssm.util.Md5Util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -71,6 +72,8 @@ public class UserServiceImpl implements UserService {
@Override
public
User
checkUserLogin
(
User
user
)
{
try
{
//加密密码
user
.
setPassword
(
Md5Util
.
md5Password
(
user
.
getPassword
()));
User
loginUser
=
userDao
.
checkUserLogin
(
user
);
if
(
loginUser
==
null
){
throw
new
BizException
(
"用户不存在"
);
...
...
@@ -94,19 +97,27 @@ public class UserServiceImpl implements UserService {
@Override
public
void
userRegister
(
User
user
,
String
code
,
HttpSession
session
)
{
try
{
User
user1
=
queryUserByEmail
(
user
.
getEmail
());
if
(
user1
!=
null
){
throw
new
BizException
(
"用户已经注册"
);
}
String
emailCode
=
(
String
)
session
.
getAttribute
(
"code"
);
if
(!
emailCode
.
equals
(
code
)){
throw
new
BizException
(
"验证码错误"
);
}
//加密密码
if
(
user
!=
null
){
user
.
setPassword
(
Md5Util
.
md5Password
(
user
.
getPassword
()));
}
else
{
return
;
}
if
(
1
!=
userDao
.
insertTUser
(
user
)){
throw
new
Exception
(
"插入数据影响函数不唯一"
);
}
}
catch
(
BizException
biz
){
LOG
.
error
(
"验证码错误"
,
biz
);
throw
new
BizException
(
"验证码错误"
);
throw
new
BizException
(
biz
.
getMessage
(),
biz
);
}
catch
(
Exception
e
){
LOG
.
error
(
"插入数据影响函数不唯一"
,
e
);
throw
new
BizException
(
"插入数据影响函数不唯一"
);
throw
new
RuntimeException
(
"插入数据影响函数不唯一"
,
e
);
}
}
...
...
@@ -118,4 +129,14 @@ public class UserServiceImpl implements UserService {
this
.
userDao
=
userDao
;
}
/**
* 检查用户是否已经注册
* @param email
* @return
*/
@Override
public
User
queryUserByEmail
(
String
email
){
return
userDao
.
queryUserByEmail
(
email
);
}
}
\ No newline at end of file
src/main/java/com/yingjun/ssm/util/Md5Util.java
0 → 100644
浏览文件 @
e6dc4a62
package
com.yingjun.ssm.util
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
/**
* md5加密实现
* @author liyunfeng
*/
public
class
Md5Util
{
/**
* 生成32位md5码
* @param password
* @return
*/
public
static
String
md5Password
(
String
password
)
{
try
{
// 得到一个信息摘要器
MessageDigest
digest
=
MessageDigest
.
getInstance
(
"md5"
);
byte
[]
result
=
digest
.
digest
(
password
.
getBytes
());
StringBuffer
buffer
=
new
StringBuffer
();
// 把每一个byte 做一个与运算 0xff;
for
(
byte
b
:
result
)
{
// 与运算
int
number
=
b
&
0xff
;
String
str
=
Integer
.
toHexString
(
number
);
if
(
str
.
length
()
==
1
)
{
buffer
.
append
(
"0"
);
}
buffer
.
append
(
str
);
}
// 标准的md5加密后的结果
return
buffer
.
toString
();
}
catch
(
NoSuchAlgorithmException
e
)
{
return
""
;
}
}
}
src/main/resources/mapper/UserMapper.xml
浏览文件 @
e6dc4a62
...
...
@@ -123,4 +123,13 @@
<if
test=
"password != null "
>
and t_user.password = #{password}
</if>
</where>
</select>
<!--查询用户是否已经注册-->
<select
id=
"queryUserByEmail"
parameterType=
"com.yingjun.ssm.entity.User"
resultType=
"com.yingjun.ssm.entity.User"
>
select
<include
refid=
"t_user_Column"
/>
from t_user
where
t_user.email = #{email}
</select>
</mapper>
\ No newline at end of file
src/main/webapp/WEB-INF/jsp/user/userResgiter.jsp
浏览文件 @
e6dc4a62
...
...
@@ -106,7 +106,7 @@
alert
(
"
注册成功
"
);
window
.
location
.
href
=
"
/user/login
"
;
}
else
{
alert
(
"
注册失败
"
);
alert
(
data
.
error
);
}
}
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录