public function debug($request, $response, $args) { $server = ["headers" => $request->getHeaders(), "content_type" => $request->getContentType()]; $res = ["server_info" => $server, "ip" => Http::getClientIP(), "version" => Config::get('version'), "reg_count" => Check::getIpRegCount(Http::getClientIP())]; Logger::debug(json_encode($res)); return $this->echoJson($response, $res); }
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); }
public function debug($request, $response, $args) { $res = ["ip" => Http::getClientIP(), "version" => Config::get('version')]; Logger::debug(json_encode($res)); return $this->echoJson($response, $res); }