コード例 #1
0
ファイル: Toolkit.java プロジェクト: withoutdelay/MyNutzbook
 public static String randomPasswd(User usr) {
   String passwd = R.sg(10).next();
   String slat = R.sg(48).next();
   usr.setSalt(slat);
   usr.setPassword(passwordEncode(passwd, slat));
   return passwd;
 }
コード例 #2
0
ファイル: UserModule.java プロジェクト: taoguan/nutztb
 @At("/passwd/reset")
 public void resetPassword(String email, HttpServletRequest req) {
   if (Strings.isBlank(email)) return;
   User user = dao.fetch(User.class, Cnd.where("email", "=", email));
   if (user == null) return;
   dao.clear(PasswordReset.class, Cnd.where("uid", "=", user.getId()));
   String token = R.UU64() + R.UU64();
   PasswordReset reset = new PasswordReset();
   reset.setUid(dao.fetch(User.class, Cnd.where("email", "=", email)).getId());
   reset.setToken(token);
   dao.insert(reset);
   String url = req.getRequestURL() + "/callback?token=" + token;
   mailService.add2Queue(email, "推爸 密码重置请求", "Reset URL --> " + url);
 }
コード例 #3
0
 @Aop("redis")
 public String accessToken(UserProfile profile) {
   String loginname = profile.getLoginname();
   String at = jedis().hget(RKEY_USER_ACCESSTOKEN, loginname);
   if (at == null) {
     // 双向绑定
     at = R.UU32();
     jedis().hset(RKEY_USER_ACCESSTOKEN, loginname, at);
     jedis().hset(RKEY_USER_ACCESSTOKEN2, at, loginname);
     jedis().hset(RKEY_USER_ACCESSTOKEN3, at, "" + profile.getUserId());
   }
   return at;
 }
コード例 #4
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!!");
 }
コード例 #5
0
 @OnEvent("get_auth_qr")
 public void getAuthQr(SocketIOClient client, Object data, AckRequest ackRequest) {
   NutMap re = new NutMap();
   try {
     // TODO 可配置
     SeckenResp resp =
         secken
             .getAuth(1, "https://nutz.cn/secken/callback/" + R.UU32(client.getSessionId()))
             .check();
     String url = resp.qrcode_url();
     re.put("ok", true);
     re.put("url", url);
   } catch (Exception e) {
     log.debug("获取洋葱授权二维码识别", e);
     re.put("msg", "获取洋葱授权二维码识别");
   }
   client.sendEvent("new_auth_qr", re);
 }
コード例 #6
0
 public NutMap upload(TempFile tmp, int userId) throws IOException {
   NutMap re = new NutMap();
   if (userId < 1) return re.setv("msg", "请先登陆!");
   if (tmp == null || tmp.getSize() == 0) {
     return re.setv("msg", "空文件");
   }
   if (tmp.getSize() > 10 * 1024 * 1024) {
     tmp.delete();
     return re.setv("msg", "文件太大了");
   }
   String id = R.UU32();
   String path = "/" + id.substring(0, 2) + "/" + id.substring(2);
   File f = new File(imageDir + path);
   Files.createNewFile(f);
   Files.write(f, tmp.getInputStream());
   tmp.delete();
   re.put("url", Mvcs.getServletContext().getContextPath() + "/yvr/upload" + path);
   re.setv("success", true);
   return re;
 }
コード例 #7
0
ファイル: UserModule.java プロジェクト: taoguan/nutztb
 @At
 public Object reg(@Param("email") String email) {
   if (Strings.isBlank(email) || !Strings.isEmail(email)) {
     return Ajax.fail().setMsg("email is blank or invaild!");
   } else {
     if (0 != dao.count(User.class, Cnd.where("email", "=", email))) {
       return Ajax.fail().setMsg("email is exist!");
     } else {
       final User me = new User();
       me.setEmail(email);
       String passwd = R.sg(12).next();
       me.setPasswd(xMD5(passwd));
       me.setNickName("_" + me.getNickName());
       dao.insert(me);
       if (mailService.add2Queue(email, "推爸注册确认邮件", "Your password : "******"Fail to send comfig email!!");
       }
     }
   }
 }