use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class UserBasicInfoController method getUserBasicInfo.
/**
* get user basic info
* 获取管理员基本信息接口
*
* @return json
* @author Hotstrip
*/
@RequestMapping(value = "user-basic-info", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String getUserBasicInfo() {
UserModel userModel = getUser();
userModel = userService.getByKey(userModel.getId(), false);
// return basic info
Map<String, Object> map = new HashMap<>(10);
map.put("id", userModel.getId());
map.put("name", userModel.getName());
map.put("systemUser", userModel.isSystemUser());
map.put("email", userModel.getEmail());
map.put("dingDing", userModel.getDingDing());
map.put("workWx", userModel.getWorkWx());
map.put("md5Token", userModel.getPassword());
boolean bindMfa = userService.hasBindMfa(userModel.getId());
map.put("bindMfa", bindMfa);
return JsonMessage.getString(200, "success", map);
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class UserBasicInfoController method saveBasicInfo.
@RequestMapping(value = "save_basicInfo.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String saveBasicInfo(@ValidatorItem(value = ValidatorRule.EMAIL, msg = "邮箱格式不正确") String email, String dingDing, String workWx, String code) {
UserModel user = getUser();
UserModel userModel = userService.getByKey(user.getId());
// 判断是否一样
if (!StrUtil.equals(email, userModel.getEmail())) {
Integer cacheCode = CACHE.get(email);
if (cacheCode == null || !Objects.equals(cacheCode.toString(), code)) {
return JsonMessage.getString(405, "请输入正确验证码");
}
}
UserModel updateModel = new UserModel(user.getId());
updateModel.setEmail(email);
//
if (StrUtil.isNotEmpty(dingDing) && !Validator.isUrl(dingDing)) {
Validator.validateMatchRegex(RegexPool.URL_HTTP, dingDing, "请输入正确钉钉地址");
}
updateModel.setDingDing(dingDing);
if (StrUtil.isNotEmpty(workWx)) {
Validator.validateMatchRegex(RegexPool.URL_HTTP, workWx, "请输入正确企业微信地址");
}
updateModel.setWorkWx(workWx);
userService.update(updateModel);
return JsonMessage.getString(200, "修改成功");
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class BuildTriggerApiController method getStatusData.
private JSONObject getStatusData(String id, String token) {
JSONObject jsonObject = new JSONObject();
BuildInfoModel item = buildInfoService.getByKey(id);
if (item == null) {
jsonObject.put("msg", "没有对应数据");
return jsonObject;
}
UserModel userModel = BuildTriggerApiController.this.getByUrlToken(token);
if (userModel == null) {
jsonObject.put("msg", "对应的用户不存在,触发器已失效");
return jsonObject;
}
//
if (!StrUtil.equals(token, item.getTriggerToken())) {
jsonObject.put("msg", "触发token错误,或者已经失效");
return jsonObject;
}
// 更新字段
Integer status = item.getStatus();
BuildStatus buildStatus = BaseEnum.getEnum(BuildStatus.class, status);
if (buildStatus == null) {
jsonObject.put("msg", "status code error");
} else {
jsonObject.put("msg", buildStatus.getDesc());
jsonObject.put("statusCode", buildStatus.getCode());
jsonObject.put("status", buildStatus.name());
}
jsonObject.put("buildNumberId", item.getBuildId());
return jsonObject;
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class BuildTriggerApiController method triggerBatch.
/**
* 构建触发器
* <p>
* 参数 <code>[
* {
* "id":"1",
* "token":"a",
* "delay":"0"
* }
* ]</code>
* <p>
* 响应 <code>[
* {
* "id":"1",
* "token":"a",
* "delay":"0",
* "msg":"开始构建",
* "data":1
* }
* ]</code>
*
* @return json
*/
@PostMapping(value = ServerOpenApi.BUILD_TRIGGER_BUILD_BATCH, produces = MediaType.APPLICATION_JSON_VALUE)
public String triggerBatch() {
try {
String body = ServletUtil.getBody(getRequest());
JSONArray jsonArray = JSONArray.parseArray(body);
List<Object> collect = jsonArray.stream().peek(o -> {
JSONObject jsonObject = (JSONObject) o;
String id = jsonObject.getString("id");
String token = jsonObject.getString("token");
Integer delay = jsonObject.getInteger("delay");
String buildRemark = jsonObject.getString("buildRemark");
BuildInfoModel item = buildInfoService.getByKey(id);
if (item == null) {
jsonObject.put("msg", "没有对应数据");
return;
}
UserModel userModel = BuildTriggerApiController.this.getByUrlToken(token);
if (userModel == null) {
jsonObject.put("msg", "对应的用户不存在,触发器已失效");
return;
}
//
if (!StrUtil.equals(token, item.getTriggerToken())) {
jsonObject.put("msg", "触发token错误,或者已经失效");
return;
}
// 更新字段
String updateItemErrorMsg = this.updateItem(jsonObject);
if (updateItemErrorMsg != null) {
jsonObject.put("msg", updateItemErrorMsg);
return;
}
BaseServerController.resetInfo(userModel);
//
JsonMessage<Integer> start = buildExecuteService.start(id, userModel, delay, 1, buildRemark);
jsonObject.put("msg", start.getMsg());
jsonObject.put("buildId", start.getData());
}).collect(Collectors.toList());
return JsonMessage.getString(200, "触发成功", collect);
} catch (Exception e) {
DefaultSystemLog.getLog().error("构建触发批量触发异常", e);
return JsonMessage.getString(500, "触发异常", e.getMessage());
}
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class LoginControl method userLogin.
/**
* 登录接口
*
* @param userName 登录名
* @param userPwd 登录密码
* @param code 验证码
* @return json
*/
@PostMapping(value = "userLogin", produces = MediaType.APPLICATION_JSON_VALUE)
@NotLogin
@Feature(method = MethodFeature.EXECUTE, resultCode = { 200, 201 }, logResponse = false)
public String userLogin(@ValidatorConfig(value = { @ValidatorItem(value = ValidatorRule.NOT_EMPTY, msg = "请输入登录信息") }) String userName, @ValidatorConfig(value = { @ValidatorItem(value = ValidatorRule.NOT_EMPTY, msg = "请输入登录信息") }) String userPwd, String code) {
if (this.ipLock()) {
return JsonMessage.getString(400, "尝试次数太多,请稍后再来");
}
synchronized (userName.intern()) {
UserModel userModel = userService.getByKey(userName);
if (userModel == null) {
this.ipError();
return JsonMessage.getString(400, "登录失败,请输入正确的密码和账号,多次失败将锁定账号");
}
// 获取验证码
String sCode = getSessionAttribute(LOGIN_CODE);
Assert.state(StrUtil.equalsIgnoreCase(code, sCode), "请输入正确的验证码");
removeSessionAttribute(LOGIN_CODE);
UserModel updateModel = null;
try {
long lockTime = userModel.overLockTime();
if (lockTime > 0) {
String msg = DateUtil.formatBetween(lockTime * 1000, BetweenFormatter.Level.SECOND);
updateModel = userModel.errorLock();
this.ipError();
return JsonMessage.getString(400, "该账户登录失败次数过多,已被锁定" + msg + ",请不要再次尝试");
}
// 验证
if (userService.simpleLogin(userName, userPwd) != null) {
updateModel = UserModel.unLock(userName);
this.ipSuccess();
// 判断是否开启 两步验证
boolean bindMfa = userService.hasBindMfa(userName);
if (bindMfa) {
//
JSONObject jsonObject = new JSONObject();
String uuid = IdUtil.fastSimpleUUID();
MFA_TOKEN.put(uuid, userName);
jsonObject.put("tempToken", uuid);
return JsonMessage.getString(201, "请输入两步验证码", jsonObject);
}
UserLoginDto userLoginDto = this.createToken(userModel);
return JsonMessage.getString(200, "登录成功", userLoginDto);
} else {
updateModel = userModel.errorLock();
this.ipError();
return JsonMessage.getString(501, "登录失败,请输入正确的密码和账号,多次失败将锁定账号");
}
} finally {
if (updateModel != null) {
userService.update(updateModel);
}
// 用于记录登录日志
BaseServerController.resetInfo(userModel);
}
}
}
Aggregations