Ejemplo n.º 1
0
 public function update($request, $response, $args)
 {
     $id = $args['id'];
     $user = User::find($id);
     $user->email = $request->getParam('email');
     if ($request->getParam('pass') != '') {
         $user->pass = Hash::passwordHash($request->getParam('pass'));
     }
     if ($request->getParam('passwd') != '') {
         $user->passwd = $request->getParam('passwd');
     }
     $user->port = $request->getParam('port');
     $user->transfer_enable = Tools::toGB($request->getParam('transfer_enable'));
     $user->invite_num = $request->getParam('invite_num');
     $user->method = $request->getParam('method');
     $user->enable = $request->getParam('enable');
     $user->is_admin = $request->getParam('is_admin');
     $user->ref_by = $request->getParam('ref_by');
     if (!$user->save()) {
         $rs['ret'] = 0;
         $rs['msg'] = "修改失败";
         return $response->getBody()->write(json_encode($rs));
     }
     $rs['ret'] = 1;
     $rs['msg'] = "修改成功";
     return $response->getBody()->write(json_encode($rs));
 }
Ejemplo n.º 2
0
 public function createAdmin()
 {
     echo "add admin/ 创建管理员帐号.....";
     // ask for input
     fwrite(STDOUT, "Enter your email/输入管理员邮箱: ");
     // get input
     $email = trim(fgets(STDIN));
     // write input back
     fwrite(STDOUT, "Enter password for: {$email} / 为 {$email} 添加密码 ");
     $passwd = trim(fgets(STDIN));
     echo "Email: {$email}, Password: {$passwd}! ";
     fwrite(STDOUT, "Press [Y] to create admin..... 按下[Y]确认来确认创建管理员账户..... ");
     $y = trim(fgets(STDIN));
     if (strtolower($y) == "y") {
         echo "start create admin account";
         // create admin user
         // do reg user
         $user = new User();
         $user->user_name = "admin";
         $user->email = $email;
         $user->pass = Hash::passwordHash($passwd);
         $user->passwd = Tools::genRandomChar(6);
         $user->port = Tools::getLastPort() + 1;
         $user->t = 0;
         $user->u = 0;
         $user->d = 0;
         $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic'));
         $user->invite_num = Config::get('inviteNum');
         $user->ref_by = 0;
         $user->is_admin = 1;
         if ($user->save()) {
             echo "Successful/添加成功!";
             return true;
         }
         echo "添加失败";
         return false;
     }
     echo "cancel";
     return false;
 }
Ejemplo n.º 3
0
 public function registerHandle($request, $response, $args)
 {
     $name = $request->getParam('name');
     $email = $request->getParam('email');
     $email = strtolower($email);
     $passwd = $request->getParam('passwd');
     $repasswd = $request->getParam('repasswd');
     $code = $request->getParam('code');
     $verifycode = $request->getParam('verifycode');
     // check code
     $c = InviteCode::where('code', $code)->first();
     if ($c == null) {
         $res['ret'] = 0;
         $res['error_code'] = self::WrongCode;
         $res['msg'] = "邀请码无效";
         return $this->echoJson($response, $res);
     }
     // check email format
     if (!Check::isEmailLegal($email)) {
         $res['ret'] = 0;
         $res['error_code'] = self::IllegalEmail;
         $res['msg'] = "邮箱无效";
         return $this->echoJson($response, $res);
     }
     // check pwd length
     if (strlen($passwd) < 8) {
         $res['ret'] = 0;
         $res['error_code'] = self::PasswordTooShort;
         $res['msg'] = "密码太短";
         return $this->echoJson($response, $res);
     }
     // check pwd re
     if ($passwd != $repasswd) {
         $res['ret'] = 0;
         $res['error_code'] = self::PasswordNotEqual;
         $res['msg'] = "两次密码输入不符";
         return $this->echoJson($response, $res);
     }
     // check email
     $user = User::where('email', $email)->first();
     if ($user != null) {
         $res['ret'] = 0;
         $res['error_code'] = self::EmailUsed;
         $res['msg'] = "邮箱已经被注册了";
         return $this->echoJson($response, $res);
     }
     // verify email
     if (Config::get('emailVerifyEnabled') && !EmailVerify::checkVerifyCode($email, $verifycode)) {
         $res['ret'] = 0;
         $res['msg'] = '邮箱验证代码不正确';
         return $this->echoJson($response, $res);
     }
     // check ip limit
     $ip = Http::getClientIP();
     $ipRegCount = Check::getIpRegCount($ip);
     if ($ipRegCount >= Config::get('ipDayLimit')) {
         $res['ret'] = 0;
         $res['msg'] = '当前IP注册次数超过限制';
         return $this->echoJson($response, $res);
     }
     // do reg user
     $user = new User();
     $user->user_name = $name;
     $user->email = $email;
     $user->pass = Hash::passwordHash($passwd);
     $user->passwd = Tools::genRandomChar(6);
     $user->port = Tools::getLastPort() + 1;
     $user->t = 0;
     $user->u = 0;
     $user->d = 0;
     $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic'));
     $user->invite_num = Config::get('inviteNum');
     $user->reg_ip = Http::getClientIP();
     $user->ref_by = $c->user_id;
     if ($user->save()) {
         $res['ret'] = 1;
         $res['msg'] = "注册成功";
         $c->delete();
         return $this->echoJson($response, $res);
     }
     $res['ret'] = 0;
     $res['msg'] = "未知错误";
     return $this->echoJson($response, $res);
 }
Ejemplo n.º 4
0
 public function registerHandle($request, $response, $next)
 {
     $name = $request->getParam('name');
     $email = $request->getParam('email');
     $email = strtolower($email);
     $passwd = $request->getParam('passwd');
     $repasswd = $request->getParam('repasswd');
     $code = $request->getParam('code');
     // check code
     $c = InviteCode::where('code', $code)->first();
     if ($c == null) {
         $res['ret'] = 0;
         $res['msg'] = "邀请码无效";
         return $response->getBody()->write(json_encode($res));
     }
     // check email format
     if (!Check::isEmailLegal($email)) {
         $res['ret'] = 0;
         $res['msg'] = "邮箱无效";
         return $response->getBody()->write(json_encode($res));
     }
     // check pwd length
     if (strlen($passwd) < 8) {
         $res['ret'] = 0;
         $res['msg'] = "密码太短";
         return $response->getBody()->write(json_encode($res));
     }
     // check pwd re
     if ($passwd != $repasswd) {
         $res['ret'] = 0;
         $res['msg'] = "两次密码输入不符";
         return $response->getBody()->write(json_encode($res));
     }
     // check email
     $user = User::where('email', $email)->first();
     if ($user != null) {
         $res['ret'] = 0;
         $res['msg'] = "邮箱已经被注册了";
         return $response->getBody()->write(json_encode($res));
     }
     // do reg user
     $user = new User();
     $user->user_name = $name;
     $user->email = $email;
     $user->pass = Hash::passwordHash($passwd);
     $user->passwd = Tools::genRandomChar(6);
     $user->port = Tools::getLastPort() + 1;
     $user->t = 0;
     $user->u = 0;
     $user->d = 0;
     $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic'));
     $user->invite_num = Config::get('inviteNum');
     $user->ref_by = $c->user_id;
     if ($user->save()) {
         $res['ret'] = 1;
         $res['msg'] = "注册成功";
         $c->delete();
         return $response->getBody()->write(json_encode($res));
     }
     $res['ret'] = 0;
     $res['msg'] = "未知错误";
     return $response->getBody()->write(json_encode($res));
 }