|
@@ -1,9 +1,16 @@
|
1
|
1
|
package com.community.huiju.controller;
|
2
|
2
|
|
|
3
|
+import com.community.commom.constant.Constant;
|
|
4
|
+import com.community.commom.session.UserElement;
|
|
5
|
+import com.community.huiju.exception.WisdomException;
|
3
|
6
|
import com.community.huiju.model.ToCommunities;
|
4
|
7
|
import com.community.huiju.service.CommunityServiceI;
|
|
8
|
+import com.community.huiju.vo.TaUserVO;
|
|
9
|
+import org.springframework.beans.BeanUtils;
|
5
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
11
|
|
|
12
|
+import javax.servlet.http.HttpSession;
|
|
13
|
+
|
7
|
14
|
/**
|
8
|
15
|
* 公共 controller
|
9
|
16
|
*/
|
|
@@ -24,4 +31,34 @@ public class BaseController {
|
24
|
31
|
return false;
|
25
|
32
|
}
|
26
|
33
|
|
|
34
|
+ /**
|
|
35
|
+ * 设置用户 session
|
|
36
|
+ * @param userVO
|
|
37
|
+ * @param session
|
|
38
|
+ */
|
|
39
|
+ protected void setUserSession(TaUserVO userVO, HttpSession session) {
|
|
40
|
+ if (null == userVO) {
|
|
41
|
+ throw new WisdomException("用户信息不能为空!");
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ UserElement userElement = new UserElement();
|
|
45
|
+ BeanUtils.copyProperties(userVO,userElement);
|
|
46
|
+ userElement.setLoginType(Constant.APP_LOGIN_TYPE);
|
|
47
|
+ session.setAttribute(Constant.APP_USER_SESSION,userElement);
|
|
48
|
+ userVO.setToken(session.getId());
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ /**
|
|
52
|
+ * 获取用户 session
|
|
53
|
+ * @param session
|
|
54
|
+ * @return
|
|
55
|
+ */
|
|
56
|
+ protected UserElement getUserElement(HttpSession session) {
|
|
57
|
+ UserElement userElement = (UserElement) session.getAttribute(Constant.APP_USER_SESSION);
|
|
58
|
+ if (null == userElement) {
|
|
59
|
+ throw new WisdomException("用户 session 不存在!");
|
|
60
|
+ }
|
|
61
|
+ return userElement;
|
|
62
|
+ }
|
|
63
|
+
|
27
|
64
|
}
|