Commit be1b826f by 宋祥

1.重置密码默认与账号相同

parent 63ba281e
package com.baosight.xservices.xs.service;
import com.baosight.iplat4j.core.cache.CacheManager;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
import com.baosight.iplat4j.core.log.xeye.entity.XEyeEntity;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.core.util.DateUtils;
import com.baosight.xservices.xs.authentication.SecurityBridgeFactory;
import com.baosight.xservices.xs.util.UserSession;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
*
* @author:songx
* @date:2024/10/18,17:45
*/
public class ServiceXS0105 extends ServiceEPBase {
private static Logger logger = LogManager.getLogger(ServiceXS0105.class);
private static String defaultPasswordSwitch = StringUtils.defaultIfEmpty(PlatApplicationContext.getProperty("xservices.security.default.password.switch"), "on");
private static final String loginFailCountCache = "iplat:security:loginFailCountCache";
private Map<String, Integer> failCountCache = CacheManager.getCache("iplat:security:loginFailCountCache");
public ServiceXS0105() {
}
public EiInfo query(EiInfo inInfo) {
String loginName = inInfo.get("loginName").toString();
Map map = new HashMap();
map.put("loginName", loginName);
List resultList = this.dao.query("XS0105.query", map);
if (null != resultList && resultList.size() == 1) {
inInfo.setStatus(EiConstant.STATUS_SUCCESS);
Map result = (Map)resultList.get(0);
inInfo.set("loginName", result.get("loginName"));
inInfo.set("userName", result.get("userName"));
inInfo.set("mobile", result.get("mobile"));
inInfo.set("email", result.get("email"));
} else {
inInfo.setStatus(EiConstant.STATUS_FAILURE);
inInfo.setMsg("请输入正确的登录账号!");
}
return inInfo;
}
public EiInfo resetPassword(EiInfo inInfo) {
String msg = "";
int status = -1;
String revisor = UserSession.getUser().getUsername();
String loginName = inInfo.get("loginName").toString();
try {
Map map = new HashMap();
map.put("loginName", loginName);
List resultList = this.dao.query("XS0104.query", map);
if (resultList != null && resultList.size() > 0) {
Map result = (Map)resultList.get(0);
String newPassword = "";
String defaultPassword;
if ("on".equals(defaultPasswordSwitch)) {
defaultPassword = StringUtils.defaultIfEmpty(PlatApplicationContext.getProperty("xservices.security.default.password"), "admin123!@#");
if (StringUtils.isBlank(defaultPassword)) {
defaultPassword = loginName;
}
newPassword = SecurityBridgeFactory.getSecurityPasswordEncrypt().encode(loginName);
} else {
newPassword = SecurityBridgeFactory.getSecurityPasswordEncrypt().encode(loginName);
}
map.put("password", newPassword);
map.put("status", "1");
map.put("isLocked", "1");
map.put("recRevisor", revisor);
map.put("recReviseTime", DateUtils.curDateTimeStr14());
map.put("pwdRevisor", revisor);
map.put("pwdReviseDate", DateUtils.curDateTimeStr14());
map.put("userId", result.get("userId"));
defaultPassword = StringUtils.defaultIfEmpty(PlatApplicationContext.getProperty("xservices.security.accountExpireDays"), "90");
String pwdExpireDays = StringUtils.defaultIfEmpty(PlatApplicationContext.getProperty("xservices.security.pwdExpireDays"), "90");
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(DateUtils.toDate8(DateUtils.curDateStr8()));
gc.add(5, Integer.parseInt(pwdExpireDays));
map.put("pwdExpireDate", DateUtils.toDateStr8(gc.getTime()));
gc.setTime(DateUtils.toDate8(DateUtils.curDateStr8()));
gc.add(5, Integer.parseInt(defaultPassword));
map.put("accountExpireDate", DateUtils.toDateStr8(gc.getTime()));
this.dao.update("XS0104.update", map);
this.failCountCache.remove(loginName);
msg = "重置密码成功!";
status = 1;
XEyeEntity xEyeEntity = new XEyeEntity();
xEyeEntity.setLogId("1004");
xEyeEntity.setLogName("重置密码");
xEyeEntity.setInvokeInfo(UserSession.getUser().getUsername() + "在" + DateUtils.curDateStr("yyyy-MM-dd HH:mm:ss") + "重置了登录名为:" + result.get("loginName") + "的用户的密码");
xEyeEntity.setStatus(inInfo.getStatus() + "");
xEyeEntity.set("x_xs_id", result.get("userId"));
xEyeEntity.set("x_xs_on", UserSession.getUser().getUsername());
xEyeEntity.set("x_xs_ln", result.get("loginName"));
this.log(xEyeEntity);
}
} catch (Exception var14) {
msg = var14.getMessage();
logger.error(var14.getCause().getMessage());
}
inInfo.setMsg(msg);
inInfo.setStatus(status);
return inInfo;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment