Search in sources :

Example 11 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class BaseProxyHandler method init.

/**
 * 连接成功 初始化
 *
 * @param session    会话
 * @param attributes 属性
 * @throws URISyntaxException 异常
 * @throws IOException        IO
 */
protected void init(WebSocketSession session, Map<String, Object> attributes) throws URISyntaxException, IOException {
    boolean init = (boolean) attributes.getOrDefault("init", false);
    if (init) {
        return;
    }
    NodeModel nodeModel = (NodeModel) attributes.get("nodeInfo");
    UserModel userInfo = (UserModel) attributes.get("userInfo");
    if (nodeModel != null) {
        Object[] parameters = this.getParameters(attributes);
        String url = NodeForward.getSocketUrl(nodeModel, nodeUrl, userInfo, parameters);
        // 连接节点
        ProxySession proxySession = new ProxySession(url, session);
        session.getAttributes().put("proxySession", proxySession);
    }
    attributes.put("init", true);
}
Also used : UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject)

Example 12 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class OutGivingRun method startRun.

/**
 * 开始异步执行分发任务
 *
 * @param id        分发id
 * @param file      文件
 * @param userModel 操作的用户
 * @param unzip     解压
 */
public static void startRun(String id, File file, UserModel userModel, boolean unzip) {
    OutGivingServer outGivingServer = SpringUtil.getBean(OutGivingServer.class);
    OutGivingModel item = outGivingServer.getByKey(id);
    Objects.requireNonNull(item, "不存在分发");
    AfterOpt afterOpt = ObjectUtil.defaultIfNull(EnumUtil.likeValueOf(AfterOpt.class, item.getAfterOpt()), AfterOpt.No);
    // 
    List<OutGivingNodeProject> outGivingNodeProjects = item.outGivingNodeProjectList();
    // 开启线程
    if (afterOpt == AfterOpt.Order_Restart || afterOpt == AfterOpt.Order_Must_Restart) {
        ThreadUtil.execute(() -> {
            // 截取睡眠时间
            int sleepTime = ObjectUtil.defaultIfNull(item.getIntervalTime(), 10);
            // 
            boolean cancel = false;
            for (OutGivingNodeProject outGivingNodeProject : outGivingNodeProjects) {
                if (cancel) {
                    String userId = userModel == null ? JpomApplication.SYSTEM_ID : userModel.getId();
                    OutGivingItemRun.updateStatus(null, id, outGivingNodeProject, OutGivingNodeProject.Status.Cancel, "前一个节点分发失败,取消分发", userId);
                } else {
                    OutGivingItemRun outGivingRun = new OutGivingItemRun(item, outGivingNodeProject, file, userModel, unzip);
                    OutGivingNodeProject.Status status = outGivingRun.call();
                    if (status != OutGivingNodeProject.Status.Ok) {
                        if (afterOpt == AfterOpt.Order_Must_Restart) {
                            // 完整重启,不再继续剩余的节点项目
                            cancel = true;
                        }
                    }
                    // 休眠x秒 等待之前项目正常启动
                    ThreadUtil.sleep(sleepTime, TimeUnit.SECONDS);
                }
            }
        });
    } else if (afterOpt == AfterOpt.Restart || afterOpt == AfterOpt.No) {
        outGivingNodeProjects.forEach(outGivingNodeProject -> ThreadUtil.execAsync(new OutGivingItemRun(item, outGivingNodeProject, file, userModel, unzip)));
    } else {
        // 
        throw new IllegalArgumentException("Not implemented " + afterOpt.getDesc());
    }
}
Also used : NodeForward(io.jpom.common.forward.NodeForward) ObjectUtil(cn.hutool.core.util.ObjectUtil) EnumUtil(cn.hutool.core.util.EnumUtil) NodeModel(io.jpom.model.data.NodeModel) SpringUtil(cn.jiangzeyin.common.spring.SpringUtil) AfterOpt(io.jpom.model.AfterOpt) File(java.io.File) OutGivingModel(io.jpom.model.data.OutGivingModel) NodeUrl(io.jpom.common.forward.NodeUrl) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) JsonMessage(cn.jiangzeyin.common.JsonMessage) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) JpomApplication(io.jpom.JpomApplication) JSONObject(com.alibaba.fastjson.JSONObject) OutGivingServer(io.jpom.service.node.OutGivingServer) ThreadUtil(cn.hutool.core.thread.ThreadUtil) UserModel(io.jpom.model.data.UserModel) OutGivingServer(io.jpom.service.node.OutGivingServer) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) AfterOpt(io.jpom.model.AfterOpt) OutGivingModel(io.jpom.model.data.OutGivingModel)

