Compare commits
4 Commits
599549f961
...
6f2ae1a92f
Author | SHA1 | Date |
---|---|---|
|
6f2ae1a92f | 10 months ago |
|
6999138b9d | 10 months ago |
|
48effa5c18 | 10 months ago |
|
05367b1c2a | 10 months ago |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,99 @@
|
|||||||
|
package com.wsk.controller;
|
||||||
|
|
||||||
|
import com.wsk.pojo.UserInformation;
|
||||||
|
import com.wsk.pojo.UserPassword;
|
||||||
|
import com.wsk.response.BaseResponse;
|
||||||
|
import com.wsk.service.UserInformationService;
|
||||||
|
import com.wsk.service.UserPasswordService;
|
||||||
|
import com.wsk.tool.StringUtils;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wsk1103 on 2017/5/9.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class ForgetController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserPasswordService userPasswordService;
|
||||||
|
@Resource
|
||||||
|
private UserInformationService userInformationService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "checkCode.do", method = {RequestMethod.POST, RequestMethod.GET})
|
||||||
|
public Map checkPhone(HttpServletRequest request, Model model,
|
||||||
|
@RequestParam String code, @RequestParam String token) {
|
||||||
|
Map<String, Integer> map = new HashMap<>();
|
||||||
|
String name = request.getParameter("name");
|
||||||
|
if (!StringUtils.getInstance().isNullOrEmpty(name)) {
|
||||||
|
request.getSession().setAttribute("name", name);
|
||||||
|
}
|
||||||
|
String checkCodeToken = (String) request.getSession().getAttribute("token");
|
||||||
|
if (StringUtils.getInstance().isNullOrEmpty(checkCodeToken) || !checkCodeToken.equals(token)) {
|
||||||
|
map.put("result", 0);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
//验证码错误
|
||||||
|
if (!checkCodePhone(code, request)) {
|
||||||
|
map.put("result", 0);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
map.put("result", 1);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新密码
|
||||||
|
@RequestMapping("updatePassword.do")
|
||||||
|
public BaseResponse updatePassword(HttpServletRequest request, Model model,
|
||||||
|
@RequestParam String password, @RequestParam String token) {
|
||||||
|
//防止重复提交
|
||||||
|
String updatePasswordToken = (String) request.getSession().getAttribute("token");
|
||||||
|
if (StringUtils.getInstance().isNullOrEmpty(updatePasswordToken) || !updatePasswordToken.equals(token)) {
|
||||||
|
return BaseResponse.fail();
|
||||||
|
}
|
||||||
|
String realPhone = (String) request.getSession().getAttribute("phone");
|
||||||
|
UserPassword userPassword = new UserPassword();
|
||||||
|
String newPassword = StringUtils.getInstance().getMD5(password);
|
||||||
|
int uid;
|
||||||
|
try {
|
||||||
|
uid = userInformationService.selectIdByPhone(realPhone);
|
||||||
|
if (uid == 0) {
|
||||||
|
return BaseResponse.fail();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return BaseResponse.fail();
|
||||||
|
}
|
||||||
|
int id = userPasswordService.selectByUid(uid).getId();
|
||||||
|
userPassword.setId(id);
|
||||||
|
userPassword.setUid(uid);
|
||||||
|
userPassword.setModified(new Date());
|
||||||
|
userPassword.setPassword(newPassword);
|
||||||
|
int result;
|
||||||
|
try {
|
||||||
|
result = userPasswordService.updateByPrimaryKeySelective(userPassword);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return BaseResponse.fail();
|
||||||
|
}
|
||||||
|
//更新失败
|
||||||
|
if (result != 1) {
|
||||||
|
return BaseResponse.fail();
|
||||||
|
}
|
||||||
|
UserInformation userInformation = userInformationService.selectByPrimaryKey(uid);
|
||||||
|
request.getSession().setAttribute("userInformation", userInformation);
|
||||||
|
return BaseResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
//check the phone`s code
|
||||||
|
private boolean checkCodePhone(String codePhone, HttpServletRequest request) {
|
||||||
|
String trueCodePhone = "12251103";
|
||||||
|
return codePhone.equals(trueCodePhone);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package com.wsk.controller.webSocket;
|
||||||
|
|
||||||
|
import com.wsk.tool.SaveSession;
|
||||||
|
import org.springframework.web.socket.CloseStatus;
|
||||||
|
import org.springframework.web.socket.TextMessage;
|
||||||
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wsk1103 on 2017/5/22.
|
||||||
|
*/
|
||||||
|
public class ChatWebSocketHandler extends TextWebSocketHandler {
|
||||||
|
|
||||||
|
private final static List<WebSocketSession> sessions = Collections.synchronizedList(new ArrayList<WebSocketSession>());
|
||||||
|
|
||||||
|
//接收文本消息,并发送出去
|
||||||
|
@Override
|
||||||
|
protected void handleTextMessage(WebSocketSession session, TextMessage message) {
|
||||||
|
// System.out.println(session.getId()+":send....");
|
||||||
|
// chatTextMessageHandler(message.getPayload());
|
||||||
|
try {
|
||||||
|
// super.handleTextMessage(session, message);
|
||||||
|
// System.out.println(session.getId()+" :"+message.getPayload() + " " + new Date());
|
||||||
|
String m = message.getPayload();
|
||||||
|
String[] wsk = m.split(",");
|
||||||
|
String phone = wsk[0];
|
||||||
|
long time = Long.parseLong(wsk[1]);
|
||||||
|
String action = wsk[2];
|
||||||
|
if (action.equals("start")){
|
||||||
|
session.sendMessage(new TextMessage("success"));
|
||||||
|
SaveSession.getInstance().save(phone,time);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean b = SaveSession.getInstance().isHave(phone,time);
|
||||||
|
if (b) {
|
||||||
|
if (session.isOpen()) {
|
||||||
|
session.sendMessage(new TextMessage("error"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (session.isOpen())
|
||||||
|
session.sendMessage(new TextMessage("success"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
try {
|
||||||
|
session.sendMessage(new TextMessage("error"));
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//连接建立后处理
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void afterConnectionEstablished(WebSocketSession session) {
|
||||||
|
sessions.add(session);
|
||||||
|
//处理离线消息
|
||||||
|
}
|
||||||
|
|
||||||
|
//抛出异常时处理
|
||||||
|
@Override
|
||||||
|
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||||
|
if (session.isOpen()) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
|
sessions.remove(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
//连接关闭后处理
|
||||||
|
@Override
|
||||||
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) {
|
||||||
|
sessions.remove(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue