use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class SystemConfigController method saveWhitelist.
/**
* 保存白名单配置
*
* @return json
*/
@RequestMapping(value = "save_whitelist", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.SYSTEM_NODE_WHITELIST, method = MethodFeature.EDIT)
public String saveWhitelist(@ValidatorItem(msg = "请选择分发的节点") String nodeIds, String project, String certificate, String nginx, String allowEditSuffix, String allowRemoteDownloadHost) {
HttpServletRequest httpServletRequest = getRequest();
String workspaceId = nodeService.getCheckUserWorkspace(httpServletRequest);
NodeAgentWhitelist agentWhitelist = new NodeAgentWhitelist();
agentWhitelist.setNodeIds(nodeIds);
agentWhitelist.setProject(project);
agentWhitelist.setCertificate(certificate);
agentWhitelist.setNginx(nginx);
agentWhitelist.setAllowEditSuffix(allowEditSuffix);
agentWhitelist.setAllowRemoteDownloadHost(allowRemoteDownloadHost);
String format = StrUtil.format("node_whitelist_{}", workspaceId);
systemParametersServer.upsert(format, agentWhitelist, format);
//
List<String> nodeIdsStr = StrUtil.splitTrim(nodeIds, StrUtil.LF);
UserModel user = getUser();
for (String s : nodeIdsStr) {
NodeModel byKey = nodeService.getByKey(s, httpServletRequest);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(agentWhitelist);
JsonMessage<String> request = NodeForward.request(byKey, NodeUrl.WhitelistDirectory_Submit, user, jsonObject);
Assert.state(request.getCode() == 200, "分发 " + byKey.getName() + " 节点配置失败" + request.getMsg());
}
return JsonMessage.getString(200, "保存成功");
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class UserBasicInfoController method generateMfa.
@GetMapping(value = "generate_mfa", produces = MediaType.APPLICATION_JSON_VALUE)
public String generateMfa() {
UserModel user = getUser();
JSONObject jsonObject = new JSONObject();
String tfaKey = TwoFactorAuthUtils.generateTFAKey();
jsonObject.put("mfaKey", tfaKey);
jsonObject.put("url", TwoFactorAuthUtils.generateOtpAuthUrl(user.getId(), tfaKey));
return JsonMessage.getString(200, "", jsonObject);
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class UserBasicInfoController method closeMfa.
/**
* 关闭自己到 mfa 相关信息
*
* @return json
*/
@GetMapping(value = "close_mfa", produces = MediaType.APPLICATION_JSON_VALUE)
public String closeMfa(@ValidatorItem String code) {
UserModel user = getUser();
boolean mfaCode = userService.verifyMfaCode(user.getId(), code);
Assert.state(mfaCode, "验证码不正确");
UserModel userModel = new UserModel(user.getId());
userModel.setTwoFactorAuthKey(StrUtil.EMPTY);
userService.update(userModel);
return JsonMessage.getString(200, "关闭成功");
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class UserBasicInfoController method myWorkspace.
/**
* 查询用户自己的工作空间
*
* @return msg
*/
@GetMapping(value = "my_workspace", produces = MediaType.APPLICATION_JSON_VALUE)
public String myWorkspace() {
UserModel user = getUser();
List<WorkspaceModel> models = userBindWorkspaceService.listUserWorkspaceInfo(user);
Assert.notEmpty(models, "当前账号没有绑定任何工作空间,请联系管理员处理");
return JsonMessage.getString(200, "", models);
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class UserBasicInfoController method bindMfa.
/**
* 绑定 mfa
*
* @param mfa mfa key
* @param twoCode 验证码
* @return json
*/
@GetMapping(value = "bind_mfa", produces = MediaType.APPLICATION_JSON_VALUE)
public String bindMfa(String mfa, String twoCode) {
//
UserModel user = getUser();
boolean bindMfa = userService.hasBindMfa(user.getId());
Assert.state(!bindMfa, "当前账号已经绑定 mfa 啦");
// demo
Assert.state(!user.isDemoUser(), PermissionInterceptor.DEMO_TIP);
//
boolean tfaCode = TwoFactorAuthUtils.validateTFACode(mfa, twoCode);
Assert.state(tfaCode, " mfa 验证码不正确");
userService.bindMfa(user.getId(), mfa);
return JsonMessage.getString(200, "绑定成功");
}
Aggregations