Search in sources :

Example 41 with UserModel

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, "保存成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) NodeAgentWhitelist(io.jpom.model.node.NodeAgentWhitelist) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with UserModel

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);
}
Also used : UserModel(io.jpom.model.data.UserModel) JSONObject(com.alibaba.fastjson.JSONObject) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 43 with UserModel

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, "关闭成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 44 with UserModel

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);
}
Also used : UserModel(io.jpom.model.data.UserModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 45 with UserModel

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, "绑定成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

UserModel (io.jpom.model.data.UserModel)66 JSONObject (com.alibaba.fastjson.JSONObject)17 MethodFeature (io.jpom.permission.MethodFeature)15 ClassFeature (io.jpom.permission.ClassFeature)14 Feature (io.jpom.permission.Feature)14 NodeModel (io.jpom.model.data.NodeModel)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 NotLogin (io.jpom.common.interceptor.NotLogin)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserService (io.jpom.service.user.UserService)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 StrUtil (cn.hutool.core.util.StrUtil)4 Entity (cn.hutool.db.Entity)4 JSONArray (com.alibaba.fastjson.JSONArray)4 BuildInfoModel (io.jpom.model.data.BuildInfoModel)4 List (java.util.List)4 JsonMessage (cn.jiangzeyin.common.JsonMessage)3 BaseServerController (io.jpom.common.BaseServerController)3 WorkspaceModel (io.jpom.model.data.WorkspaceModel)3 UserLoginDto (io.jpom.model.dto.UserLoginDto)3