비밀번호 변경 관련 수정

master
mjkhan21 5 months ago
parent 336ec57a81
commit 3ffe2e6bb8

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

@ -87,11 +87,20 @@ public interface UserService {
boolean update(User user); boolean update(User user);
/** . {@link cokr.xit.foundation.util.CharsEncoder } . /** . {@link cokr.xit.foundation.util.CharsEncoder } .
* @param init
* @param password * @param password
* @param userIDs * @param userIDs
* @return * @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 * @param lock

@ -1,6 +1,7 @@
package cokr.xit.base.user.service.bean; package cokr.xit.base.user.service.bean;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -113,21 +114,50 @@ public class UserBean extends AbstractBean {
User existing = getExistingUser(user); User existing = getExistingUser(user);
if (existing != null && !equals(user.getId(), existing.getId())) if (existing != null && !equals(user.getId(), existing.getId()))
throw applicationException(null) throw applicationException(null)
.setMessage(message("duplicate.object", "사용자")); .setMessage(message("authenticationFailure.badCredentials"));
user.setModifiedBy(currentUser().getId()); user.setModifiedBy(currentUser().getId());
return userMapper.updateUser(user) > 0; 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 } . /** . {@link cokr.xit.foundation.util.CharsEncoder } .
* @param init
* @param password * @param password
* @param userIDs * @param userIDs
* @return * @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); 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 * @param lock
* <ul><li> true</li> * <ul><li> true</li>

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

@ -134,9 +134,18 @@ public class UserController<U extends User> extends AbstractController {
.addObject("saved", saved); .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 password
* @param userIDs
* @return jsonView * @return jsonView
* <pre><code> { * <pre><code> {
* "affected": , * "affected": ,
@ -144,8 +153,16 @@ public class UserController<U extends User> extends AbstractController {
* }</code></pre> * }</code></pre>
*/ */
@PostMapping(name="비밀번호 변경", value="/changePassword.do") @PostMapping(name="비밀번호 변경", value="/changePassword.do")
public ModelAndView changePassword(String userID, String password) { public ModelAndView changePassword(boolean init, String currentPassword, String password, String... userIDs) {
int affected = userService.changePassword(password, userID); 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") return new ModelAndView("jsonView")
.addObject("affected", affected) .addObject("affected", affected)
.addObject("saved", affected > 0); .addObject("saved", affected > 0);

Loading…
Cancel
Save