비밀번호 변경 관련 수정

master
mjkhan21 5 months ago
parent 336ec57a81
commit 3ffe2e6bb8

@ -73,12 +73,10 @@ public interface UserMapper extends AbstractMapper {
* @return
*/
default <T extends User> T getUser(String account, String institute) {
notEmpty(account, "사용자 계정");
notEmpty(institute, "소속 기관 코드");
return getUser(
params()
.set("account", account)
.set("institute", institute)
.set("account", notEmpty(account, "사용자 계정"))
.set("institute", notEmpty(institute, "소속 기관 코드"))
);
}

@ -87,11 +87,20 @@ public interface UserService {
boolean update(User user);
/** . {@link cokr.xit.foundation.util.CharsEncoder } .
* @param init
* @param password
* @param userIDs
* @return
*/
int changePassword(String password, String... userIDs);
int changePassword(boolean init, String password, String... userIDs);
/** . {@link cokr.xit.foundation.util.CharsEncoder } .
* @param userID
* @param currentPassword
* @param password
* @return
*/
int changePassword(String userID, String currentPassword, String password);
/** .
* @param lock

@ -1,6 +1,7 @@
package cokr.xit.base.user.service.bean;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
@ -113,21 +114,50 @@ public class UserBean extends AbstractBean {
User existing = getExistingUser(user);
if (existing != null && !equals(user.getId(), existing.getId()))
throw applicationException(null)
.setMessage(message("duplicate.object", "사용자"));
.setMessage(message("authenticationFailure.badCredentials"));
user.setModifiedBy(currentUser().getId());
return userMapper.updateUser(user) > 0;
}
private String defaultPassword() {
return properties.getString("defaultPassword");
}
/** .
* @param encrypted
* @return
*/
public boolean isDefaultPassword(String encrypted) {
String defaultPassword = defaultPassword();
if (isEmpty(encrypted)
|| isEmpty(defaultPassword))
return false;
return passwordEncoder.matches(defaultPassword, encrypted);
}
/** . {@link cokr.xit.foundation.util.CharsEncoder } .
* @param init
* @param password
* @param userIDs
* @return
*/
public int changePassword(String password, String... userIDs) {
public int changePassword(boolean init, String password, String... userIDs) {
if (init) {
password = defaultPassword();
}
return userMapper.changePassword(passwordEncoder.encode(password), userIDs);
}
public int changePassword(String userID, String currentPassword, String password) {
User user = userMapper.getUser(Map.of("userID", userID));
if (!passwordEncoder.matches(currentPassword, user.getPassword()))
return 0;
return changePassword(false, password, userID);
}
/** .
* @param lock
* <ul><li> true</li>

@ -58,8 +58,13 @@ public class UserServiceBean extends AbstractServiceBean implements UserService
}
@Override
public int changePassword(String password, String... userIDs) {
return userBean.changePassword(password, userIDs);
public int changePassword(boolean init, String password, String... userIDs) {
return userBean.changePassword(init, password, userIDs);
}
@Override
public int changePassword(String userID, String currentPassword, String password) {
return userBean.changePassword(userID, currentPassword, password);
}
@Override

@ -134,9 +134,18 @@ public class UserController<U extends User> extends AbstractController {
.addObject("saved", saved);
}
/** (user/password) .
* @return base/user/password
*/
@RequestMapping(name = "비밀번호 변경", value = "/changePassword.do")
public ModelAndView changePassword() {
return new ModelAndView("base/user/password");
}
/** .
* @param userID
* @param init
* @param password
* @param userIDs
* @return jsonView
* <pre><code> {
* "affected": ,
@ -144,8 +153,16 @@ public class UserController<U extends User> extends AbstractController {
* }</code></pre>
*/
@PostMapping(name="비밀번호 변경", value="/changePassword.do")
public ModelAndView changePassword(String userID, String password) {
int affected = userService.changePassword(password, userID);
public ModelAndView changePassword(boolean init, String currentPassword, String password, String... userIDs) {
int affected = 0;
if (!init) {
affected = isEmpty(currentPassword) ?
userService.changePassword(false, password, userIDs) :
userService.changePassword(userIDs[0], currentPassword, password);
} else {
affected = userService.changePassword(true, password, userIDs);
}
return new ModelAndView("jsonView")
.addObject("affected", affected)
.addObject("saved", affected > 0);

Loading…
Cancel
Save