|
@@ -1,6 +1,5 @@
|
|
|
package com.uas.platform.b2bManage.service.impl;
|
|
package com.uas.platform.b2bManage.service.impl;
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.uas.message.mail.service.MailService;
|
|
import com.uas.message.mail.service.MailService;
|
|
|
import com.uas.platform.b2bManage.core.support.SystemSession;
|
|
import com.uas.platform.b2bManage.core.support.SystemSession;
|
|
|
import com.uas.platform.b2bManage.core.util.StringUtils;
|
|
import com.uas.platform.b2bManage.core.util.StringUtils;
|
|
@@ -10,11 +9,10 @@ import com.uas.platform.b2bManage.model.Constant;
|
|
|
import com.uas.platform.b2bManage.model.SecretKeyRecord;
|
|
import com.uas.platform.b2bManage.model.SecretKeyRecord;
|
|
|
import com.uas.platform.b2bManage.model.User;
|
|
import com.uas.platform.b2bManage.model.User;
|
|
|
import com.uas.platform.b2bManage.service.UserService;
|
|
import com.uas.platform.b2bManage.service.UserService;
|
|
|
|
|
+import com.uas.platform.b2bManage.support.MyException;
|
|
|
import com.uas.platform.b2bManage.support.SecurityConstant;
|
|
import com.uas.platform.b2bManage.support.SecurityConstant;
|
|
|
import com.uas.platform.b2bManage.support.StringUtil;
|
|
import com.uas.platform.b2bManage.support.StringUtil;
|
|
|
-import com.uas.platform.core.util.AgentUtils;
|
|
|
|
|
import com.uas.platform.core.util.encry.Md5Utils;
|
|
import com.uas.platform.core.util.encry.Md5Utils;
|
|
|
-import javassist.NotFoundException;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -26,14 +24,13 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.io.UnsupportedEncodingException;
|
|
|
-import java.net.URLEncoder;
|
|
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 用户数据接口
|
|
* 用户数据接口
|
|
|
*
|
|
*
|
|
|
- * Created by hejq on 2018-04-23.
|
|
|
|
|
|
|
+ * @author hejq
|
|
|
|
|
+ * @date 2018-04-23
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
public class UserServiceImpl implements UserService {
|
|
public class UserServiceImpl implements UserService {
|
|
@@ -51,7 +48,7 @@ public class UserServiceImpl implements UserService {
|
|
|
* 通过电话号码查询用户信息
|
|
* 通过电话号码查询用户信息
|
|
|
*
|
|
*
|
|
|
* @param tel 电话
|
|
* @param tel 电话
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @return User
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public User findByTel(String tel) {
|
|
public User findByTel(String tel) {
|
|
@@ -63,7 +60,7 @@ public class UserServiceImpl implements UserService {
|
|
|
* 通过邮箱查询用户信息
|
|
* 通过邮箱查询用户信息
|
|
|
*
|
|
*
|
|
|
* @param email 邮箱
|
|
* @param email 邮箱
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @return User
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public User findUserByUserEmail(String email) {
|
|
public User findUserByUserEmail(String email) {
|
|
@@ -75,7 +72,7 @@ public class UserServiceImpl implements UserService {
|
|
|
* 通过用户名查询用户信息
|
|
* 通过用户名查询用户信息
|
|
|
*
|
|
*
|
|
|
* @param name
|
|
* @param name
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @return User
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public User findUserByName(String name) {
|
|
public User findUserByName(String name) {
|
|
@@ -91,23 +88,26 @@ public class UserServiceImpl implements UserService {
|
|
|
*
|
|
*
|
|
|
* @param userName 账号
|
|
* @param userName 账号
|
|
|
* @param passWord 密码
|
|
* @param passWord 密码
|
|
|
|
|
+ * @param request request
|
|
|
|
|
+ * @param response response
|
|
|
|
|
+ * @throws MyException 自定义异常
|
|
|
|
|
+ * @throws UnsupportedEncodingException 编码异常
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public void login(String userName, String passWord, HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, UnsupportedEncodingException {
|
|
|
|
|
|
|
+ public void login(String userName, String passWord, HttpServletRequest request, HttpServletResponse response) throws MyException, UnsupportedEncodingException {
|
|
|
List<User> users = userDao.findByTel(userName);
|
|
List<User> users = userDao.findByTel(userName);
|
|
|
if (CollectionUtils.isEmpty(users)) {
|
|
if (CollectionUtils.isEmpty(users)) {
|
|
|
users = userDao.findByEmail(userName);
|
|
users = userDao.findByEmail(userName);
|
|
|
if (CollectionUtils.isEmpty(users)) {
|
|
if (CollectionUtils.isEmpty(users)) {
|
|
|
- throw new IllegalAccessException("未找到账号信息");
|
|
|
|
|
|
|
+ throw new MyException("未找到账号信息");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
User user = users.get(0);
|
|
User user = users.get(0);
|
|
|
if (Md5Utils.encode(passWord, user.getName()).equals(user.getPassword())) {
|
|
if (Md5Utils.encode(passWord, user.getName()).equals(user.getPassword())) {
|
|
|
SystemSession.setUser(user);
|
|
SystemSession.setUser(user);
|
|
|
request.getSession().setAttribute("user", user);
|
|
request.getSession().setAttribute("user", user);
|
|
|
- request.getSession().setAttribute("ipAddress", AgentUtils.getIp(request));
|
|
|
|
|
} else {
|
|
} else {
|
|
|
- throw new IllegalAccessException("账号或密码错误");
|
|
|
|
|
|
|
+ throw new MyException("账号或密码错误");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -115,7 +115,7 @@ public class UserServiceImpl implements UserService {
|
|
|
* 注册用户
|
|
* 注册用户
|
|
|
*
|
|
*
|
|
|
* @param user 用户信息
|
|
* @param user 用户信息
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @return User
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public User register(User user) {
|
|
public User register(User user) {
|
|
@@ -156,11 +156,15 @@ public class UserServiceImpl implements UserService {
|
|
|
* 通过访问链接修改密码
|
|
* 通过访问链接修改密码
|
|
|
*
|
|
*
|
|
|
* @param secretKey 秘钥
|
|
* @param secretKey 秘钥
|
|
|
- * @param response 请求
|
|
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @param response 请求
|
|
|
|
|
+ * @param request request
|
|
|
|
|
+ * @return User
|
|
|
|
|
+ * @throws IOException
|
|
|
|
|
+ * @throws MyException
|
|
|
|
|
+ * @throws ServletException
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public User resetPwd(String secretKey, HttpServletResponse response, HttpServletRequest request) throws IOException, NotFoundException, ServletException {
|
|
|
|
|
|
|
+ public User resetPwd(String secretKey, HttpServletResponse response, HttpServletRequest request) throws IOException, MyException, ServletException {
|
|
|
if (StringUtils.isEmpty(secretKey)) {
|
|
if (StringUtils.isEmpty(secretKey)) {
|
|
|
response.sendRedirect(Constant.INVALIDURL);
|
|
response.sendRedirect(Constant.INVALIDURL);
|
|
|
}
|
|
}
|
|
@@ -174,7 +178,7 @@ public class UserServiceImpl implements UserService {
|
|
|
} else {
|
|
} else {
|
|
|
List<User> users = userDao.findByEmail(record.getEmail().trim());
|
|
List<User> users = userDao.findByEmail(record.getEmail().trim());
|
|
|
if (CollectionUtils.isEmpty(users)) {
|
|
if (CollectionUtils.isEmpty(users)) {
|
|
|
- throw new NotFoundException("未找到该邮箱用户信息");
|
|
|
|
|
|
|
+ throw new MyException("未找到该邮箱用户信息");
|
|
|
} else {
|
|
} else {
|
|
|
SystemSession.setUser(users.get(0));
|
|
SystemSession.setUser(users.get(0));
|
|
|
request.getSession().setAttribute("user", users.get(0));
|
|
request.getSession().setAttribute("user", users.get(0));
|
|
@@ -191,6 +195,7 @@ public class UserServiceImpl implements UserService {
|
|
|
*
|
|
*
|
|
|
* @param id 用户id
|
|
* @param id 用户id
|
|
|
* @param password 密码
|
|
* @param password 密码
|
|
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public void resetPassword(Long id, String password, HttpServletResponse response) throws IOException {
|
|
public void resetPassword(Long id, String password, HttpServletResponse response) throws IOException {
|