コード例 #1
0
ファイル: UserModule.java プロジェクト: taoguan/nutztb
 @Filters(@By(type = AjaxCheckSession.class, args = "me"))
 @At("/update")
 public Object updateInfo(
     String nickName, String passwd, @Attr("me") User me, HttpSession session) {
   if (!Strings.isBlank(nickName)
       && !nickName.startsWith("_") // 系统默认生成的nickName以_开头
       && me.getNickName().startsWith("_") // 只允许修改一次nickName
       && nickName.trim().length() > 1
       && nickName.trim().length() < 10
       && nickName.indexOf("<") < 0
       && nickName.indexOf(">") < 0
       && nickName.indexOf("@") < 0
       && nickName.indexOf("#") < 0
       && nickName.indexOf(" ") < 0
       && nickName.indexOf("&") < 0) {
     try {
       dao.update(
           User.class, Chain.make("nickName", nickName.trim()), Cnd.where("id", "=", me.getId()));
     } catch (Throwable e) {
       return Ajax.fail().setMsg("Nickname is dup or it is BAD!");
     }
   }
   if (!Strings.isBlank(passwd) && passwd.trim().length() > 5 && passwd.trim().length() < 40) {
     dao.update(
         User.class, Chain.make("passwd", xMD5(passwd.trim())), Cnd.where("id", "=", me.getId()));
   }
   session.setAttribute("me", dao.fetch(User.class, Cnd.where("id", "=", me.getId())));
   return Ajax.ok();
 }
コード例 #2
0
  @Override
  public void init(NutConfig config) {
    Ioc ioc = config.getIoc();
    Dao dao = ioc.get(Dao.class);

    // 若必要的数据表不存在,则初始化数据库
    if (!dao.exists(User.class)) {
      dao.create(User.class, true);
      dao.create(Role.class, true);
      dao.create(Permission.class, true);
      FileSqlManager fm = new FileSqlManager("init_system_h2.sql");
      List<Sql> sqlList = fm.createCombo(fm.keys());
      dao.execute(sqlList.toArray(new Sql[sqlList.size()]));
      // 初始化用户密码(全部都是123)及salt
      List<User> userList = dao.query(User.class, null);
      for (User user : userList) {
        RandomNumberGenerator rng = new SecureRandomNumberGenerator();
        String salt = rng.nextBytes().toBase64();
        String hashedPasswordBase64 = new Sha256Hash("123", salt, 1024).toBase64();
        user.setSalt(salt);
        user.setPassword(hashedPasswordBase64);
        dao.update(user);
      }
    }

    // 设置 Shiro 的 securityManager
    SecurityManager securityManager = ioc.get(SecurityManager.class);
    SecurityUtils.setSecurityManager(securityManager);
  }
コード例 #3
0
  public void confirm(ActionEvent event) {
    String name = nameField.getText();
    if (S.isEmpty(name)) {
      tipsLabel.setText("错误:工具名字不能为空!");
      nameField.requestFocus();
      return;
    }
    String command = commandText.getText();
    String order = orderField.getText();
    ToolsTray bandeja = (ToolsTray) parentCombo.getSelectionModel().getSelectedItem();
    Integer parentId = bandeja.getId();
    ToolType toolType = (ToolType) typeCombo.getSelectionModel().getSelectedItem();
    String type = toolType.getToolType();

    ToolsTray toolsTray = new ToolsTray();
    toolsTray.setTrayName(name);
    toolsTray.setCommand(command);
    toolsTray.setParentId(parentId);
    toolsTray.setToolOrder(order);
    toolsTray.setToolType(type);
    if (null == id) {
      dao.insert(toolsTray);
      id = toolsTray.getId();
      tipsLabel.setText("添加成功:" + name);
    } else {
      toolsTray.setId(id);
      dao.update(toolsTray);
      tipsLabel.setText("更新成功:" + name);
    }
    refresh(null);
  }
コード例 #4
0
 @Aop("redis")
 public boolean updateTags(String topicId, @Param("tags") Set<String> tags) {
   if (Strings.isBlank(topicId) || tags == null) {
     return false;
   }
   Topic topic = dao.fetch(Topic.class, topicId);
   if (topic == null) return false;
   Set<String> oldTags = topic.getTags();
   if (oldTags == null) oldTags = new HashSet<>();
   log.debugf("update from '%s' to '%s'", oldTags, tags);
   topic.setTags(tags);
   dao.update(topic, "tags");
   Set<String> newTags = new HashSet<>(tags);
   newTags.removeAll(oldTags);
   Set<String> removeTags = new HashSet<>(oldTags);
   ;
   removeTags.remove(tags);
   fillTopic(topic, null);
   Date lastReplyTime = topic.getCreateTime();
   if (topic.getLastComment() != null) lastReplyTime = topic.getLastComment().getCreateTime();
   Pipeline pipe = jedis().pipelined();
   for (String tag : removeTags) {
     pipe.zrem(RKEY_TOPIC_TAG + tag.toLowerCase().trim(), topic.getId());
     pipe.zincrby(RKEY_TOPIC_TAG_COUNT, -1, tag.toLowerCase().trim());
   }
   for (String tag : newTags) {
     pipe.zadd(RKEY_TOPIC_TAG + tag.toLowerCase().trim(), lastReplyTime.getTime(), topic.getId());
     pipe.zincrby(RKEY_TOPIC_TAG_COUNT, 1, tag.toLowerCase().trim());
   }
   pipe.sync();
   return true;
 }
