Search in sources :

Example 21 with UserModel

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

Example 22 with UserModel

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

Example 23 with UserModel

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;
}
Also used : UserModel(io.jpom.model.data.UserModel) JSONObject(com.alibaba.fastjson.JSONObject) BuildStatus(io.jpom.model.enums.BuildStatus) BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Example 24 with UserModel

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());
    }
}
Also used : ObjectUtil(cn.hutool.core.util.ObjectUtil) ServerOpenApi(io.jpom.common.ServerOpenApi) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) BuildInfoTriggerController(io.jpom.controller.build.BuildInfoTriggerController) BaseEnum(io.jpom.model.BaseEnum) RegexPool(cn.hutool.core.lang.RegexPool) MediaType(org.springframework.http.MediaType) Collectors(java.util.stream.Collectors) BaseJpomController(io.jpom.common.BaseJpomController) StringUtils(org.h2.util.StringUtils) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) BuildInfoService(io.jpom.service.dblog.BuildInfoService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Convert(cn.hutool.core.convert.Convert) JSONObject(com.alibaba.fastjson.JSONObject) Entity(cn.hutool.db.Entity) BuildInfoModel(io.jpom.model.data.BuildInfoModel) NotLogin(io.jpom.common.interceptor.NotLogin) BuildExecuteService(io.jpom.build.BuildExecuteService) UserModel(io.jpom.model.data.UserModel) BuildStatus(io.jpom.model.enums.BuildStatus) UserService(io.jpom.service.user.UserService) BaseServerController(io.jpom.common.BaseServerController) Validator(cn.hutool.core.lang.Validator) Assert(org.springframework.util.Assert) UserModel(io.jpom.model.data.UserModel) JSONObject(com.alibaba.fastjson.JSONObject) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Example 25 with UserModel

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);
        }
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) JSONObject(com.alibaba.fastjson.JSONObject) UserLoginDto(io.jpom.model.dto.UserLoginDto) NotLogin(io.jpom.common.interceptor.NotLogin) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

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