Example 13 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class BaseDbService method updateById.

/**
 * update by id with data
 *
 * @param info          data
 * @param whereConsumer 查询条件回调
 * @return 影响的行数
 */
public int updateById(T info, Consumer<Entity> whereConsumer) {
    // check id
    String id = info.getId();
    Assert.hasText(id, "不能执行:error");
    // def modify time
    info.setModifyTimeMillis(ObjectUtil.defaultIfNull(info.getModifyTimeMillis(), SystemClock.now()));
    // remove create time
    Long createTimeMillis = info.getCreateTimeMillis();
    info.setCreateTimeMillis(null);
    // fill modify user
    if (info instanceof BaseUserModifyDbModel) {
        BaseUserModifyDbModel modifyDbModel = (BaseUserModifyDbModel) info;
        UserModel userModel = BaseServerController.getUserModel();
        if (userModel != null) {
            modifyDbModel.setModifyUser(ObjectUtil.defaultIfNull(modifyDbModel.getModifyUser(), userModel.getId()));
        }
    }
    // 
    Entity entity = this.dataBeanToEntity(info);
    // 
    entity.remove(StrUtil.format("`{}`", Const.ID_STR));
    // 
    Entity where = new Entity();
    where.set(Const.ID_STR, id);
    if (whereConsumer != null) {
        whereConsumer.accept(where);
    }
    int update = super.update(entity, where);
    // backtrack
    info.setCreateTimeMillis(createTimeMillis);
    return update;
}
Also used : UserModel(io.jpom.model.data.UserModel) Entity(cn.hutool.db.Entity) BaseUserModifyDbModel(io.jpom.model.BaseUserModifyDbModel)

Example 14 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class UserInfoController method updatePwd.

/**
 * 修改密码
 *
 * @param oldPwd 旧密码
 * @param newPwd 新密码
 * @return json
 */
@RequestMapping(value = "updatePwd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String updatePwd(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空") String oldPwd, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空") String newPwd) {
    Assert.state(!StrUtil.equals(oldPwd, newPwd), "新旧密码一致");
    UserModel userName = getUser();
    Assert.state(!userName.isDemoUser(), "当前账户为演示账号,不支持修改密码");
    try {
        UserModel userModel = userService.simpleLogin(userName.getId(), oldPwd);
        Assert.notNull(userModel, "旧密码不正确!");
        Assert.state(ObjectUtil.defaultIfNull(userModel.getPwdErrorCount(), 0) <= 0, "当前账号被锁定中,不能修改密码");
        userService.updatePwd(userName.getId(), newPwd);
        // 如果修改成功,则销毁会话
        getSession().invalidate();
        return JsonMessage.getString(200, "修改密码成功!");
    } catch (Exception e) {
        DefaultSystemLog.getLog().error(e.getMessage(), e);
        return JsonMessage.getString(500, "系统异常:" + e.getMessage());
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class UserListController method addUser.

/**
 * 编辑用户
 *
 * @param type 操作类型
 * @return String
 */
@PostMapping(value = "edit", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String addUser(String type) {
    // 
    boolean create = StrUtil.equals(type, "add");
    UserModel userModel = this.parseUser(create);
    if (create) {
        userService.insert(userModel);
    } else {
        UserModel model = userService.getByKey(userModel.getId());
        Assert.notNull(model, "不存在对应的用户");
        boolean systemUser = userModel.isSystemUser();
        if (!systemUser) {
            Assert.state(!model.isSuperSystemUser(), "不能取消超级管理员的权限");
        }
        UserModel optUser = getUser();
        if (StrUtil.equals(model.getId(), optUser.getId())) {
            Assert.state(optUser.isSuperSystemUser(), "不能修改自己的信息");
        }
        userService.update(userModel);
    }
    // 
    String workspace = getParameter("workspace");
    JSONArray jsonArray = JSONArray.parseArray(workspace);
    List<String> workspaceList = jsonArray.toJavaList(String.class);
    userBindWorkspaceService.updateUserWorkspace(userModel.getId(), workspaceList);
    return JsonMessage.getString(200, "操作成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) JSONArray(com.alibaba.fastjson.JSONArray) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

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