コード例 #5
0
ファイル: StoreCtrl.java プロジェクト: kangqbing/koo
 @At
 @Ok("json")
 @AdaptBy(type = JsonAdaptor.class)
 public Object update(
     @Param("..") Store store, @Attr(scope = Scope.SESSION, value = "account") Account acc) {
   dao.update(store);
   return store;
 }
コード例 #6
0
ファイル: UserModule.java プロジェクト: taoguan/nutztb
 @At("/passwd/reset/callback")
 public Object resetPasswdCallback(String token) {
   PasswordReset reset = dao.fetch(PasswordReset.class, Cnd.where("token", "=", token));
   if (reset != null) {
     dao.clear(PasswordReset.class, Cnd.where("token", "=", token));
     if (System.currentTimeMillis() - reset.getCreateTime().getTime() > 30 * 60 * 1000)
       return Ajax.fail().setMsg("token is expise");
     String passwd = R.sg(12).next();
     dao.update(
         User.class, Chain.make("passwd", xMD5(passwd)), Cnd.where("id", "=", reset.getUid()));
     String email = dao.fetch(User.class, Cnd.where("id", "=", reset.getUid())).getEmail();
     mailService.add2Queue(email, "推爸密码重置邮件", "Your password : "******"Reset success!! Check you email!");
   }
   return Ajax.fail().setMsg("Token not found!!");
 }
コード例 #7
0
  @SuppressWarnings("serial")
  public void init(NutConfig nc) {
    NutShiro.DefaultLoginURL = "/admin/logout";
    // 检查环境
    if (!Charset.defaultCharset().name().equalsIgnoreCase(Encoding.UTF8)) {
      log.warn("This project must run in UTF-8, pls add -Dfile.encoding=UTF-8 to JAVA_OPTS");
    }

    // 获取Ioc容器及Dao对象
    Ioc ioc = nc.getIoc();
    // 加载freemarker自定义标签 自定义宏路径
    ioc.get(Configuration.class)
        .setAutoImports(
            new HashMap<String, String>(2) {
              {
                put("p", "/ftl/pony/index.ftl");
                put("s", "/ftl/spring.ftl");
              }
            });
    ioc.get(FreeMarkerConfigurer.class, "mapTags");
    Dao dao = ioc.get(Dao.class);

    // 为全部标注了@Table的bean建表
    Daos.createTablesInPackage(dao, getClass().getPackage().getName() + ".bean", false);

    // 获取配置对象
    PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");

    // 初始化SysLog,触发全局系统日志初始化
    ioc.get(SysLogService.class);

    // 初始化默认根用户
    User admin = dao.fetch(User.class, "admin");
    if (admin == null) {
      UserService us = ioc.get(UserService.class);
      admin = us.add("admin", "123456");
    }
    // 初始化游客用户
    User guest = dao.fetch(User.class, "guest");
    if (guest == null) {
      UserService us = ioc.get(UserService.class);
      guest = us.add("guest", "123456");
      UserProfile profile = dao.fetch(UserProfile.class, guest.getId());
      profile.setNickname("游客");
      dao.update(profile, "nickname");
    }

    // 获取NutQuartzCronJobFactory从而触发计划任务的初始化与启动
    ioc.get(NutQuartzCronJobFactory.class);

    // 权限系统初始化
    AuthorityService as = ioc.get(AuthorityService.class);
    as.initFormPackage("net.wendal.nutzbook");
    as.checkBasicRoles(admin);

    // 检查一下Ehcache CacheManager 是否正常.
    CacheManager cacheManager = ioc.get(CacheManager.class);
    log.debug("Ehcache CacheManager = " + cacheManager);
    // CachedNutDaoExecutor.DEBUG = true;

    // 启用FastClass执行入口方法
    Mvcs.disableFastClassInvoker = false;

    // 设置Markdown缓存
    if (cacheManager.getCache("markdown") == null) cacheManager.addCache("markdown");
    Markdowns.cache = cacheManager.getCache("markdown");
    if (conf.getBoolean("cdn.enable", false) && !Strings.isBlank(conf.get("cdn.urlbase"))) {
      MarkdownFunction.cdnbase = conf.get("cdn.urlbase");
    }
  }
コード例 #8
0
ファイル: ItemDaoImpl.java プロジェクト: bosen365/mz-g
 @Override
 public void update(Item i) {
   dao.update(i);
 }