예제 #1
0
 public function getIndex(Request $request)
 {
     $data = [];
     $userControllerObj = new UserController();
     $cookie = $userControllerObj->checkCookie($request);
     $data['categories'] = Categories::getCategories();
     if ($cookie === 0) {
         return View::make('index', $data);
     } else {
         if ($cookie === -1) {
             $response = new Response('Your cookie is invalid, We have cleared it for you, Refresh to re-login to NEUP-Channel');
             return $response->withCookie('neupchan', "", -1);
         } else {
             if ($cookie->shortCookie === NULL) {
                 $shortCookie = $cookie->short_cookie;
                 $data['firstLogin'] = true;
             } else {
                 $shortCookie = $cookie->shortCookie;
                 $data['lastLoginIP'] = $cookie->last_login_ip;
             }
         }
     }
     $data['shortCookie'] = $shortCookie;
     //return View::make('index', $data)->withCookie(cookie('neupchan', $cookie, 90 * 24 * 60));
     $response = new Response(view('index', $data));
     if (isset($data['firstLogin'])) {
         return $response->withCookie('neupchan', $cookie, 90 * 24 * 60);
     } else {
         return $response;
     }
 }
 /**
  * Add the RateLimit to the response cookies.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Illuminate\Http\Response $response
  * @return \Illuminate\Http\Response
  */
 protected function addRateLimitToResponse($request, $response, $limit)
 {
     $throttle = $this->throttle->get($request);
     $response->header('x-rate-limit-limit', $limit);
     $response->header('x-rate-limit-remaining', $limit - $throttle->count());
     return $response;
 }
예제 #3
0
 /**
  * [nextDate description]
  * @return [type] [description]
  */
 public function setVisitor(Request $request)
 {
     // Fetch cookie
     $cvuid_val = $request->cookie('CVUID');
     // Check if cookie exists
     if (isset($cvuid_val)) {
         $u = Visitor::where('session', '=', $cvuid_val)->first();
         // Check if user is alive
         if ($u != Null && $u->count() > 0) {
             $uid = $cvuid_val;
             $u->touch();
             //touch user to keep alive
         } else {
             // Create new user cause seems dead
             $uid = uniqid('_csnvaka', true);
             $v = new Visitor();
             $v->session = $uid;
             $v->save();
         }
     } else {
         // Create new user, cause totaly new :)
         $uid = uniqid('_csnvaka', true);
         $v = new Visitor();
         $v->session = $uid;
         $v->save();
     }
     // Create response with cookie
     $response = new Response($uid);
     $response->withCookie(cookie('CVUID', $uid, 720));
     return $response;
 }
 public function handle($request, Closure $next)
 {
     $response = new Response();
     if (Auth::check() === false) {
         $request->request->set('roleId', $this->retrieveRoleIdByName('Customer'));
         return $next($request);
     }
     $user = Auth::user();
     if ($user === null) {
         $response->header(Constants::RESPONSE_HEADER, "Failed to retrieve authenticated user.");
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
         return $response;
     }
     $role = Roles::where('id', $user->role_id)->firstOrFail();
     if ($role->name !== "Administrator") {
         $response->header(Constants::RESPONSE_HEADER, "Permission are required for performing registration operation.");
         $response->setStatusCode(Response::HTTP_FORBIDDEN);
         return $response;
     }
     try {
         $roleName = $request->get('roleName');
         if ($roleName === null) {
             $request->request->set('roleId', $this->retrieveRoleIdByName('Customer'));
         } else {
             $request->request->set('roleId', $this->retrieveRoleIdByName($roleName));
         }
     } catch (Exception $exception) {
         $response->header(Constants::RESPONSE_HEADER, $exception->getMessage());
         $response->setStatusCode(Response::HTTP_BAD_REQUEST);
         return $response;
     }
     return $next($request);
 }
