dcs 2 місяців тому
батько
коміт
16ab944fc1

+ 2 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/dao/MgrUserDao.java

@@ -30,6 +30,8 @@ public interface MgrUserDao {
 
 	public int updatePhone(MgrUser user);
 
+	public int updatePwd(MgrUser user);
+
 	public int banUser(long id, int status);
 
 	public int checkFace(long id);

+ 10 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/model/MgrUser.java

@@ -17,6 +17,8 @@ public class MgrUser implements BaseModel {
 
 	private String phone;
 
+	private String pwd;
+
 	private String email;
 
 	private Date createTime;
@@ -93,6 +95,14 @@ public class MgrUser implements BaseModel {
 		this.phone = phone;
 	}
 
+	public String getPwd() {
+		return pwd;
+	}
+
+	public void setPwd(String pwd) {
+		this.pwd = pwd;
+	}
+
 	public String getEmail() {
 		return email;
 	}

+ 12 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/shiro/LoginUserDto.java

@@ -7,6 +7,11 @@ public class LoginUserDto {
      */
     private String phone;
 
+    /**
+     * 密码
+     */
+    private String password;
+
     /**
      * 手机号验证码
      */
@@ -54,4 +59,11 @@ public class LoginUserDto {
         this.pCode = pCode;
     }
 
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
 }

+ 9 - 1
virgo.core/src/main/java/com/bosshand/virgo/core/shiro/UserRealm.java

@@ -43,7 +43,15 @@ public class UserRealm extends AuthorizingRealm {
 		if (mgrUser.getStatus() == 1) {
 			throw new AuthenticationException("该用户已被封号");
 		}
-		return new SimpleAuthenticationInfo(phone, CodeCache.getKey(phone), "UserRealm");
+
+		String pwd = null;
+
+		if (CodeCache.getKey(phone) != null) {
+			pwd = CodeCache.getKey(phone);
+		} else {
+			pwd = mgrUser.getPwd();
+		}
+		return new SimpleAuthenticationInfo(phone, pwd, "UserRealm");
 	}
 
 	@Override

+ 7 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/shiro/VirgoAuthenticationFilter.java

@@ -7,6 +7,7 @@ import com.bosshand.virgo.core.model.MgrUser;
 import com.bosshand.virgo.core.response.Response;
 import com.bosshand.virgo.core.service.MgrUserService;
 import com.bosshand.virgo.core.utils.CodeCache;
+import com.bosshand.virgo.core.utils.SecurityUtils;
 import com.bosshand.virgo.exception.AuthException;
 import com.bosshand.virgo.exception.Constant;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -110,6 +111,12 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 				return createToken(dto.getPhone(), CodeCache.DefaultPhoneCode, request, response);
 			}
 
+			// 密码登录
+			if(dto.getPassword() != null){
+				String password = SecurityUtils.MD5LoginSecu(dto.getPassword().getBytes());
+				return createToken(dto.getPhone(), password, request, response);
+			}
+
 			// 手机号验证码注册登录
 			phoneCode = CodeCache.getKey(dto.getPhone());
 			if (!dto.getPhoneCode().equals(phoneCode)) {

+ 5 - 0
virgo.core/src/main/resources/mapper/MgrUserMapper.xml

@@ -9,6 +9,7 @@
 	<result column="name" property="name"/>	
 	<result column="sex" property="sex"/>	
 	<result column="phone" property="phone"/>
+	<result column="pwd" property="pwd"/>
 	<result column="email" property="email"/>
 	<result column="portrait" property="portrait"/>	
 	<result column="create_time" property="createTime"/>
@@ -95,6 +96,10 @@
 	UPDATE mgr_user SET phone = #{phone} where id =#{id}
 </update>
 
+<update id="updatePwd" parameterType="com.bosshand.virgo.core.model.MgrUser">
+	UPDATE mgr_user SET pwd = #{pwd} where id =#{id}
+</update>
+
 <update id="banUser" parameterType="com.bosshand.virgo.core.model.MgrUser">
 	UPDATE mgr_user set status = #{status} WHERE id=#{id}
 </update>

+ 9 - 0
virgo.manager/src/main/java/com/bosshand/virgo/controller/UserInfoController.java

@@ -81,6 +81,15 @@ public class UserInfoController {
 		return Response.ok();
 	}
 
+	@ApiOperation(value="个人信息管理", notes="设置修改密码")
+	@RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
+	public Response updatePwd(@RequestBody MgrUser user) {
+		userService.updatePwd(user);
+		mgrUserService.loadContext(SecurityUtils.getSubject());
+		return Response.ok();
+	}
+
+
 	@ApiOperation(value="个人信息管理", notes="个人信息")
 	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
 	public Response getUser(@PathVariable long id) {

+ 7 - 0
virgo.manager/src/main/java/com/bosshand/virgo/service/UserService.java

@@ -10,6 +10,7 @@ import com.bosshand.virgo.core.model.MgrOrganization;
 import com.bosshand.virgo.core.model.MgrUser;
 import com.bosshand.virgo.core.model.MgrUserRole;
 import com.bosshand.virgo.core.utils.CodeCache;
+import com.bosshand.virgo.core.utils.SecurityUtils;
 import com.bosshand.virgo.core.utils.Utils;
 import com.bosshand.virgo.core.utils.WeChatUtil;
 import com.bosshand.virgo.util.MD5Utils;
@@ -43,6 +44,12 @@ public class UserService {
         return mgrUserDao.getByPhone(phone);
     }
 
+    public int updatePwd(MgrUser user) {
+        String password = SecurityUtils.MD5LoginSecu(user.getPwd().getBytes());
+        user.setPwd(password);
+        return mgrUserDao.updatePwd(user);
+    }
+
     public int update(MgrUser user) {
         int update = mgrUserDao.update(user);
         //修改聊天用户信息