Commit ed19bdb62b06b8040b650f74387849c1ec4359b7
1 parent
2be0f169
修改密码逻辑
Showing
4 changed files
with
56 additions
and
50 deletions
WebRoot/WEB-INF/jsp/sunvote/teacher/teacher_edit3.jsp
... | ... | @@ -157,14 +157,16 @@ |
157 | 157 | type:"POST", |
158 | 158 | success:function(res){ |
159 | 159 | console.log(res); |
160 | - | |
161 | - $("#save_btn").tips({ | |
162 | - side:3, | |
163 | - msg:res.data, | |
164 | - bg:'#AE81FF', | |
165 | - time:2 | |
166 | - }); | |
167 | - window.top.modal.remove(); | |
160 | + if(res.code == 0){ | |
161 | + window.top.modal.remove(); | |
162 | + }else{ | |
163 | + $("#PASSWORD_OLD").tips({ | |
164 | + side:3, | |
165 | + msg:res.message, | |
166 | + bg:'#AE81FF', | |
167 | + time:2 | |
168 | + }); | |
169 | + } | |
168 | 170 | } |
169 | 171 | }) |
170 | 172 | //$("#Form").submit(); | ... | ... |
src/com/fh/controller/api/ResponseGson.java
src/com/fh/controller/sunvote/teacher/TeacherController.java
... | ... | @@ -172,6 +172,18 @@ public class TeacherController extends BaseController { |
172 | 172 | PageData pd = new PageData(); |
173 | 173 | pd = this.getPageData(); |
174 | 174 | teacherService.edit(pd); |
175 | + pd.put("USER_ID", pd.getString("ID")); // ID 主键 | |
176 | + pd.put("LAST_LOGIN", ""); // 最后登录时间 | |
177 | + pd.put("IP", ""); // IP | |
178 | + pd.put("STATUS", "0"); // 状态 | |
179 | + pd.put("SKIN", "default"); | |
180 | + pd.put("RIGHTS", ""); | |
181 | + pd.put("USERNAME", pd.getString("ACCOUT")); | |
182 | + pd.put("ROLE_ID", "57bb1e6f138247a0b05cc721a5da1b64"); | |
183 | + pd.put("PASSWORD", | |
184 | + new SimpleHash("SHA-1", pd.getString("ACCOUT"), pd | |
185 | + .getString("PASSWORD")).toString()); // 密码加密 | |
186 | + userService.editU(pd); // 执行保存 | |
175 | 187 | mv.addObject("msg", "success"); |
176 | 188 | mv.setViewName("save_result"); |
177 | 189 | return mv; |
... | ... | @@ -197,17 +209,12 @@ public class TeacherController extends BaseController { |
197 | 209 | pd.put("STATUS", "0"); // 状态 |
198 | 210 | pd.put("SKIN", "default"); |
199 | 211 | pd.put("RIGHTS", ""); |
200 | - pd.put("USERNAME", pd.getString("ACCOUT")); | |
212 | + pd.put("USERNAME", n.getString("ACCOUT")); | |
201 | 213 | pd.put("ROLE_ID", "57bb1e6f138247a0b05cc721a5da1b64"); |
202 | 214 | pd.put("PASSWORD", |
203 | - new SimpleHash("SHA-1", pd.getString("ACCOUT"), pd | |
215 | + new SimpleHash("SHA-1", n.getString("ACCOUT"), pd | |
204 | 216 | .getString("PASSWORD")).toString()); // 密码加密 |
205 | - | |
206 | - if (null == userService.findByUsername(pd)) { // 判断用户名是否存在 | |
207 | - userService.saveU(pd); // 执行保存 | |
208 | - FHLOG.save(Jurisdiction.getUsername(), | |
209 | - "新增系统用户:" + pd.getString("USERNAME")); | |
210 | - } | |
217 | + userService.editU(pd); // 执行保存 | |
211 | 218 | mv.addObject("msg", "success"); |
212 | 219 | mv.setViewName("save_result2"); |
213 | 220 | return mv; |
... | ... | @@ -235,19 +242,15 @@ public class TeacherController extends BaseController { |
235 | 242 | pd.put("STATUS", "0"); // 状态 |
236 | 243 | pd.put("SKIN", "default"); |
237 | 244 | pd.put("RIGHTS", ""); |
238 | - pd.put("USERNAME", pd.getString("ACCOUT")); | |
245 | + pd.put("USERNAME", n.getString("ACCOUT")); | |
239 | 246 | pd.put("ROLE_ID", "57bb1e6f138247a0b05cc721a5da1b64"); |
240 | 247 | pd.put("PASSWORD", |
241 | - new SimpleHash("SHA-1", pd.getString("ACCOUT"), pd | |
248 | + new SimpleHash("SHA-1", n.getString("ACCOUT"), pd | |
242 | 249 | .getString("PASSWORD")).toString()); // 密码加密 |
243 | - | |
244 | - if (null == userService.findByUsername(pd)) { // 判断用户名是否存在 | |
245 | - userService.saveU(pd); // 执行保存 | |
246 | - FHLOG.save(Jurisdiction.getUsername(), | |
247 | - "新增系统用户:" + pd.getString("USERNAME")); | |
248 | - } | |
250 | + userService.editU(pd); // 执行保存 | |
249 | 251 | ret.setData("Success"); |
250 | 252 | }else{ |
253 | + ret.set5Error(); | |
251 | 254 | ret.setData("Fail"); |
252 | 255 | } |
253 | 256 | return ret.toJson(); | ... | ... |
src/com/fh/plugin/websocketInstantMsg/ChatServer.java
... | ... | @@ -3,7 +3,9 @@ package com.fh.plugin.websocketInstantMsg; |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.net.InetSocketAddress; |
5 | 5 | import java.net.UnknownHostException; |
6 | +import java.util.ArrayList; | |
6 | 7 | import java.util.Date; |
8 | +import java.util.List; | |
7 | 9 | |
8 | 10 | import net.sf.json.JSONObject; |
9 | 11 | |
... | ... | @@ -15,6 +17,8 @@ import org.java_websocket.server.WebSocketServer; |
15 | 17 | |
16 | 18 | |
17 | 19 | public class ChatServer extends WebSocketServer{ |
20 | + | |
21 | + private List<WebSocket> list = new ArrayList<WebSocket>(); | |
18 | 22 | |
19 | 23 | public ChatServer(int port) throws UnknownHostException { |
20 | 24 | super(new InetSocketAddress(port)); |
... | ... | @@ -31,6 +35,7 @@ public class ChatServer extends WebSocketServer{ |
31 | 35 | public void onOpen( WebSocket conn, ClientHandshake handshake ) { |
32 | 36 | //this.sendToAll( "new connection: " + handshake.getResourceDescriptor() ); |
33 | 37 | //System.out.println("===" + conn.getRemoteSocketAddress().getAddress().getHostAddress()); |
38 | + list.add(conn); | |
34 | 39 | } |
35 | 40 | |
36 | 41 | /** |
... | ... | @@ -38,7 +43,7 @@ public class ChatServer extends WebSocketServer{ |
38 | 43 | */ |
39 | 44 | @Override |
40 | 45 | public void onClose( WebSocket conn, int code, String reason, boolean remote ) { |
41 | - userLeave(conn); | |
46 | + list.remove(conn); | |
42 | 47 | } |
43 | 48 | |
44 | 49 | /** |
... | ... | @@ -46,18 +51,10 @@ public class ChatServer extends WebSocketServer{ |
46 | 51 | */ |
47 | 52 | @Override |
48 | 53 | public void onMessage(WebSocket conn, String message){ |
49 | - message = message.toString(); | |
50 | - if(null != message && message.startsWith("FHadminqq313596790")){ | |
51 | - this.userjoin(message.replaceFirst("FHadminqq313596790", ""),conn); | |
52 | - }if(null != message && message.startsWith("LeaveFHadminqq313596790")){ | |
53 | - this.userLeave(conn); | |
54 | - }if(null != message && message.contains("fhadmin886")){ | |
55 | - String toUser = message.substring(message.indexOf("fhadmin886")+10, message.indexOf("fhfhadmin888")); | |
56 | - message = message.substring(0, message.indexOf("fhadmin886")) +"[私信] "+ message.substring(message.indexOf("fhfhadmin888")+12, message.length()); | |
57 | - ChatServerPool.sendMessageToUser(ChatServerPool.getWebSocketByUser(toUser),message);//向所某用户发送消息 | |
58 | - ChatServerPool.sendMessageToUser(conn, message);//同时向本人发送消息 | |
59 | - }else{ | |
60 | - ChatServerPool.sendMessage(message.toString());//向所有在线用户发送消息 | |
54 | + for(WebSocket w:list){ | |
55 | + if(w != conn){ | |
56 | + w.send(message); | |
57 | + } | |
61 | 58 | } |
62 | 59 | } |
63 | 60 | |
... | ... | @@ -69,10 +66,10 @@ public class ChatServer extends WebSocketServer{ |
69 | 66 | */ |
70 | 67 | @Override |
71 | 68 | public void onError( WebSocket conn, Exception ex ) { |
72 | - ex.printStackTrace(); | |
73 | - if( conn != null ) { | |
74 | - //some errors like port binding failed may not be assignable to a specific websocket | |
75 | - } | |
69 | + try{ | |
70 | + conn.close(0); | |
71 | + }catch(Exception e){} | |
72 | + list.remove(conn); | |
76 | 73 | } |
77 | 74 | |
78 | 75 | |
... | ... | @@ -99,16 +96,16 @@ public class ChatServer extends WebSocketServer{ |
99 | 96 | * @param user |
100 | 97 | */ |
101 | 98 | public void userLeave(WebSocket conn){ |
102 | - String user = ChatServerPool.getUserByKey(conn); | |
99 | +// String user = ChatServerPool.getUserByKey(conn); | |
103 | 100 | boolean b = ChatServerPool.removeUser(conn); //在连接池中移除连接 |
104 | - if(b){ | |
105 | - JSONObject result = new JSONObject(); | |
106 | - result.element("type", "user_leave"); | |
107 | - result.element("user", "<a onclick=\"toUserMsg('"+user+"');\">"+user+"</a>"); | |
108 | - ChatServerPool.sendMessage(result.toString()); //把当前用户从所有在线用户列表中删除 | |
109 | - String joinMsg = "{\"from\":\"[系统]\",\"content\":\""+user+"下线了\",\"timestamp\":"+new Date().getTime()+",\"type\":\"message\"}"; | |
110 | - ChatServerPool.sendMessage(joinMsg); //向在线用户发送当前用户退出的消息 | |
111 | - } | |
101 | +// if(b){ | |
102 | +// JSONObject result = new JSONObject(); | |
103 | +// result.element("type", "user_leave"); | |
104 | +// result.element("user", "<a onclick=\"toUserMsg('"+user+"');\">"+user+"</a>"); | |
105 | +// ChatServerPool.sendMessage(result.toString()); //把当前用户从所有在线用户列表中删除 | |
106 | +// String joinMsg = "{\"from\":\"[系统]\",\"content\":\""+user+"下线了\",\"timestamp\":"+new Date().getTime()+",\"type\":\"message\"}"; | |
107 | +// ChatServerPool.sendMessage(joinMsg); //向在线用户发送当前用户退出的消息 | |
108 | +// } | |
112 | 109 | } |
113 | 110 | public static void main( String[] args ) throws InterruptedException , IOException { |
114 | 111 | WebSocketImpl.DEBUG = false; | ... | ... |