예제 #5
0
 /**
  * Render an exception into a response.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception $exception
  * @return \Illuminate\Http\Response
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function render($request, Exception $exception)
 {
     $response = (new SymfonyExceptionHandler(env('APP_DEBUG', false)))->createResponse($exception);
     $response = new Response($response->getContent(), $response->getStatusCode(), $response->headers->all());
     $response->exception = $exception;
     return $response;
 }
예제 #6
0
 /**
  * Preparing Response
  *
  * @return Response
  */
 protected function setResponse()
 {
     $response = new Response();
     $response->setStatusCode($this->content['http_code']);
     $response->setContent($this->content);
     return $response;
 }
 /**
  * Deletes members funds and recalculates total
  *
  * @param $incomeServiceId
  * @param $memberId
  * @return \Illuminate\Http\JsonResponse
  */
 public function deleteMemberFund($incomeServiceId, $memberId, Response $response, Gate $gate)
 {
     if (!$gate->check('putPostDelete', new IncomeServiceMemberFund())) {
         return $response->setContent('Unauthorized')->setStatusCode(401);
     }
     return response()->json($this->dispatch(new DeleteIncomeServiceMemberFundTotal($incomeServiceId, $memberId)));
 }
예제 #8
0
 public function postRegister(Request $request)
 {
     $errors = [];
     // Validate all fields have been received.
     $validator = \Validator::make($request->all(), array('email' => 'required|email|max:128|unique:users,email', 'username' => 'required|min:1|max:20|unique:users,name', 'password' => 'required|min:6|max:255', 'g-recaptcha-response' => 'recaptcha'));
     if ($validator->fails()) {
         // Validator detected some problems.
         foreach ($validator->errors()->getMessages() as $error) {
             $errors[] = $error;
         }
     }
     if (count($errors) > 0) {
         // Errors detected, generate response
         $response = new Response(json_encode(['status' => false, 'errors' => $errors]), 200);
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     // Get input
     $email = $request->input('email');
     $username = $request->input('username');
     $password = $request->input('password');
     // Register user
     $user = User::register($email, $username, $password);
     // Login
     Auth::login($user);
     // Generate response
     $response = new Response(json_encode(['status' => true]), 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
예제 #9
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function saveUser(Response $response, Request $request)
 {
     $despo = new Valentine();
     $Userexists = Valentine::getExistingUser($request->input('id'));
     if (is_object($Userexists)) {
         if (!is_null($Userexists->interests)) {
             $response->setContent('/findlove');
             $response->withCookie(cookie()->forever('shy_first_college', $Userexists->college));
         } else {
             $response->setContent('/profile/complete');
         }
         $response->withCookie(cookie()->forever('shy_first_id', $Userexists->id));
         $response->withCookie(cookie()->forever('shy_first_sex', $Userexists->sex));
     } else {
         $despo->name = $request->input('name');
         $despo->age = $request->input('birthday', '');
         $despo->sex = $request->input('gender');
         $despo->userId = $request->input('id');
         $despo->tel = $request->input('name');
         $despo->social = $request->input('social');
         $despo->url = $request->input('link');
         $despo->email = $request->input('email');
         if ($despo->save()) {
             $response->setContent('/profile/complete');
             $response->withCookie(cookie()->forever('shy_first_id', $despo->id));
             $response->withCookie(cookie()->forever('shy_first_sex', $request->input('sex')));
         }
     }
     return $response;
 }
예제 #10
0
 public function responseFactory($content, $code = 200)
 {
     $response = new Response();
     $response->setContent($content);
     $response->setStatusCode($code);
     return $response;
 }
예제 #11
0
 public function put(Route $route, Request $request, Response $response)
 {
     $key = $this->makeCacheKey($request->url());
     if (!Cache::has($key)) {
         Cache::put($key, $response->getContent(), 10);
     }
 }
 /**
  * Serialize a response.
  *
  * @param \Illuminate\Http\Response $response
  *
  * @return string
  */
 public function serialize(Response $response)
 {
     $content = $response->getContent();
     $statusCode = $response->getStatusCode();
     $headers = $response->headers;
     return serialize(compact('content', 'statusCode', 'headers'));
 }
 /**
  * Create new Income Service
  *
  * @param IncomeServiceRequest $request
  * @param Guard $guard
  * @param Response $response
  * @param Gate $gate
  * @return ItemResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function store(IncomeServiceRequest $request, Guard $guard, Response $response, Gate $gate)
 {
     if (!$gate->check('putPostDelete', new IncomeService())) {
         return $response->setContent('Unauthorized')->setStatusCode(401);
     }
     return new ItemResponse($this->dispatch(new CreateIncomeServiceCommand($request->get('service_id'), $request->get('service_date'), $guard->user()->id, 3, 'status')));
 }
 /**
  * @param \Illuminate\Http\Response $response
  *
  * @return $this
  */
 protected function addCookieConsentScriptToResponse(Response $response)
 {
     $content = $response->getContent();
     $closingBodyTagPosition = $this->getLastClosingBodyTagPosition($content);
     $content = '' . substr($content, 0, $closingBodyTagPosition) . view('cookieConsent::index')->render() . substr($content, $closingBodyTagPosition);
     return $response->setContent($content);
 }
예제 #15
0
    /**
     * Append disqus script on the end of the page.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Illuminate\Http\Response $response
     * @return mixed
     */
    protected function appendDisqusScript($request, $response)
    {
        $content = $response->getContent();
        if (!Str::contains($content, '<div id="disqus_thread"></div>')) {
            return;
        }
        $uri = $request->getRequestUri();
        $pageUrl = url($uri);
        $pageId = 'route' . implode('.', explode('/', $uri));
        $username = config('disqus.username');
        $disqusHtml = <<<CDATA
<script>
     var disqus_config = function () {
         this.page.url = '{$pageUrl}';
         this.page.identifier = '{$pageId}';
     };

    (function() {  // DON'T EDIT BELOW THIS LINE
        var d = document, s = d.createElement('script');

        s.src = '//{$username}.disqus.com/embed.js';

        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href=\\"https://disqus.com/?ref_noscript\\" rel=\\"nofollow\\">comments powered by Disqus.</a></noscript>
CDATA;
        $bodyPosition = strripos($content, '</body>');
        if (false !== $bodyPosition) {
            $content = substr($content, 0, $bodyPosition) . $disqusHtml . substr($content, $bodyPosition);
        }
        $response->setContent($content);
    }
 public function store()
 {
     $preferences = Request::all();
     $response = new Response('OK');
     $response->withCookie(Cookie::forever(PreferencesVO::PREFERENCES_AMOUNT, $preferences['amount'], PreferencesVO::PREFERENCES_LIFESPAN))->withCookie(Cookie::forever(PreferencesVO::PREFERENCES_PERIOD, $preferences['period'], PreferencesVO::PREFERENCES_LIFESPAN))->withCookie(Cookie::forever(PreferencesVO::PREFERENCES_TAXCDB, $preferences['taxcdb'], PreferencesVO::PREFERENCES_LIFESPAN))->withCookie(Cookie::forever(PreferencesVO::PREFERENCES_TAXLCI, $preferences['taxlci'], PreferencesVO::PREFERENCES_LIFESPAN));
     return $response;
 }
예제 #17
0
 /**
  * Cache the response 1 year (31536000 sec)
  */
 protected function cacheResponse(Response $response)
 {
     $response->setSharedMaxAge(31536000);
     $response->setMaxAge(31536000);
     $response->setExpires(new \DateTime('+1 year'));
     return $response;
 }
예제 #18
0
 /**
  * New thread (not the create thread page)
  * @param Request $request
  * @return string
  */
 public function newThread(Request $request)
 {
     // Validate input
     $this->validate($request, ['title' => 'required|max:255', 'forum' => 'required|numeric', 'body' => 'required|max:30000']);
     // Verify forum is a valid forum that can be posted in
     $forum = null;
     try {
         $forum = Forum::findOrFail($request->input('forum'));
     } catch (ModelNotFoundException $e) {
         abort(400);
         // 400 Bad Request - invalid forum id
     }
     if ($forum->type != 0) {
         abort(400);
         // 400 Bad Request - not correct forum type
     }
     // Create thread
     $thread = Thread::newThread($request->input('title'), $request->input('forum'));
     // Create opening post
     $post = post::newPost($request->input('body'), $thread->id);
     // Generate response
     $resp = new Response(json_encode(['status' => true, 'link' => $thread->getUserFriendlyURL()]), 200);
     $resp->header('Content-Type', 'application/json');
     return $resp;
 }
예제 #19
0
 private function setViewWithDR($view)
 {
     $response = new Response($view->with('dr', $this->dr));
     $response->withCookie(cookie('to', $this->dr->to->format('Y-m-d'), 45000));
     $response->withCookie(cookie('fr', $this->dr->fr->format('Y-m-d'), 45000));
     $response->withCookie(cookie('date', $this->dr->date->format('Y-m-d'), 45000));
     return $response;
 }
예제 #20
0
 public function createCookie(Request $request)
 {
     // create .seeties.me token Cookie
     $token = 'JDJ5JDEwJFdDdGRLLlo4OWRCeDlMMTEyUTFtbXVPUDNBN3kxV1VNQ0NEdC9ORXp6WmtSRWkwOTd5WGwy';
     $cookie = \Cookie::make('token', $token, 60, null, env('COOKIE_DOMAIN'));
     $response = new Response('Hello world');
     return $response->withCookie($cookie);
 }
 public function get_captcha_image()
 {
     $fname = Input::get('fname');
     $content = file_get_contents($fname);
     $response = new Response($content, 200);
     $response->header('Content-Type', "image/png");
     return $response;
 }
예제 #22
0
 public function getQr(Request $req)
 {
     $qrCode = new QrCode();
     $qrCode->setText("http://10.0.20.55:8001/index/wel#/sys/activities/one")->setSize(300)->setPadding(10)->setErrorCorrection('high')->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0));
     $response = new Response($qrCode->get(), 200);
     $response->header('content-type', 'image/png');
     return $response;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $currentUserRoles = $this->grantedRoles();
     if (!$this->isAuthorized($currentUserRoles)) {
         return $this->response->setContent('Unauthorized')->setStatusCode(401);
     }
     return $next($request);
 }
예제 #24
0
 public function create(Request $request)
 {
     $val = Url::saveUrl($request);
     $path = route('short_url', array('short' => $val->getAttribute('short')));
     $resp = new Response();
     $resp->setContent($path);
     return $resp;
 }
예제 #25
0
 /**
  * Attempt to create local response type from guzzle response
  *
  * @param  GuzzleResponse $guzzleResponse
  *
  * @return Response
  */
 protected static function createLocalResponse(GuzzleResponse $guzzleResponse)
 {
     $response = new Response($guzzleResponse->getBody(), $guzzleResponse->getStatusCode());
     $headers = $guzzleResponse->getHeaders();
     array_walk($headers, function ($values, $name) use($response) {
         $response->header($name, implode(', ', $values), true);
     });
     return $response;
 }
예제 #26
0
파일: Response.php 프로젝트: nodes-php/api
 /**
  * Make an API response from an existing response object.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param  \Illuminate\Http\Response $old
  * @return \Nodes\Api\Http\Response
  */
 public static function makeFromExisting(IlluminateResponse $old)
 {
     // Support for custom status code and message
     $statusCode = $old instanceof self ? $old->getStatusCodeAndMessage() : $old->getStatusCode();
     // Generate API response from response object
     $new = static::create($old->getOriginalContent(), $statusCode);
     $new->headers = $old->headers;
     return $new;
 }
예제 #27
0
 /**
  * 获取Cookie
  */
 public function getAddCookie()
 {
     $response = new Response();
     //第一个参数是cookie名,第二个参数是cookie值,第三个参数是有效期(分钟)
     $response->withCookie(cookie('website', 'LaravelAcademy.org', 1));
     //如果想要cookie长期有效使用如下方法
     //$response->withCookie(cookie()->forever('name', 'value'));
     return $response;
 }
예제 #28
0
 /**
  * Add content security policy headers to response.
  *
  * @return void
  *
  * @throws \Exception
  */
 protected function buildCsp()
 {
     if ($this->response instanceof BinaryFileResponse) {
         return;
     }
     $csp = CSPBuilder::fromFile(config_path('csp.json'));
     $csp->addDirective('upgrade-insecure-requests', $this->request->secure());
     $this->response->withHeaders($csp->getHeaderArray(false));
 }
예제 #29
0
 /**
  * Convert document to JSON-API string, return as a Laravel Response.
  * @param Document $responseDocument
  * @return Response
  */
 public function serialize(Document $responseDocument)
 {
     $response = new Response();
     $jsonDocument = $this->formatDocument($responseDocument);
     $response->setContent($this->encodeJson($jsonDocument));
     // Add other headers
     $responseDocument->headers = array_merge($responseDocument->headers, ['Content-Type' => JsonApi::MIME_TYPE]);
     $response->headers->add($responseDocument->headers);
     return $response;
 }
 protected function makeMessageFromResponse(Response $response)
 {
     $message['original_content'] = $response->getOriginalContent();
     $message['content'] = $response->getContent();
     $message['status_code'] = $response->getStatusCode();
     return json_encode($message, JSON_PRETTY_PRINT);
 }