Browse Source

重置密码功能

yingp 7 years ago
parent
commit
f2b8920e04

+ 18 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/controller/AccountController.java

@@ -100,6 +100,24 @@ public class AccountController {
         return Result.success(getAccountDTO(account));
     }
 
+    /**
+     * 重置当前登录账户的密码
+     *
+     * @param password
+     * @return
+     */
+    @PostMapping(value = "/pwd/reset")
+    public Result resetPad(@RequestParam(value = "password") String password) {
+        Account account = accountService.findByPrimaryKey(BaseContextHolder.getUserId());
+        if (null == account) {
+            return Result.error(ExceptionCode.USER_NOT_EXIST);
+        }
+
+        account.setPassword(accountService.getEncryptedPassword(password, account.getSalt()));
+        accountService.updateByPrimaryKey(account);
+        return Result.success();
+    }
+
     /**
      * 账户 + 账户的全部绑定信息
      *

+ 16 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/AccountMapper.java

@@ -26,6 +26,22 @@ public interface AccountMapper {
      */
     int insertSelective(Account account);
 
+    /**
+     * 按主键更新
+     *
+     * @param account
+     * @return
+     */
+    int updateByPrimaryKey(Account account);
+
+    /**
+     * 按主键更新非空字段
+     *
+     * @param account
+     * @return
+     */
+    int updateByPrimaryKeySelective(Account account);
+
     /**
      * 按ID查找
      *

+ 8 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/AccountService.java

@@ -18,6 +18,14 @@ public interface AccountService {
      */
     boolean save(Account account);
 
+    /**
+     * 更新
+     *
+     * @param account
+     * @return
+     */
+    boolean updateByPrimaryKey(Account account);
+
     /**
      * 按用户名查找
      *

+ 14 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/impl/AccountServiceImpl.java

@@ -10,11 +10,13 @@ import com.usoftchina.saas.account.po.Role;
 import com.usoftchina.saas.account.po.RoleResource;
 import com.usoftchina.saas.account.service.AccountService;
 import com.usoftchina.saas.account.service.RoleService;
+import com.usoftchina.saas.context.BaseContextHolder;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.DigestUtils;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -41,9 +43,21 @@ public class AccountServiceImpl implements AccountService {
 
     @Override
     public boolean save(Account account) {
+        account.setCreateTime(new Date());
+        account.setCreatorId(BaseContextHolder.getUserId());
+        account.setUpdateTime(new Date());
+        account.setUpdaterId(BaseContextHolder.getUserId());
+
         return accountMapper.insert(account) > 0;
     }
 
+    @Override
+    public boolean updateByPrimaryKey(Account account) {
+        account.setUpdateTime(new Date());
+        account.setUpdaterId(BaseContextHolder.getUserId());
+        return accountMapper.updateByPrimaryKeySelective(account) > 0;
+    }
+
     @Override
     public Account findByUsername(String username) {
         return accountMapper.selectByUsername(username);

+ 58 - 0
base-servers/account/account-server/src/main/resources/mapper/AccountMapper.xml

@@ -106,6 +106,64 @@
             </if>
         </trim>
     </insert>
+    <update id="updateByPrimaryKey" parameterType="com.usoftchina.saas.account.po.Account">
+        update ac_account set
+        username=#{username,jdbcType=VARCHAR},
+        password=#{password,jdbcType=VARCHAR},
+        salt=#{salt,jdbcType=VARCHAR},
+        realname=#{realname,jdbcType=VARCHAR},
+        email=#{email,jdbcType=VARCHAR},
+        mobile=#{mobile,jdbcType=VARCHAR},
+        type=#{type,jdbcType=INTEGER},
+        enabled=#{enabled,jdbcType=BOOLEAN},
+        creator_id=#{creatorId,jdbcType=BIGINT},
+        create_time=#{createTime,jdbcType=TIMESTAMP},
+        updater_id=#{updaterId,jdbcType=BIGINT},
+        update_time=#{updateTime,jdbcType=TIMESTAMP})
+        where id=#{id,jdbcType=BIGINT}
+    </update>
+    <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.saas.account.po.Account">
+        update ac_account
+        <set>
+            <if test="username != null">
+                username=#{username,jdbcType=VARCHAR},
+            </if>
+            <if test="password != null">
+                password=#{password,jdbcType=VARCHAR},
+            </if>
+            <if test="salt != null">
+                salt=#{salt,jdbcType=VARCHAR},
+            </if>
+            <if test="realname != null">
+                realname=#{realname,jdbcType=VARCHAR},
+            </if>
+            <if test="email != null">
+                email=#{email,jdbcType=VARCHAR},
+            </if>
+            <if test="mobile != null">
+                mobile=#{mobile,jdbcType=VARCHAR},
+            </if>
+            <if test="type != null">
+                type=#{type,jdbcType=INTEGER},
+            </if>
+            <if test="enabled != null">
+                enabled=#{enabled,jdbcType=BOOLEAN},
+            </if>
+            <if test="creatorId != null">
+                creator_id=#{creatorId,jdbcType=BIGINT},
+            </if>
+            <if test="createTime != null">
+                create_time=#{createTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="updaterId != null">
+                updater_id=#{updaterId,jdbcType=BIGINT},
+            </if>
+            <if test="updateTime != null">
+                update_time=#{updateTime,jdbcType=TIMESTAMP})
+            </if>
+        </set>
+        where id=#{id,jdbcType=BIGINT}
+    </update>
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
         select <include refid="baseColumns"/> from ac_account where id=#{id}
     </select>