Exemplo n.º 1
0
  @CacheNameRemove(name = AppConstants.DEFAULT_CACHENAME)
  @Before({AdminValidator.UpdatePwdValidator.class, Tx.class})
  public void updatePwd() {
    keepModel(User.class);
    User user = getModel(User.class);
    HasherInfo passwordInfo = HasherUtils.me().hash(user.getStr("password"), Hasher.DEFAULT);
    user.set("password", passwordInfo.getHashResult());
    user.set("hasher", passwordInfo.getHasher().value());
    user.set("salt", passwordInfo.getSalt());

    if (user.update()) {
      setAttr("state", "success");
    } else setAttr("state", "failure");
    dynaRender("/view/admin/user.ftl");
  }
Exemplo n.º 2
0
  @Test
  public void testRegexpValidator() {
    deleteAndPopulateTables("users", "addresses");
    User u = new User();

    // test good value
    u.set("email", "*****@*****.**");
    u.validate();
    a(u.errors().size()).shouldBeEqual(0);

    // test bad value
    u.set("email", "this is not email value");
    u.validate();
    a(u.errors().size()).shouldBeEqual(1);
  }
Exemplo n.º 3
0
 @Before(UserInterceptor.class)
 public void setting() throws InterruptedException {
   String method = getRequest().getMethod();
   if (method.equalsIgnoreCase(Constants.GET)) {
     setAttr("save", getPara("save"));
     render("front/user/setting.ftl");
   } else if (method.equalsIgnoreCase(Constants.POST)) {
     User user = getSessionAttr(Constants.USER_SESSION);
     String url = getPara("url");
     String nickname = getPara("nickname");
     if (!user.getStr("nickname").equalsIgnoreCase(nickname)
         && User.me.findByNickname(nickname) != null) {
       error("此昵称已被注册,请更换昵称");
     } else {
       if (!StrUtil.isBlank(url)) {
         if (!url.substring(0, 7).equalsIgnoreCase("http://")) {
           url = "http://" + url;
         }
       }
       user.set("url", StrUtil.transHtml(url))
           .set("nickname", StrUtil.noHtml(nickname).trim())
           .set("signature", StrUtil.transHtml(getPara("signature")))
           .update();
       // 保存成功
       setSessionAttr(Constants.USER_SESSION, user);
       success();
     }
   }
 }
Exemplo n.º 4
0
  @CacheNameRemove(name = AppConstants.DEFAULT_CACHENAME)
  @Before({AdminValidator.deleteUserValidator.class, Tx.class})
  public void deleteUser() {
    keepModel(User.class);
    User user = getModel(User.class);

    if (user.getDate("deleted_at") != null) {
      user.set("deleted_at", new Date());
    } else {
      user.set("deleted_at", null);
    }

    if (user.update()) setAttr("state", "success");
    else setAttr("state", "failure");
    dynaRender("/view/admin/user.ftl");
  }
Exemplo n.º 5
0
 @Before(UserInterceptor.class)
 public void uploadAvatar() throws Exception {
   UploadFile uploadFile = getFile("avatar", Constants.UPLOAD_DIR_AVATAR);
   String path = "/static/upload/" + Constants.UPLOAD_DIR_AVATAR + "/" + uploadFile.getFileName();
   User user = (User) getSession().getAttribute(Constants.USER_SESSION);
   user.set("avatar", path).update();
   // 裁剪图片
   String realPath = Constants.UPLOAD_DIR + "/avatar/" + uploadFile.getFileName();
   ImageUtil.zoomImage(realPath, realPath, 100, 100);
   redirect("/user/setting");
 }
Exemplo n.º 6
0
  @Test
  public void testUniquenessValidator() {
    deleteAndPopulateTables("users", "addresses");
    // create a new user
    new User().set("email", "*****@*****.**").saveIt();

    // attempt creating another user with the same email
    User u = new User();
    u.set("email", "*****@*****.**").saveIt();
    a(u).shouldNotBe("valid");
    a(u.errors().get("email")).shouldBeEqual("This email is already taken.");
  }
Exemplo n.º 7
0
  @Test
  public void testSaveItMethod() {
    deleteAndPopulateTables("users", "addresses");
    final User u = new User();

    // cause exception
    u.set("email", "this is not email value");
    expect(
        new ExceptionExpectation(ValidationException.class) {
          public void exec() {
            u.saveIt();
          }
        });
  }
Exemplo n.º 8
0
 @Before(UserInterceptor.class)
 public void cancelBind() {
   String pt = getPara("pt");
   if (StrUtil.isBlank(pt)) {
     error("非法操作");
   } else {
     User user = (User) getSession().getAttribute(Constants.USER_SESSION);
     if (pt.equalsIgnoreCase(Constants.QQ)) {
       user.set("qq_open_id", null).set("qq_avatar", null).set("qq_nickname", null).update();
     } else if (pt.equalsIgnoreCase(Constants.SINA)) {
       user.set("sina_open_id", null).set("sina_avatar", null).set("sina_nickname", null).update();
     } /* else if(pt.equalsIgnoreCase(Constants.ThirdLogin.WECHAT)) {
           user.set("wechat_open_id", null)
                   .set("wechat_avatar", null)
                   .update();
       }*/
     setSessionAttr(Constants.USER_SESSION, user);
     setCookie(
         Constants.USER_COOKIE,
         StrUtil.getEncryptionToken(user.getStr("token")),
         30 * 24 * 60 * 60);
     success();
   }
 }