Commit 75f68f7e1eca85b7db9619a72a8760093c0bc7e9
1 parent
d94a7ceae3
Exists in
master
and in
1 other branch
platform permission
login model move login center
Showing 16 changed files with 409 additions and 161 deletions
- platform-biz-service/src/main/java/com/lyms/platform/permission/dao/UsersMapper.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/model/Users.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/model/UsersQuery.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/service/UsersService.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/UsersServiceImpl.java
- platform-biz-service/src/main/resources/mainOrm/Users.xml
- platform-common/src/main/java/com/lyms/platform/common/base/LoginState.java
- platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java
- platform-common/src/main/java/com/lyms/platform/common/utils/MessageUtil.java
- platform-common/src/main/java/com/lyms/platform/common/utils/ResultUtils.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/DepartmentsController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/OrganizationController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/RolesController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/TokenValidateInteceptor.java
- platform-operate-api/src/main/resources/database.properties
platform-biz-service/src/main/java/com/lyms/platform/permission/dao/UsersMapper.java
View file @
75f68f7
| ... | ... | @@ -5,7 +5,19 @@ |
| 5 | 5 | |
| 6 | 6 | import java.util.List; |
| 7 | 7 | |
| 8 | -public interface UsersMapper {public void addUsers(Users obj);public void updateUsers(Users obj);public void deleteUsers(Integer id);public Users getUsers(Integer id);public int queryUsersCount(UsersQuery query);public List<Users> queryUsers(UsersQuery query); | |
| 8 | +public interface UsersMapper { | |
| 9 | + public void addUsers(Users obj); | |
| 9 | 10 | |
| 11 | + public void updateUsers(Users obj); | |
| 12 | + | |
| 13 | + public void deleteUsers(Integer id); | |
| 14 | + | |
| 15 | + public Users getUsers(Integer id); | |
| 16 | + | |
| 17 | + public int queryUsersCount(UsersQuery query); | |
| 18 | + | |
| 19 | + public List<Users> queryUsers(UsersQuery query); | |
| 20 | + | |
| 21 | + public Users getUsersByLoginCenterId(Integer id); | |
| 10 | 22 | } |
platform-biz-service/src/main/java/com/lyms/platform/permission/model/Users.java
View file @
75f68f7
| ... | ... | @@ -2,177 +2,188 @@ |
| 2 | 2 | |
| 3 | 3 | import java.util.Date; |
| 4 | 4 | |
| 5 | -public class Users { | |
| 6 | - private Integer id; | |
| 7 | - private Integer type; | |
| 8 | - private Integer orgId; | |
| 9 | - private Integer deptId; | |
| 10 | - private String name; | |
| 11 | - private String account; | |
| 12 | - private String pwd; | |
| 13 | - private String phone; | |
| 14 | - private Integer publishId; | |
| 15 | - private String publishName; | |
| 16 | - private Integer yn; | |
| 17 | - private Integer enable; | |
| 18 | - private Date modified; | |
| 19 | - private Date created; | |
| 20 | - private String remarks; | |
| 21 | - private Date lastLoginTime; | |
| 5 | +public class Users {private Integer id;private Integer logincenterId;private Integer type;private Integer orgId;private Integer deptId;private String name;private String account;private String pwd;private String phone;private Integer publishId;private String publishName;private Integer yn;private Integer enable;private Date modified;private Date created;private String remarks;private Date lastLoginTime; | |
| 22 | 6 | |
| 23 | - public Integer getId() { | |
| 7 | +public Integer getId() { | |
| 24 | 8 | return id; |
| 25 | 9 | } |
| 26 | 10 | |
| 27 | 11 | |
| 12 | + | |
| 28 | 13 | public void setId(Integer id) { |
| 29 | 14 | this.id = id; |
| 30 | 15 | |
| 31 | 16 | } |
| 32 | 17 | |
| 33 | - public Integer getType() { | |
| 18 | +public Integer getLogincenterId() { | |
| 19 | + return logincenterId; | |
| 20 | + } | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + public void setLogincenterId(Integer logincenterId) { | |
| 25 | + this.logincenterId = logincenterId; | |
| 26 | + | |
| 27 | + } | |
| 28 | + | |
| 29 | +public Integer getType() { | |
| 34 | 30 | return type; |
| 35 | 31 | } |
| 36 | 32 | |
| 37 | 33 | |
| 34 | + | |
| 38 | 35 | public void setType(Integer type) { |
| 39 | 36 | this.type = type; |
| 40 | 37 | |
| 41 | 38 | } |
| 42 | 39 | |
| 43 | - public Integer getOrgId() { | |
| 40 | +public Integer getOrgId() { | |
| 44 | 41 | return orgId; |
| 45 | 42 | } |
| 46 | 43 | |
| 47 | 44 | |
| 45 | + | |
| 48 | 46 | public void setOrgId(Integer orgId) { |
| 49 | 47 | this.orgId = orgId; |
| 50 | 48 | |
| 51 | 49 | } |
| 52 | 50 | |
| 53 | - public Integer getDeptId() { | |
| 51 | +public Integer getDeptId() { | |
| 54 | 52 | return deptId; |
| 55 | 53 | } |
| 56 | 54 | |
| 57 | 55 | |
| 56 | + | |
| 58 | 57 | public void setDeptId(Integer deptId) { |
| 59 | 58 | this.deptId = deptId; |
| 60 | 59 | |
| 61 | 60 | } |
| 62 | 61 | |
| 63 | - public String getName() { | |
| 62 | +public String getName() { | |
| 64 | 63 | return name; |
| 65 | 64 | } |
| 66 | 65 | |
| 67 | 66 | |
| 67 | + | |
| 68 | 68 | public void setName(String name) { |
| 69 | 69 | this.name = name; |
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public String getAccount() { | |
| 73 | +public String getAccount() { | |
| 74 | 74 | return account; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | + | |
| 78 | 79 | public void setAccount(String account) { |
| 79 | 80 | this.account = account; |
| 80 | 81 | |
| 81 | 82 | } |
| 82 | 83 | |
| 83 | - public String getPwd() { | |
| 84 | +public String getPwd() { | |
| 84 | 85 | return pwd; |
| 85 | 86 | } |
| 86 | 87 | |
| 87 | 88 | |
| 89 | + | |
| 88 | 90 | public void setPwd(String pwd) { |
| 89 | 91 | this.pwd = pwd; |
| 90 | 92 | |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | - public String getPhone() { | |
| 95 | +public String getPhone() { | |
| 94 | 96 | return phone; |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | |
| 100 | + | |
| 98 | 101 | public void setPhone(String phone) { |
| 99 | 102 | this.phone = phone; |
| 100 | 103 | |
| 101 | 104 | } |
| 102 | 105 | |
| 103 | - public Integer getPublishId() { | |
| 106 | +public Integer getPublishId() { | |
| 104 | 107 | return publishId; |
| 105 | 108 | } |
| 106 | 109 | |
| 107 | 110 | |
| 111 | + | |
| 108 | 112 | public void setPublishId(Integer publishId) { |
| 109 | 113 | this.publishId = publishId; |
| 110 | 114 | |
| 111 | 115 | } |
| 112 | 116 | |
| 113 | - public String getPublishName() { | |
| 117 | +public String getPublishName() { | |
| 114 | 118 | return publishName; |
| 115 | 119 | } |
| 116 | 120 | |
| 117 | 121 | |
| 122 | + | |
| 118 | 123 | public void setPublishName(String publishName) { |
| 119 | 124 | this.publishName = publishName; |
| 120 | 125 | |
| 121 | 126 | } |
| 122 | 127 | |
| 123 | - public Integer getYn() { | |
| 128 | +public Integer getYn() { | |
| 124 | 129 | return yn; |
| 125 | 130 | } |
| 126 | 131 | |
| 127 | 132 | |
| 133 | + | |
| 128 | 134 | public void setYn(Integer yn) { |
| 129 | 135 | this.yn = yn; |
| 130 | 136 | |
| 131 | 137 | } |
| 132 | 138 | |
| 133 | - public Integer getEnable() { | |
| 139 | +public Integer getEnable() { | |
| 134 | 140 | return enable; |
| 135 | 141 | } |
| 136 | 142 | |
| 137 | 143 | |
| 144 | + | |
| 138 | 145 | public void setEnable(Integer enable) { |
| 139 | 146 | this.enable = enable; |
| 140 | 147 | |
| 141 | 148 | } |
| 142 | 149 | |
| 143 | - public Date getModified() { | |
| 150 | +public Date getModified() { | |
| 144 | 151 | return modified; |
| 145 | 152 | } |
| 146 | 153 | |
| 147 | 154 | |
| 155 | + | |
| 148 | 156 | public void setModified(Date modified) { |
| 149 | 157 | this.modified = modified; |
| 150 | 158 | |
| 151 | 159 | } |
| 152 | 160 | |
| 153 | - public Date getCreated() { | |
| 161 | +public Date getCreated() { | |
| 154 | 162 | return created; |
| 155 | 163 | } |
| 156 | 164 | |
| 157 | 165 | |
| 166 | + | |
| 158 | 167 | public void setCreated(Date created) { |
| 159 | 168 | this.created = created; |
| 160 | 169 | |
| 161 | 170 | } |
| 162 | 171 | |
| 163 | - public String getRemarks() { | |
| 172 | +public String getRemarks() { | |
| 164 | 173 | return remarks; |
| 165 | 174 | } |
| 166 | 175 | |
| 167 | 176 | |
| 177 | + | |
| 168 | 178 | public void setRemarks(String remarks) { |
| 169 | 179 | this.remarks = remarks; |
| 170 | 180 | |
| 171 | 181 | } |
| 172 | 182 | |
| 173 | - public Date getLastLoginTime() { | |
| 183 | +public Date getLastLoginTime() { | |
| 174 | 184 | return lastLoginTime; |
| 175 | 185 | } |
| 186 | + | |
| 176 | 187 | |
| 177 | 188 | |
| 178 | 189 | public void setLastLoginTime(Date lastLoginTime) { |
platform-biz-service/src/main/java/com/lyms/platform/permission/model/UsersQuery.java
View file @
75f68f7
| ... | ... | @@ -8,7 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | |
| 11 | -public class UsersQuery extends BaseQuery {private Integer id;private Integer type;private Integer orgId;private Integer deptId;private String name;private String account;private String pwd;private String phone;private Integer publishId;private String publishName;private Integer yn;private Integer enable;private Date modified;private Date created;private String remarks;private Date lastLoginTime; | |
| 11 | +public class UsersQuery extends BaseQuery {private Integer id;private Integer logincenterId;private Integer type;private Integer orgId;private Integer deptId;private String name;private String account;private String pwd;private String phone;private Integer publishId;private String publishName;private Integer yn;private Integer enable;private Date modified;private Date created;private String remarks;private Date lastLoginTime; | |
| 12 | 12 | |
| 13 | 13 | public Integer getId() { |
| 14 | 14 | return id; |
| ... | ... | @@ -18,6 +18,17 @@ |
| 18 | 18 | |
| 19 | 19 | public void setId(Integer id) { |
| 20 | 20 | this.id = id; |
| 21 | + | |
| 22 | + } | |
| 23 | + | |
| 24 | +public Integer getLogincenterId() { | |
| 25 | + return logincenterId; | |
| 26 | + } | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + public void setLogincenterId(Integer logincenterId) { | |
| 31 | + this.logincenterId = logincenterId; | |
| 21 | 32 | |
| 22 | 33 | } |
| 23 | 34 |
platform-biz-service/src/main/java/com/lyms/platform/permission/service/UsersService.java
View file @
75f68f7
| ... | ... | @@ -5,7 +5,20 @@ |
| 5 | 5 | |
| 6 | 6 | import java.util.List; |
| 7 | 7 | |
| 8 | -public interface UsersService {public void addUsers(Users obj);public void updateUsers(Users obj);public void deleteUsers(Integer id);public Users getUsers(Integer id);public int queryUsersCount(UsersQuery query);public List<Users> queryUsers(UsersQuery query); | |
| 8 | +public interface UsersService { | |
| 9 | + public void addUsers(Users obj); | |
| 10 | + | |
| 11 | + public void updateUsers(Users obj); | |
| 12 | + | |
| 13 | + public void deleteUsers(Integer id); | |
| 14 | + | |
| 15 | + public Users getUsers(Integer id); | |
| 16 | + | |
| 17 | + public int queryUsersCount(UsersQuery query); | |
| 18 | + | |
| 19 | + public List<Users> queryUsers(UsersQuery query); | |
| 20 | + | |
| 21 | + public Users getUsersByLoginCenterId(Integer id); | |
| 9 | 22 | |
| 10 | 23 | } |
platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/UsersServiceImpl.java
View file @
75f68f7
| ... | ... | @@ -29,5 +29,11 @@ |
| 29 | 29 | @Override |
| 30 | 30 | public List<Users> queryUsers (UsersQuery query){if (query.getNeed() != null) {query.mysqlBuild(usersMapper.queryUsersCount(query));}return usersMapper.queryUsers(query);} |
| 31 | 31 | |
| 32 | + @Override | |
| 33 | + public Users getUsersByLoginCenterId(Integer id) { | |
| 34 | + return usersMapper.getUsersByLoginCenterId(id); | |
| 35 | + } | |
| 36 | + | |
| 37 | + | |
| 32 | 38 | } |
platform-biz-service/src/main/resources/mainOrm/Users.xml
View file @
75f68f7
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | |
| 5 | 5 | <resultMap id="UsersResultMap" type="com.lyms.platform.permission.model.Users"> |
| 6 | 6 | <id column="id" property="id" jdbcType="INTEGER" /> |
| 7 | +<result column="logincenter_id" property="logincenterId" jdbcType="INTEGER" /> | |
| 7 | 8 | <result column="type" property="type" jdbcType="INTEGER" /> |
| 8 | 9 | <result column="org_id" property="orgId" jdbcType="INTEGER" /> |
| 9 | 10 | <result column="dept_id" property="deptId" jdbcType="INTEGER" /> |
| 10 | 11 | |
| ... | ... | @@ -24,13 +25,16 @@ |
| 24 | 25 | |
| 25 | 26 | |
| 26 | 27 | <insert id="addUsers" parameterType="com.lyms.platform.permission.model.Users"> |
| 27 | -insert into users (type,org_id,dept_id,name,account,pwd,phone,publish_id,publish_name,yn,enable,modified,created,remarks,last_login_time) values (#{type},#{orgId},#{deptId},#{name},#{account},#{pwd},#{phone},#{publishId},#{publishName},#{yn},#{enable},#{modified},#{created},#{remarks},#{lastLoginTime}) | |
| 28 | +insert into users (logincenter_id,type,org_id,dept_id,name,account,pwd,phone,publish_id,publish_name,yn,enable,modified,created,remarks,last_login_time) values (#{logincenterId},#{type},#{orgId},#{deptId},#{name},#{account},#{pwd},#{phone},#{publishId},#{publishName},#{yn},#{enable},#{modified},#{created},#{remarks},#{lastLoginTime}) | |
| 28 | 29 | </insert> |
| 29 | 30 | |
| 30 | 31 | |
| 31 | 32 | |
| 32 | 33 | <update id="updateUsers" parameterType="com.lyms.platform.permission.model.Users"> |
| 33 | -update users <set><if test="type != null and type >= 0"> | |
| 34 | +update users <set><if test="logincenterId != null and logincenterId >= 0"> | |
| 35 | +logincenter_id = #{logincenterId,jdbcType=INTEGER}, | |
| 36 | +</if> | |
| 37 | +<if test="type != null and type >= 0"> | |
| 34 | 38 | type = #{type,jdbcType=INTEGER}, |
| 35 | 39 | </if> |
| 36 | 40 | <if test="orgId != null and orgId >= 0"> |
| 37 | 41 | |
| 38 | 42 | |
| ... | ... | @@ -87,11 +91,16 @@ |
| 87 | 91 | |
| 88 | 92 | |
| 89 | 93 | <select id="getUsers" resultMap="UsersResultMap" parameterType="java.lang.Integer"> |
| 90 | -select id,type,org_id,dept_id,name,account,pwd,phone,publish_id,publish_name,yn,enable,modified,created,remarks,last_login_time | |
| 94 | +select id,logincenter_id,type,org_id,dept_id,name,account,pwd,phone,publish_id,publish_name,yn,enable,modified,created,remarks,last_login_time | |
| 91 | 95 | from users where id = #{id,jdbcType=INTEGER} |
| 92 | 96 | </select> |
| 93 | 97 | |
| 98 | + <select id="getUsersByLoginCenterId" resultMap="UsersResultMap" parameterType="java.lang.Integer"> | |
| 99 | + select id,logincenter_id,type,org_id,dept_id,name,account,pwd,phone,publish_id,publish_name,yn,enable,modified,created,remarks,last_login_time | |
| 100 | + from users where logincenter_id = #{id,jdbcType=INTEGER} | |
| 101 | + </select> | |
| 94 | 102 | |
| 103 | + | |
| 95 | 104 | <sql id="orderAndLimit"> |
| 96 | 105 | <if test="sort != null and sort != '' "> |
| 97 | 106 | order by ${sort} |
| ... | ... | @@ -109,6 +118,9 @@ |
| 109 | 118 | <if test="id != null and id >= 0"> |
| 110 | 119 | and id = #{id,jdbcType=INTEGER} |
| 111 | 120 | </if> |
| 121 | +<if test="logincenterId != null and logincenterId >= 0"> | |
| 122 | +and logincenter_id = #{logincenterId,jdbcType=INTEGER} | |
| 123 | +</if> | |
| 112 | 124 | <if test="type != null and type >= 0"> |
| 113 | 125 | and type = #{type,jdbcType=INTEGER} |
| 114 | 126 | </if> |
| ... | ... | @@ -160,7 +172,7 @@ |
| 160 | 172 | |
| 161 | 173 | |
| 162 | 174 | <select id="queryUsers" resultMap="UsersResultMap" parameterType="com.lyms.platform.permission.model.UsersQuery"> |
| 163 | -select id,type,org_id,dept_id,name,account,pwd,phone,publish_id,publish_name,yn,enable,modified,created,remarks,last_login_time | |
| 175 | +select id,logincenter_id,type,org_id,dept_id,name,account,pwd,phone,publish_id,publish_name,yn,enable,modified,created,remarks,last_login_time | |
| 164 | 176 | from users |
| 165 | 177 | <include refid="UsersCondition" /> |
| 166 | 178 | <include refid="orderAndLimit" /> |
platform-common/src/main/java/com/lyms/platform/common/base/LoginState.java
View file @
75f68f7
| 1 | +package com.lyms.platform.common.base; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by Zhang.Rui on 2016/3/28. | |
| 5 | + */ | |
| 6 | +public class LoginState { | |
| 7 | + private String token; | |
| 8 | + private Integer id; | |
| 9 | + private Integer errorcode; | |
| 10 | + private String errormsg; | |
| 11 | + | |
| 12 | + public String getToken() { | |
| 13 | + return token; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public void setToken(String token) { | |
| 17 | + this.token = token; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public Integer getErrorcode() { | |
| 21 | + return errorcode; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public void setErrorcode(Integer errorcode) { | |
| 25 | + this.errorcode = errorcode; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public String getErrormsg() { | |
| 29 | + return errormsg; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public void setErrormsg(String errormsg) { | |
| 33 | + this.errormsg = errormsg; | |
| 34 | + } | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + public Integer getId() { | |
| 39 | + return id; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void setId(Integer id) { | |
| 43 | + this.id = id; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public boolean isLogin() { | |
| 47 | + return 0 == this.errorcode ? true : false; | |
| 48 | + } | |
| 49 | +} |
platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java
View file @
75f68f7
| 1 | 1 | package com.lyms.platform.common.utils; |
| 2 | 2 | |
| 3 | +import com.lyms.platform.common.base.LoginState; | |
| 4 | +import jdk.nashorn.internal.runtime.regexp.joni.Regex; | |
| 5 | +import org.apache.commons.digester.RegexMatcher; | |
| 6 | +import org.apache.commons.httpclient.HttpClient; | |
| 7 | +import org.apache.commons.httpclient.NameValuePair; | |
| 8 | +import org.apache.commons.httpclient.methods.GetMethod; | |
| 9 | +import org.apache.commons.httpclient.methods.PostMethod; | |
| 10 | +import org.apache.commons.httpclient.params.HttpMethodParams; | |
| 11 | +import org.springframework.beans.factory.annotation.Value; | |
| 12 | + | |
| 3 | 13 | import java.security.MessageDigest; |
| 4 | 14 | import java.security.NoSuchAlgorithmException; |
| 15 | +import java.util.ArrayList; | |
| 16 | +import java.util.HashMap; | |
| 17 | +import java.util.List; | |
| 18 | +import java.util.Map; | |
| 19 | +import java.util.regex.Matcher; | |
| 20 | +import java.util.regex.Pattern; | |
| 5 | 21 | |
| 6 | 22 | public class LoginUtil { |
| 7 | 23 | |
| 24 | + public static Integer register(String phone, String token, String typeId) { | |
| 25 | + HttpClient client = new HttpClient(); | |
| 26 | + PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/register.action"); | |
| 27 | + NameValuePair[] data = { | |
| 28 | + new NameValuePair("phone", phone), | |
| 29 | + new NameValuePair("typeId", typeId), | |
| 30 | + }; | |
| 31 | + post.setRequestBody(data); | |
| 32 | + post.setRequestHeader("Authorization", token); | |
| 33 | + try { | |
| 34 | + client.executeMethod(post); | |
| 35 | + int statusCode = post.getStatusCode(); | |
| 36 | + String result = new String(post.getResponseBodyAsString()); | |
| 37 | + post.releaseConnection(); | |
| 38 | + if(200 == statusCode) { | |
| 39 | + LoginState loginState = JsonUtil.str2Obj(result, LoginState.class); | |
| 40 | + return loginState.getId(); | |
| 41 | + } | |
| 42 | + } catch (Exception e) { | |
| 43 | + e.printStackTrace(); | |
| 44 | + } | |
| 45 | + return null; | |
| 46 | + } | |
| 47 | + | |
| 48 | + | |
| 49 | + public static String login(String phone, String varCode, String typeId, String token) { | |
| 50 | + HttpClient client = new HttpClient(); | |
| 51 | + PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/login.action"); | |
| 52 | + NameValuePair[] data = { | |
| 53 | + new NameValuePair("phone", phone), | |
| 54 | + new NameValuePair("typeId", typeId), | |
| 55 | + new NameValuePair("code", varCode) | |
| 56 | + }; | |
| 57 | + post.setRequestBody(data); | |
| 58 | + post.setRequestHeader("Authorization", token); | |
| 59 | + try { | |
| 60 | + client.executeMethod(post); | |
| 61 | + int statusCode = post.getStatusCode(); | |
| 62 | + String result = new String(post.getResponseBodyAsString()); | |
| 63 | + | |
| 64 | + post.releaseConnection(); | |
| 65 | + if(200 == statusCode) { | |
| 66 | + LoginState loginState = JsonUtil.str2Obj(result, LoginState.class); | |
| 67 | + if(0 == loginState.getErrorcode()) { | |
| 68 | + return loginState.getToken(); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + } catch (Exception e) { | |
| 72 | + e.printStackTrace(); | |
| 73 | + } | |
| 74 | + return null; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public static boolean sendVerCode(String phone, String typeId, String token) { | |
| 78 | + HttpClient client = new HttpClient(); | |
| 79 | + String query = "?phone=" + phone + "&typeId=" + typeId + "&token=" + token + "&userType=2"; | |
| 80 | + GetMethod get = new MessageUtil.UTF8GetMethod("http://passport.healthbaby.com.cn/v1/vercode.action" + query); | |
| 81 | + | |
| 82 | + get.setRequestHeader("Authorization", token); | |
| 83 | + try { | |
| 84 | + client.executeMethod(get); | |
| 85 | + int statusCode = get.getStatusCode(); | |
| 86 | + String result = new String(get.getResponseBodyAsString()); | |
| 87 | + get.releaseConnection(); | |
| 88 | + if(200 == statusCode) { | |
| 89 | + LoginState loginState = JsonUtil.str2Obj(result, LoginState.class); | |
| 90 | + if(0 == loginState.getErrorcode()) { | |
| 91 | + return true; | |
| 92 | + } | |
| 93 | + } | |
| 94 | + } catch (Exception e) { | |
| 95 | + e.printStackTrace(); | |
| 96 | + } | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + | |
| 100 | + | |
| 101 | + public static LoginState checkLoginState(String token) { | |
| 102 | + LoginState loginState = new LoginState(); | |
| 103 | + HttpClient client = new HttpClient(); | |
| 104 | + String query = "?token=" + token ; | |
| 105 | + GetMethod get = new MessageUtil.UTF8GetMethod("http://passport.healthbaby.com.cn/v1/check.action" + query); | |
| 106 | + get.setRequestHeader("Authorization", token); | |
| 107 | + try { | |
| 108 | + client.executeMethod(get); | |
| 109 | + int statusCode = get.getStatusCode(); | |
| 110 | + String result = new String(get.getResponseBodyAsString()); | |
| 111 | + get.releaseConnection(); | |
| 112 | + if(200 == statusCode) { | |
| 113 | + loginState = JsonUtil.str2Obj(result, LoginState.class); | |
| 114 | + return loginState; | |
| 115 | + } | |
| 116 | + } catch (Exception e) { | |
| 117 | + e.printStackTrace(); | |
| 118 | + } | |
| 119 | + return loginState; | |
| 120 | + } | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 8 | 125 | public static String md5(String plainText) { |
| 9 | 126 | try { |
| 10 | 127 | if(plainText==null){ |
| ... | ... | @@ -29,11 +146,22 @@ |
| 29 | 146 | return null; |
| 30 | 147 | } |
| 31 | 148 | } |
| 32 | - | |
| 33 | - public static void main(String[] args) { | |
| 34 | - System.out.println(md5("123789456")); | |
| 35 | - //3949ba59abbe56e057f20f88 | |
| 36 | - } | |
| 149 | +// | |
| 150 | +// public static void main(String[] args) { | |
| 151 | +// System.out.println(md5("123789456")); | |
| 152 | +// String a = "{\"id\":20,\"token\":\"ucefac93386a4c70a8a570da5bbfc24ad0\",\"errormsg\":\"成功\",\"errorcode\":3}"; | |
| 153 | +// | |
| 154 | +// | |
| 155 | +// System.out.println(a.matches(".*errorcode\":0.*")); | |
| 156 | +// | |
| 157 | +// Pattern pattern = Pattern.compile("token\":\"(.*?)\""); | |
| 158 | +// Matcher matcher = pattern.matcher(a); | |
| 159 | +// while(matcher.find()) { | |
| 160 | +// System.out.println(matcher.group(1)); | |
| 161 | +// } | |
| 162 | +// | |
| 163 | +// //3949ba59abbe56e057f20f88 | |
| 164 | +// } | |
| 37 | 165 | |
| 38 | 166 | } |
platform-common/src/main/java/com/lyms/platform/common/utils/MessageUtil.java
View file @
75f68f7
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | import com.lyms.platform.common.cache.redis.RedisUtils; |
| 5 | 5 | import org.apache.commons.httpclient.HttpClient; |
| 6 | 6 | import org.apache.commons.httpclient.NameValuePair; |
| 7 | +import org.apache.commons.httpclient.methods.GetMethod; | |
| 7 | 8 | import org.apache.commons.httpclient.methods.PostMethod; |
| 8 | 9 | import org.apache.commons.httpclient.methods.PutMethod; |
| 9 | 10 | |
| ... | ... | @@ -101,6 +102,18 @@ |
| 101 | 102 | |
| 102 | 103 | public static class UTF8PutMethod extends PutMethod { |
| 103 | 104 | public UTF8PutMethod(String url){ |
| 105 | + super(url); | |
| 106 | + } | |
| 107 | + @Override | |
| 108 | + public String getRequestCharSet() { | |
| 109 | + //return super.getRequestCharSet(); | |
| 110 | + return "UTF-8"; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + | |
| 114 | + | |
| 115 | + public static class UTF8GetMethod extends GetMethod { | |
| 116 | + public UTF8GetMethod(String url){ | |
| 104 | 117 | super(url); |
| 105 | 118 | } |
| 106 | 119 | @Override |
platform-common/src/main/java/com/lyms/platform/common/utils/ResultUtils.java
View file @
75f68f7
| ... | ... | @@ -19,6 +19,18 @@ |
| 19 | 19 | /** |
| 20 | 20 | * 返回成功数据 |
| 21 | 21 | */ |
| 22 | + public static void buildSuccessResultAndWrite(HttpServletResponse httpServletResponse,Map data){ | |
| 23 | + Map<String,Object> result= new HashMap<String, Object>(); | |
| 24 | + result.put(ERROR_CODE, ErrorCodeConstants.SUCCESS); | |
| 25 | + result.put(ERROR_MSG,"成功"); | |
| 26 | + result.putAll(data); | |
| 27 | + writeJson(httpServletResponse, JsonUtil.obj2JsonString(result)); | |
| 28 | + } | |
| 29 | + | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 返回成功数据 | |
| 33 | + */ | |
| 22 | 34 | public static void buildSuccessResultAndWrite(HttpServletResponse httpServletResponse, Object data){ |
| 23 | 35 | Map<String,Object> result= new HashMap<String, Object>(); |
| 24 | 36 | result.put(ERROR_CODE, ErrorCodeConstants.SUCCESS); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/DepartmentsController.java
View file @
75f68f7
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | import com.lyms.platform.common.annotation.TokenRequired; |
| 5 | 5 | import com.lyms.platform.common.base.BaseController; |
| 6 | 6 | import com.lyms.platform.common.base.ContextHolder; |
| 7 | +import com.lyms.platform.common.base.LoginState; | |
| 7 | 8 | import com.lyms.platform.common.base.PlatformContext; |
| 8 | 9 | import com.lyms.platform.common.constants.ErrorCodeConstants; |
| 9 | 10 | import com.lyms.platform.common.enums.YnEnums; |
| ... | ... | @@ -15,6 +16,7 @@ |
| 15 | 16 | import org.springframework.stereotype.Controller; |
| 16 | 17 | import org.springframework.web.bind.annotation.*; |
| 17 | 18 | |
| 19 | +import javax.servlet.http.HttpServletRequest; | |
| 18 | 20 | import javax.servlet.http.HttpServletResponse; |
| 19 | 21 | import java.util.Date; |
| 20 | 22 | import java.util.List; |
| 21 | 23 | |
| 22 | 24 | |
| ... | ... | @@ -112,16 +114,18 @@ |
| 112 | 114 | @RequestMapping(value = "/departments", method = RequestMethod.POST) |
| 113 | 115 | @TokenRequired |
| 114 | 116 | public void addDepartments(HttpServletResponse response, |
| 117 | + HttpServletRequest request, | |
| 115 | 118 | @RequestParam(value = "pid") Integer pid, |
| 116 | 119 | @RequestParam(value = "name") String name, |
| 117 | 120 | @RequestParam(value = "orgId") Integer orgId, |
| 118 | 121 | @RequestParam(value = "description") String description, |
| 119 | 122 | @RequestParam(value = "shortCode") String shortCode) { |
| 120 | 123 | |
| 124 | + | |
| 125 | + | |
| 121 | 126 | //获取登录用户 |
| 122 | - PlatformContext mommyBobyContext = ContextHolder.getContext(); | |
| 123 | - String token = mommyBobyContext.getToken(); | |
| 124 | - Users users = usersService.getUsers(tokenService.getUserId(token)); | |
| 127 | + LoginState loginState = (LoginState) request.getAttribute("loginState"); | |
| 128 | + Users users = usersService.getUsersByLoginCenterId(loginState.getId()); | |
| 125 | 129 | |
| 126 | 130 | if (null == name || null == orgId || null == users) { |
| 127 | 131 | ResultUtils.buildParameterErrorResultAndWrite(response); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/OrganizationController.java
View file @
75f68f7
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | import com.lyms.platform.common.annotation.TokenRequired; |
| 5 | 5 | import com.lyms.platform.common.base.BaseController; |
| 6 | 6 | import com.lyms.platform.common.base.ContextHolder; |
| 7 | +import com.lyms.platform.common.base.LoginState; | |
| 7 | 8 | import com.lyms.platform.common.base.PlatformContext; |
| 8 | 9 | import com.lyms.platform.common.constants.ErrorCodeConstants; |
| 9 | 10 | import com.lyms.platform.common.enums.YnEnums; |
| ... | ... | @@ -19,6 +20,7 @@ |
| 19 | 20 | import org.springframework.stereotype.Controller; |
| 20 | 21 | import org.springframework.web.bind.annotation.*; |
| 21 | 22 | |
| 23 | +import javax.servlet.http.HttpServletRequest; | |
| 22 | 24 | import javax.servlet.http.HttpServletResponse; |
| 23 | 25 | import java.util.Date; |
| 24 | 26 | import java.util.List; |
| ... | ... | @@ -118,6 +120,7 @@ |
| 118 | 120 | @RequestMapping(value = "/organization", method = RequestMethod.POST) |
| 119 | 121 | @TokenRequired |
| 120 | 122 | public void addOrganization(HttpServletResponse response, |
| 123 | + HttpServletRequest request, | |
| 121 | 124 | @RequestParam(value = "name") String name, |
| 122 | 125 | @RequestParam(value = "type") Integer type, |
| 123 | 126 | @RequestParam(value = "level") Integer level, |
| ... | ... | @@ -130,9 +133,8 @@ |
| 130 | 133 | @RequestParam(value = "shortCode") String shortCode) { |
| 131 | 134 | |
| 132 | 135 | //获取登录用户 |
| 133 | - PlatformContext mommyBobyContext = ContextHolder.getContext(); | |
| 134 | - String token = mommyBobyContext.getToken(); | |
| 135 | - Users users = usersService.getUsers(tokenService.getUserId(token)); | |
| 136 | + LoginState loginState = (LoginState) request.getAttribute("loginState"); | |
| 137 | + Users users = usersService.getUsersByLoginCenterId(loginState.getId()); | |
| 136 | 138 | |
| 137 | 139 | if (type == null || StringUtils.isBlank(name) || null == users) { |
| 138 | 140 | ResultUtils.buildParameterErrorResultAndWrite(response); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/RolesController.java
View file @
75f68f7
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | import com.lyms.platform.common.annotation.TokenRequired; |
| 5 | 5 | import com.lyms.platform.common.base.BaseController; |
| 6 | 6 | import com.lyms.platform.common.base.ContextHolder; |
| 7 | +import com.lyms.platform.common.base.LoginState; | |
| 7 | 8 | import com.lyms.platform.common.base.PlatformContext; |
| 8 | 9 | import com.lyms.platform.common.constants.ConstantInterface; |
| 9 | 10 | import com.lyms.platform.common.enums.YnEnums; |
| ... | ... | @@ -18,6 +19,7 @@ |
| 18 | 19 | import org.springframework.stereotype.Controller; |
| 19 | 20 | import org.springframework.web.bind.annotation.*; |
| 20 | 21 | |
| 22 | +import javax.servlet.http.HttpServletRequest; | |
| 21 | 23 | import javax.servlet.http.HttpServletResponse; |
| 22 | 24 | import java.util.*; |
| 23 | 25 | |
| ... | ... | @@ -101,6 +103,7 @@ |
| 101 | 103 | @RequestMapping(value = "/roles",method = RequestMethod.POST) |
| 102 | 104 | @TokenRequired |
| 103 | 105 | public void addRoles(HttpServletResponse response, |
| 106 | + HttpServletRequest request, | |
| 104 | 107 | @RequestParam(value = "type")Integer type, |
| 105 | 108 | @RequestParam(value = "name")String name, |
| 106 | 109 | @RequestParam(value = "enable")Integer enable, |
| ... | ... | @@ -108,9 +111,8 @@ |
| 108 | 111 | @RequestParam(value = "shortCode")String shortCode) { |
| 109 | 112 | |
| 110 | 113 | //获取登录用户 |
| 111 | - PlatformContext mommyBobyContext = ContextHolder.getContext(); | |
| 112 | - String token = mommyBobyContext.getToken(); | |
| 113 | - Users users = usersService.getUsers(tokenService.getUserId(token)); | |
| 114 | + LoginState loginState = (LoginState) request.getAttribute("loginState"); | |
| 115 | + Users users = usersService.getUsersByLoginCenterId(loginState.getId()); | |
| 114 | 116 | |
| 115 | 117 | if (type == null || StringUtils.isBlank(name) || null == users) { |
| 116 | 118 | ResultUtils.buildParameterErrorResultAndWrite(response); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
View file @
75f68f7
| ... | ... | @@ -4,9 +4,11 @@ |
| 4 | 4 | import com.lyms.platform.common.annotation.TokenRequired; |
| 5 | 5 | import com.lyms.platform.common.base.BaseController; |
| 6 | 6 | import com.lyms.platform.common.base.ContextHolder; |
| 7 | +import com.lyms.platform.common.base.LoginState; | |
| 7 | 8 | import com.lyms.platform.common.base.PlatformContext; |
| 8 | 9 | import com.lyms.platform.common.cache.redis.RedisUtils; |
| 9 | 10 | import com.lyms.platform.common.constants.ConstantInterface; |
| 11 | +import com.lyms.platform.common.constants.ErrorCodeConstants; | |
| 10 | 12 | import com.lyms.platform.common.constants.TimeConstants; |
| 11 | 13 | import com.lyms.platform.common.enums.YnEnums; |
| 12 | 14 | import com.lyms.platform.common.utils.*; |
| 13 | 15 | |
| ... | ... | @@ -15,10 +17,12 @@ |
| 15 | 17 | import org.apache.commons.collections.CollectionUtils; |
| 16 | 18 | import org.apache.commons.lang.StringUtils; |
| 17 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | +import org.springframework.beans.factory.annotation.Value; | |
| 18 | 21 | import org.springframework.http.MediaType; |
| 19 | 22 | import org.springframework.stereotype.Controller; |
| 20 | 23 | import org.springframework.web.bind.annotation.*; |
| 21 | 24 | |
| 25 | +import javax.servlet.http.HttpServletRequest; | |
| 22 | 26 | import javax.servlet.http.HttpServletResponse; |
| 23 | 27 | import java.text.MessageFormat; |
| 24 | 28 | import java.util.*; |
| 25 | 29 | |
| ... | ... | @@ -41,9 +45,12 @@ |
| 41 | 45 | UserOrganizationMapsService userOrganizationMapsService; |
| 42 | 46 | @Autowired |
| 43 | 47 | OrganizationService organizationService; |
| 48 | + @Value("#{configProperties['login.token']}") | |
| 49 | + private String token; | |
| 50 | + @Value("#{configProperties['login.typeId']}") | |
| 51 | + private String typeId; | |
| 44 | 52 | |
| 45 | 53 | |
| 46 | - | |
| 47 | 54 | private static final String LYMS = "龙源美生"; |
| 48 | 55 | |
| 49 | 56 | |
| 50 | 57 | |
| 51 | 58 | |
| ... | ... | @@ -103,44 +110,22 @@ |
| 103 | 110 | writeJson(response, JsonUtil.obj2JsonString(resultMsgMap)); |
| 104 | 111 | return; |
| 105 | 112 | } |
| 113 | + | |
| 106 | 114 | UsersQuery usersQuery = new UsersQuery(); |
| 107 | 115 | usersQuery.setPhone(account); |
| 108 | - usersQuery.setYn(YnEnums.YES.getId()); | |
| 109 | - List<Users> usersList = usersService.queryUsers(usersQuery); | |
| 116 | + List<Users> users = usersService.queryUsers(usersQuery); | |
| 117 | + if(0 == users.size()) { | |
| 118 | + ResultUtils.buildParameterErrorResultAndWrite(response, "该账户不存在"); | |
| 119 | + return; | |
| 120 | + } | |
| 110 | 121 | |
| 111 | - //判断这个查询出来的集合不为空 | |
| 112 | - if (CollectionUtils.isNotEmpty(usersList)) { | |
| 113 | - Users users = usersList.get(0); | |
| 114 | - //从redis里面获取验证码 | |
| 115 | - Object verCodeObj = (Object) RedisUtils.getObj("c_" + account); | |
| 116 | - if (null == verCodeObj) { | |
| 117 | - //参数错误 | |
| 118 | - resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.VER_CODE_EXPIRE); | |
| 119 | - resultMsgMap.put(ResultUtils.ERROR_MSG, "验证码已过期,请重新获取."); | |
| 120 | - writeJson(response, JsonUtil.obj2JsonString(resultMsgMap));//把这个map转成一个json字符串输出到前台 | |
| 121 | - return; | |
| 122 | - } | |
| 123 | - if (code.equals(verCodeObj)) { | |
| 124 | - resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.SUCCESS); | |
| 125 | - resultMsgMap.put(ResultUtils.ERROR_MSG, "成功"); | |
| 126 | - //修改最后一次登录时间 | |
| 127 | - users.setLastLoginTime(new Date()); | |
| 128 | - usersService.updateUsers(users); | |
| 129 | - | |
| 130 | - //创建token | |
| 131 | - resultMsgMap.put("token", tokenService.createToken(users.getId(), 3600)); | |
| 132 | - //id | |
| 133 | - resultMsgMap.put("id", users.getId()); | |
| 134 | - writeJson(response, JsonUtil.obj2JsonString(resultMsgMap)); | |
| 135 | - } else { | |
| 136 | - resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.USER_PASSWORD_ERROR); | |
| 137 | - resultMsgMap.put(ResultUtils.ERROR_MSG, "验证码错误,请重新输入"); | |
| 138 | - writeJson(response, JsonUtil.obj2JsonString(resultMsgMap)); | |
| 139 | - } | |
| 140 | - } else { | |
| 141 | - resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.USER_NOT_EXISTS); | |
| 142 | - resultMsgMap.put(ResultUtils.ERROR_MSG, "登录失败,用户信息不存在"); | |
| 143 | - writeJson(response, JsonUtil.obj2JsonString(resultMsgMap)); | |
| 122 | + String key =LoginUtil.login(account,code, typeId, token); | |
| 123 | + if(null != key) { | |
| 124 | + Map<String, Object> result = new HashMap<>(); | |
| 125 | + result.put("token", key); | |
| 126 | + ResultUtils.buildSuccessResultAndWrite(response, result); | |
| 127 | + }else { | |
| 128 | + ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.PARAMETER_ERROR, "登录失败,手机或验证码错误"); | |
| 144 | 129 | } |
| 145 | 130 | } |
| 146 | 131 | |
| 147 | 132 | |
| 148 | 133 | |
| ... | ... | @@ -158,48 +143,19 @@ |
| 158 | 143 | return; |
| 159 | 144 | } |
| 160 | 145 | |
| 161 | - try { | |
| 162 | - UsersQuery usersQuery = new UsersQuery(); | |
| 163 | - usersQuery.setPhone(phone); | |
| 164 | - usersQuery.setYn(YnEnums.YES.getId()); | |
| 165 | - String countKey = "c_" + phone; | |
| 166 | - Object obj = RedisUtils.getObj(phone); | |
| 146 | + UsersQuery usersQuery = new UsersQuery(); | |
| 147 | + usersQuery.setPhone(phone); | |
| 148 | + int count = usersService.queryUsersCount(usersQuery); | |
| 149 | + if(0 == count) { | |
| 150 | + ResultUtils.buildParameterErrorResultAndWrite(httpServletResponse, "该账户不存在"); | |
| 151 | + return; | |
| 152 | + } | |
| 167 | 153 | |
| 168 | - if (usersService.queryUsersCount(usersQuery) > 0 && (null == obj || (Integer) obj <= 9)) { | |
| 169 | - String code = NumberUtils.getRandomString(6); | |
| 170 | - //设置缓存10分钟验证码 | |
| 171 | - RedisUtils.setObj(countKey, code, TimeConstants.TEN_MINUTE); | |
| 172 | 154 | |
| 173 | - System.out.println(phone + "----" + code); | |
| 174 | - //发送短信 | |
| 175 | - MessageUtil.send(phone, ConstantInterface.SHORT_MESSAGE_PRE + MessageFormat.format("验证码{0},您正在登录区域平台,若非本人操作,请勿泄露。", code)); | |
| 176 | - | |
| 177 | - ResultUtils.buildSuccessResultAndWrite(httpServletResponse); | |
| 178 | - int count = 0; | |
| 179 | - if (null != obj) { | |
| 180 | - count = (Integer) obj; | |
| 181 | - } | |
| 182 | - count += 1; | |
| 183 | - RedisUtils.setObj(phone, count, DateUtil.getDaySeconds()); | |
| 184 | - } else if (obj != null) { | |
| 185 | - Map<String, Object> resultMsgMap = new HashMap<>(); | |
| 186 | - //参数错误 | |
| 187 | - resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 188 | - resultMsgMap.put(ResultUtils.ERROR_MSG, "您已超过限制."); | |
| 189 | - writeJson(httpServletResponse, JsonUtil.obj2JsonString(resultMsgMap)); | |
| 190 | - } else { | |
| 191 | - Map<String, Object> resultMsgMap = new HashMap<>(); | |
| 192 | - //参数错误 | |
| 193 | - resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 194 | - resultMsgMap.put(ResultUtils.ERROR_MSG, "您的手机号没注册."); | |
| 195 | - writeJson(httpServletResponse, JsonUtil.obj2JsonString(resultMsgMap)); | |
| 196 | - } | |
| 197 | - } catch (Exception e) { | |
| 198 | - Map<String, Object> resultMsgMap = new HashMap<>(); | |
| 199 | - //参数错误 | |
| 200 | - resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 201 | - resultMsgMap.put(ResultUtils.ERROR_MSG, "请重试."); | |
| 202 | - writeJson(httpServletResponse, JsonUtil.obj2JsonString(resultMsgMap)); | |
| 155 | + if(LoginUtil.sendVerCode(phone, typeId, token) ) { | |
| 156 | + ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SUCCESS, "发送成功"); | |
| 157 | + } else { | |
| 158 | + ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SUCCESS, "发送失败"); | |
| 203 | 159 | } |
| 204 | 160 | } |
| 205 | 161 | |
| ... | ... | @@ -223,8 +179,6 @@ |
| 223 | 179 | @RequestMapping(value = "/adminPermissions", method = RequestMethod.POST) |
| 224 | 180 | @TokenRequired |
| 225 | 181 | public void adminPermissions(HttpServletResponse response,@RequestParam(value = "userId") Integer userId, @RequestParam(value = "ids") String ids){ |
| 226 | - PlatformContext mommyBobyContext = ContextHolder.getContext(); | |
| 227 | - String token = mommyBobyContext.getToken(); | |
| 228 | 182 | |
| 229 | 183 | if (ids == null) { |
| 230 | 184 | ResultUtils.buildParameterErrorResultAndWrite(response); |
| ... | ... | @@ -292,6 +246,7 @@ |
| 292 | 246 | @RequestMapping(value = "/users", method = RequestMethod.POST) |
| 293 | 247 | @TokenRequired |
| 294 | 248 | public void addUsers(HttpServletResponse response, |
| 249 | + HttpServletRequest request, | |
| 295 | 250 | @RequestParam(value = "type") Integer type, |
| 296 | 251 | @RequestParam(value = "deptId") Integer deptId, |
| 297 | 252 | @RequestParam(value = "orgId") Integer orgId, |
| 298 | 253 | |
| ... | ... | @@ -302,11 +257,12 @@ |
| 302 | 257 | @RequestParam(value = "remarks") String remarks, |
| 303 | 258 | @RequestParam(value = "roleIds") String roleIds) { |
| 304 | 259 | |
| 305 | - PlatformContext mommyBobyContext = ContextHolder.getContext(); | |
| 306 | - String token = mommyBobyContext.getToken(); | |
| 307 | - //获取登录用户ID | |
| 308 | - Users user = usersService.getUsers(Integer.valueOf(tokenService.getUserId(token))); | |
| 309 | 260 | |
| 261 | + //获取登录用户 | |
| 262 | + LoginState loginState = (LoginState) request.getAttribute("loginState"); | |
| 263 | + Users user = usersService.getUsersByLoginCenterId(loginState.getId()); | |
| 264 | + | |
| 265 | + | |
| 310 | 266 | if (type == null || StringUtils.isBlank(roleIds) || deptId == null || |
| 311 | 267 | StringUtils.isBlank(name) /*|| StringUtils.isBlank(account) || |
| 312 | 268 | StringUtils.isBlank(pwd) */ || StringUtils.isBlank(phone) || null == user) { |
| ... | ... | @@ -328,6 +284,7 @@ |
| 328 | 284 | return; |
| 329 | 285 | } |
| 330 | 286 | |
| 287 | + //准备添加数据 | |
| 331 | 288 | Users users = new Users(); |
| 332 | 289 | users.setType(type); |
| 333 | 290 | users.setDeptId(deptId); |
| ... | ... | @@ -344,6 +301,15 @@ |
| 344 | 301 | users.setCreated(new Date()); |
| 345 | 302 | users.setLastLoginTime(new Date()); |
| 346 | 303 | // users.setPwd(LoginUtil.md5(NumberUtils.getRandomString(6))); |
| 304 | + | |
| 305 | + //关联登录中心ID | |
| 306 | + Integer loginCenterId = LoginUtil.register(phone, token, typeId); | |
| 307 | + if(null == loginCenterId) { | |
| 308 | + ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.SYSTEM_ERROR, "服务器内部错误"); | |
| 309 | + return; | |
| 310 | + } | |
| 311 | + users.setLogincenterId(loginCenterId); | |
| 312 | + | |
| 347 | 313 | usersService.addUsers(users); |
| 348 | 314 | |
| 349 | 315 | |
| 350 | 316 | |
| ... | ... | @@ -385,10 +351,9 @@ |
| 385 | 351 | @RequestParam(value = "remarks",required = false) String remarks, |
| 386 | 352 | @RequestParam(value = "roleIds",required = false) String roleIds) { |
| 387 | 353 | |
| 388 | - PlatformContext mommyBobyContext = ContextHolder.getContext(); | |
| 389 | - String token = mommyBobyContext.getToken(); | |
| 390 | 354 | |
| 391 | 355 | |
| 356 | + | |
| 392 | 357 | //获取登录用户ID |
| 393 | 358 | Integer userId = Integer.valueOf(tokenService.getUserId(token)); |
| 394 | 359 | if (userId != null) { |
| 395 | 360 | |
| ... | ... | @@ -463,9 +428,8 @@ |
| 463 | 428 | @RequestMapping(value = "/users/enable", method = RequestMethod.POST) |
| 464 | 429 | @TokenRequired |
| 465 | 430 | public void enableUsers(HttpServletResponse response,@RequestParam Integer id, @RequestParam Integer flag) { |
| 466 | - PlatformContext mommyBobyContext = ContextHolder.getContext(); | |
| 467 | - String token = mommyBobyContext.getToken(); | |
| 468 | 431 | |
| 432 | + | |
| 469 | 433 | //检查账户是否存在 |
| 470 | 434 | UsersQuery usersQuery = new UsersQuery(); |
| 471 | 435 | usersQuery.setId(id); |
| ... | ... | @@ -543,6 +507,7 @@ |
| 543 | 507 | @RequestMapping(value = "/passwords", method = RequestMethod.PUT) |
| 544 | 508 | @TokenRequired |
| 545 | 509 | public void updateUserPwd(HttpServletResponse httpServletResponse, |
| 510 | + HttpServletRequest request, | |
| 546 | 511 | @RequestParam(value = "oldPwd") String oldPwd, |
| 547 | 512 | @RequestParam(value = "newPwd") String newPwd) { |
| 548 | 513 | Map<String, Object> resultMsgMap = new HashMap<String, Object>(); |
| 549 | 514 | |
| 550 | 515 | |
| 551 | 516 | |
| ... | ... | @@ -550,19 +515,20 @@ |
| 550 | 515 | ResultUtils.buildParameterErrorResultAndWrite(httpServletResponse); |
| 551 | 516 | return; |
| 552 | 517 | } |
| 553 | - PlatformContext mommyBobyContext = ContextHolder.getContext(); | |
| 554 | - Integer userId = tokenService.getUserId(mommyBobyContext.getToken()); | |
| 518 | + //获取登录用户 | |
| 519 | + LoginState loginState = (LoginState) request.getAttribute("loginState"); | |
| 520 | + Users users = usersService.getUsersByLoginCenterId(loginState.getId()); | |
| 555 | 521 | |
| 556 | - if (null != userId) { | |
| 522 | + if (null != users) { | |
| 557 | 523 | //修改前的密码 |
| 558 | - Users users = usersService.getUsers(userId); | |
| 524 | + | |
| 559 | 525 | //验证之前的密码和数据库中的密码是否一致 |
| 560 | 526 | if (null != users && LoginUtil.md5(oldPwd).equals(users.getPwd()) && !LoginUtil.md5(newPwd).equals(users.getPwd())) { |
| 561 | 527 | |
| 562 | 528 | Users newUsers = new Users(); |
| 563 | 529 | newUsers.setPwd(LoginUtil.md5(newPwd)); |
| 564 | 530 | newUsers.setModified(new Date()); |
| 565 | - newUsers.setId(userId); | |
| 531 | + newUsers.setId(users.getId()); | |
| 566 | 532 | |
| 567 | 533 | //修改数据库的值 |
| 568 | 534 | usersService.updateUsers(newUsers); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/TokenValidateInteceptor.java
View file @
75f68f7
| ... | ... | @@ -4,12 +4,17 @@ |
| 4 | 4 | import com.lyms.platform.common.annotation.TokenRequired; |
| 5 | 5 | import com.lyms.platform.common.base.BaseController; |
| 6 | 6 | import com.lyms.platform.common.base.ContextHolder; |
| 7 | +import com.lyms.platform.common.base.LoginState; | |
| 7 | 8 | import com.lyms.platform.common.base.PlatformContext; |
| 8 | 9 | import com.lyms.platform.common.exception.ParameterException; |
| 9 | 10 | import com.lyms.platform.common.exception.TokenException; |
| 10 | 11 | import com.lyms.platform.common.utils.LogUtil; |
| 12 | +import com.lyms.platform.common.utils.LoginUtil; | |
| 11 | 13 | import com.lyms.platform.common.utils.TokenUtils; |
| 14 | +import com.lyms.platform.permission.model.Users; | |
| 15 | +import com.lyms.platform.permission.model.UsersQuery; | |
| 12 | 16 | import com.lyms.platform.permission.service.TokenService; |
| 17 | +import com.lyms.platform.permission.service.UsersService; | |
| 13 | 18 | import org.apache.commons.lang.StringUtils; |
| 14 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | 20 | import org.springframework.web.method.HandlerMethod; |
| ... | ... | @@ -18,6 +23,7 @@ |
| 18 | 23 | import javax.servlet.http.HttpServletRequest; |
| 19 | 24 | import javax.servlet.http.HttpServletResponse; |
| 20 | 25 | import java.lang.annotation.Annotation; |
| 26 | +import java.util.List; | |
| 21 | 27 | |
| 22 | 28 | /** |
| 23 | 29 | * 验证token拦截器 |
| ... | ... | @@ -33,6 +39,8 @@ |
| 33 | 39 | public class TokenValidateInteceptor extends HandlerInterceptorAdapter { |
| 34 | 40 | @Autowired |
| 35 | 41 | private TokenService tokenService; |
| 42 | + @Autowired | |
| 43 | + private UsersService usersService; | |
| 36 | 44 | |
| 37 | 45 | public static boolean isSiteController(Object handler) { |
| 38 | 46 | return handler instanceof HandlerMethod && (((HandlerMethod) handler).getBean() instanceof BaseController); |
| 39 | 47 | |
| ... | ... | @@ -64,23 +72,18 @@ |
| 64 | 72 | if (StringUtils.isEmpty(token)) { |
| 65 | 73 | throw new ParameterException(); |
| 66 | 74 | } |
| 67 | - Object object = null; | |
| 68 | - try { | |
| 69 | - object= tokenService.getUserId(token); | |
| 70 | - if(null==object){ | |
| 71 | - throw new TokenException(); | |
| 72 | - } | |
| 73 | - PlatformContext mommyBabyContext = new PlatformContext(); | |
| 74 | - mommyBabyContext.setToken(token); | |
| 75 | - mommyBabyContext.setUserId( object.toString()); | |
| 76 | - mommyBabyContext.setIpAddr(TokenUtils.getIpAddr(httpServletRequest)); | |
| 77 | - ContextHolder.setContext(mommyBabyContext); | |
| 78 | - LogUtil.tokenInfo("from:" + mommyBabyContext.getIpAddr() + ", userId:" + mommyBabyContext.getUserId() + ", token:" + mommyBabyContext.getToken() + ",url:" + httpServletRequest.getRequestURI() + ",method:" + httpServletRequest.getMethod()); | |
| 79 | - } catch (Exception e) { | |
| 80 | - LogUtil.tokenError("", e); | |
| 75 | + LoginState loginState = LoginUtil.checkLoginState(token); | |
| 76 | + if(!loginState.isLogin()) { | |
| 81 | 77 | throw new TokenException(); |
| 82 | 78 | } |
| 83 | - return null != object; | |
| 79 | + Users users = usersService.getUsersByLoginCenterId(loginState.getId()); | |
| 80 | + if(null == users) { | |
| 81 | + throw new TokenException(); | |
| 82 | + } | |
| 83 | + httpServletRequest.setAttribute("loginState", loginState); | |
| 84 | + LogUtil.tokenInfo( " userId:" + users.getId() + ", ,url:" + httpServletRequest.getRequestURI() + ",method:" + httpServletRequest.getMethod()); | |
| 85 | + | |
| 86 | + return loginState.isLogin(); | |
| 84 | 87 | } |
| 85 | 88 | /** |
| 86 | 89 | * This implementation is empty. |