示例#1
0
 private boolean setUsername(String username, UsrAccount account) {
   boolean isEmail = emailValidator.isValid(username, null);
   if (isEmail) {
     account.setEmail(username);
     return true;
   }
   boolean isQQ =
       StringUtils.isNumeric(username) && (username.length() >= 5 && username.length() <= 10);
   if (isQQ) {
     account.setQq(username);
     return true;
   }
   boolean isTel = StringUtils.isNumeric(username) && (username.length() == 11);
   if (isTel) {
     account.setTel(username);
     return true;
   }
   return false;
 }
示例#2
0
 @RequestMapping("/submit.json")
 @ResponseBody
 public ActionResult register(@RequestBody RegParam param) {
   UsrAccount account = userService.findAccount(param.getUsername());
   if (account != null) {
     return ActionResult.errorResult("用户名" + param.getUsername() + "已存在。");
   }
   account = new UsrAccount();
   account.setAttrs("{}");
   boolean username = setUsername(param.getUsername(), account);
   if (username == false) {
     return ActionResult.errorResult("用户名不合规范,可以选择的有邮箱带@和后缀,QQ或手机号码。");
   }
   account.setRegisterTime(new Timestamp(System.currentTimeMillis()));
   userDao.persist(UsrAccount.class, account);
   UUID uuid = account.getAccountId();
   String encoded = userService.encodePassword(uuid.toString(), param.getPassword());
   account.setPwd(encoded);
   userDao.update(account);
   return ActionResult.successResult();
 }