function it_fails_with_string(Encrypter $encrypter, Request $request)
 {
     $time = date("Y-m-d H:i:s", strtotime("30 seconds ago"));
     $request->get('_guard_opened')->willReturn($time);
     $encrypter->decrypt($time)->willReturn($time);
     $this->validate($request)->shouldReturn(false);
 }
 function it_returns_the_timer_html(Encrypter $encrypter)
 {
     $time = time();
     $encrypter->encrypt($time)->willReturn($time);
     $html = (require __DIR__ . "/../../../src/Html/templates/timer.php");
     $this->html()->shouldReturn($html);
 }
Пример #3
0
 /**
  * The data that is needed in the view
  *
  * @return mixed
  */
 public function getData()
 {
     $params = ['project' => $this->user->pivot->project_id, 'user' => $this->user->id];
     $userHash = $this->encrypter->encrypt($params);
     $url = env('BASE_URL', 'http://knoters.com') . '/editor/' . $userHash;
     return ['url' => $url];
 }
 /**
  * Handle the command.
  *
  * @param Repository $config
  * @param Encrypter  $encrypter
  * @return string
  */
 public function handle(Repository $config, Encrypter $encrypter)
 {
     $email = $encrypter->encrypt($this->user->getEmail());
     $code = $encrypter->encrypt($this->user->getResetCode());
     $query = "?email={$email}&code={$code}&redirect={$this->redirect}";
     return $config->get('anomaly.module.users::paths.reset') . $query;
 }
Пример #5
0
 /**
  * Decrypt an array based cookie.
  *
  * @param  array  $cookie
  * @return array
  */
 protected function decryptArray(array $cookie)
 {
     $decrypted = array();
     foreach ($cookie as $key => $value) {
         $decrypted[$key] = $this->encrypter->decrypt(urldecode($value));
     }
     return $decrypted;
 }
Пример #6
0
 /**
  * Determine if the session and input CSRF tokens match.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return bool
  */
 protected function tokensMatch($request)
 {
     $token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
     if (!$token && ($header = $request->header('X-XSRF-TOKEN'))) {
         $token = $this->encrypter->decrypt($header);
     }
     return Str::equals($request->session()->token(), $token);
 }
 /**
  * Fired just before building.
  *
  * @param Encrypter $encrypter
  * @param Request   $request
  */
 public function onReady(Encrypter $encrypter, Request $request)
 {
     if ($code = $request->get('code')) {
         array_set($this->parameters, 'code', $encrypter->decrypt($code));
     }
     if ($email = $request->get('email')) {
         array_set($this->parameters, 'email', $encrypter->decrypt($email));
     }
 }
Пример #8
0
 /**
  * Execute the job.
  *
  * @param  Mailer  $mailer
  * @return void
  */
 public function handle(Mailer $mailer, Encrypter $encrypter)
 {
     app()->setLocale($this->locale);
     $token = $encrypter->encrypt(json_encode(['id' => $this->user->getKey(), 'expires' => time() + 3600 * 72]));
     $user = $this->user;
     $mailer->send('core::emails.activate', compact('user', 'token'), function ($message) use($user) {
         $message->to($user->email);
         $message->subject(trans('core::auth.emails.activate.subject'));
     });
 }
 /**
  * Fetch the list of Locations
  *
  * @Get("/", as="AdminLocationsIndex")
  */
 public function locationUpdate($id, Encrypter $encrypter)
 {
     //echo $id;
     $token = $encrypter->encrypt(csrf_token());
     //$locations = DB::table('locations')->where('id', '=', $id)->first();
     $query = "SELECT ld.`id` AS `location_id` , ld.`name` AS `location` , ld.`slug` AS `slug` , IF( la.`id` = ld.`id` , '', la.`id` ) AS `parent_id` , IF( la.`id` = ld.`id` , '', la.`name` ) AS `parent` , CAST( ld.type AS CHAR ) AS `location_type`\n                FROM locations_tree AS `lt`\n                INNER JOIN locations AS `ld` ON lt.`descendant` = ld.`id`\n                INNER JOIN locations AS `la` ON lt.`ancestor` = la.`id`\n                WHERE (lt.`length` =1 OR ld.`type` = 'Country') AND ld.id = '{$id}'";
     $locations = DB::select($query);
     /*print_r($locations);
       echo $locations['0']->location_id;
       exit;*/
     return view('admin.settings.locationsupdate', ['_token' => $token, 'locations' => $locations]);
     //return response()->json($locations->fetch($request->all()));
 }
 /**
  * Determine if the session and input CSRF tokens match.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return bool
  */
 protected function tokensMatch($request)
 {
     // Get tokens from session and the request
     $sessionToken = $request->session()->token();
     $token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
     if (!$token && ($header = $request->header('X-XSRF-TOKEN'))) {
         $token = $this->encrypter->decrypt($header);
     }
     if (!is_string($sessionToken) || !is_string($token)) {
         return false;
     }
     // Validate them
     return hash_equals((string) $request->session()->token(), (string) $token);
 }
 /**
  * Handle the command.
  *
  * @param UserRepositoryInterface $users
  * @param UserActivator           $activator
  * @param Encrypter               $encrypter
  * @param Request                 $request
  * @return bool
  */
 public function handle(UserRepositoryInterface $users, UserActivator $activator, Encrypter $encrypter, Request $request)
 {
     $code = $request->get('code');
     $email = $request->get('email');
     if (!$code || !$email) {
         return false;
     }
     $code = $encrypter->decrypt($code);
     $email = $encrypter->decrypt($email);
     if (!($user = $users->findByEmail($email))) {
         return false;
     }
     return $activator->activate($user, $code);
 }
Пример #12
0
 /**
  * Activate a user by token
  * @param  string  $token
  * @param  Request $request
  * @param  Events  $events
  * @return Illuminate\Http\Response
  */
 public function getActivate(Encrypter $encrypter, Request $request, Events $events, $token)
 {
     try {
         $data = json_decode($encrypter->decrypt($token));
         if (is_object($data) && isset($data->id) && is_numeric($data->id) && isset($data->expires) && with(new Carbon(date('Y-m-d H:i:s', $data->expires)))->gt(Carbon::now())) {
             $user = $this->activateUser($data->id);
             $events->fire(new UserActivated($user));
             return $this->userWasActivated($data->id);
         } else {
             throw new Exception("Invalid token");
         }
     } catch (Exception $e) {
         return $this->userWasNotActivated();
     }
 }
 /**
  * Validate the request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  array $params
  * @return bool
  */
 public function validate($request, $params = [])
 {
     $this->params = $params;
     try {
         $timeOpened = $this->encrypter->decrypt($request->get('_guard_opened'));
     } catch (DecryptException $e) {
         return false;
     }
     if (!is_numeric($timeOpened)) {
         return false;
     }
     $timeElapsed = time() - $timeOpened;
     $tooFast = $timeElapsed < $this->getMinTime();
     $tooSlow = $timeElapsed > $this->getMaxTime();
     return !$tooFast && !$tooSlow;
 }
 /**
  * Encrypt the cookies on an outgoing response.
  *
  * @param  \Symfony\Component\HttpFoundation\Response  $response
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function encrypt(Response $response)
 {
     foreach ($response->headers->getCookies() as $key => $cookie) {
         $response->headers->setCookie($this->duplicate($cookie, $this->encrypter->encrypt($cookie->getValue())));
     }
     return $response;
 }
 /**
  * Encrypt the cookies on an outgoing response.
  *
  * @param  \Symfony\Component\HttpFoundation\Response  $response
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function encrypt(Response $response)
 {
     foreach ($response->headers->getCookies() as $cookie) {
         if ($this->isDisabled($cookie->getName())) {
             continue;
         }
         $response->headers->setCookie($this->duplicate($cookie, $this->encrypter->encrypt($cookie->getValue())));
     }
     return $response;
 }
Пример #16
0
 /**
  * Display a listing of the resource.
  *
  * @param Encrypter $encrypter
  * @param $hash
  * @return Response
  * @throws Exception
  */
 public function index(Encrypter $encrypter, $hash)
 {
     try {
         $params = $encrypter->decrypt($hash);
         $project = $this->projectRepository->find($params['project']);
         $user = $project->users->find($params['user']);
         if (is_null($user)) {
             throw new Exception('the user was not found');
         }
         $sourceClass = app()->make('Knoters\\Services\\Sources\\' . ucfirst($project->type->name) . 'Service');
         $video = $sourceClass->getVideo($project->video_id);
         $this->fractal->setSerializer(new ArraySerializer());
         JavaScriptFacade::put(['user' => $this->fractal->createData(new Item($user, new UserTransformer()))->toArray(), 'project' => $this->fractal->createData(new Item($project, new ProjectTransformer()))->toArray()]);
         return view('editor', ['video' => $video, 'project' => $project]);
     } catch (Exception $e) {
         throw $e;
         $this->errorResponse($e);
     }
 }
Пример #17
0
 /**
  * Increment or decrement an item in the cache.
  *
  * @param  string  $key
  * @param  mixed  $value
  * @param  \Closure  $callback
  * @return void
  */
 protected function incrementOrDecrement($key, $value, Closure $callback)
 {
     $prefixed = $this->prefix . $key;
     $cache = $this->table()->where('key', $prefixed)->lockForUpdate()->first();
     if (!is_null($cache)) {
         $current = $this->encrypter->decrypt($cache->value);
         if (is_numeric($current)) {
             $this->table()->where('key', $prefixed)->update(['value' => $this->encrypter->encrypt($callback($current))]);
         }
     }
 }
Пример #18
0
 /**
  * @param \Illuminate\Http\Request $request
  *
  * @return bool
  */
 protected function tokensMatch($request)
 {
     $sessionToken = $request->session()->token();
     $token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
     if (!$token && ($header = $request->header('X-XSRF-TOKEN'))) {
         $token = $this->encrypter->decrypt($header);
     }
     if (!is_string($sessionToken) || !is_string($token)) {
         return false;
     }
     return hash_equals($sessionToken, $token);
 }
Пример #19
0
 /**
  * Set a given setting value.
  *
  * @param string $key
  * @param mixed $value
  * @return void
  */
 public function set($key, $value = null)
 {
     $this->fire('setting', $key, [$key, $value]);
     $generatedKey = $this->getKey($key);
     $serializedValue = $this->serializeValue($value);
     $this->repository->set($generatedKey, $this->isEncryptionEnabled() ? $this->encrypter->encrypt($serializedValue) : $serializedValue);
     if ($this->isCacheEnabled()) {
         $this->cache->forget($generatedKey);
     }
     $this->fire('set', $key, [$key, $value]);
     $this->context(null);
 }
 /**
  * Store an item in the cache for a given number of minutes.
  *
  * @param  string  $key
  * @param  mixed   $value
  * @param  int     $minutes
  * @return void
  */
 public function put($key, $value, $minutes)
 {
     $key = $this->prefix . $key;
     // All of the cached values in the database are encrypted in case this is used
     // as a session data store by the consumer. We'll also calculate the expire
     // time and place that on the table so we will check it on our retrieval.
     $value = $this->encrypter->encrypt($value);
     $expiration = $this->getTime() + $minutes * 60;
     try {
         $this->table()->insert(compact('key', 'value', 'expiration'));
     } catch (Exception $e) {
         $this->table()->where('key', '=', $key)->update(compact('value', 'expiration'));
     }
 }
Пример #21
0
 /**
  * Increment or decrement an item in the cache.
  *
  * @param string $key        	
  * @param mixed $value        	
  * @param \Closure $callback        	
  * @return int|bool
  */
 protected function incrementOrDecrement($key, $value, Closure $callback)
 {
     return $this->connection->transaction(function () use($key, $value, $callback) {
         $prefixed = $this->prefix . $key;
         $cache = $this->table()->where('key', $prefixed)->lockForUpdate()->first();
         if (is_null($cache)) {
             return false;
         }
         $current = $this->encrypter->decrypt($cache->value);
         $new = $callback($current, $value);
         if (!is_numeric($current)) {
             return false;
         }
         $this->table()->where('key', $prefixed)->update(['value' => $this->encrypter->encrypt($new)]);
         return $new;
     });
 }
Пример #22
0
 /**
  * Encrypt payload.
  *
  * @return string
  */
 protected function encryptPayload()
 {
     $payload = json_encode($this->payload);
     return $this->encrypter->encrypt($payload);
 }
Пример #23
0
 /**
  * Determine if the session and input CSRF tokens match.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return bool
  */
 protected function tokensMatch($request)
 {
     $token = $request->session()->token();
     $header = $request->header('X-XSRF-TOKEN');
     return StringUtils::equals($token, $request->input('_token')) || $header && StringUtils::equals($token, $this->encrypter->decrypt($header));
 }
Пример #24
0
 /**
  * Fire the Closure based queue job.
  *
  * @param  \Illuminate\Contracts\Queue\Job  $job
  * @param  array  $data
  * @return void
  */
 public function fire($job, $data)
 {
     $closure = unserialize($this->crypt->decrypt($data['closure']));
     $closure($job);
 }
Пример #25
0
 /**
  * The login View
  *
  * @return Response
  */
 public function loginView(Encrypter $encrypter)
 {
     $token = $encrypter->encrypt(csrf_token());
     return view('admin.login', ['_token' => $token]);
 }
Пример #26
0
 /**
  * Display the locations available for gourmetitup
  *
  * @Get("/locations", as="adminSettingsLocations")
  * @return Response
  */
 public function locations(Encrypter $encrypter)
 {
     $token = $encrypter->encrypt(csrf_token());
     return view('admin.settings.locations', ['_token' => $token]);
 }
Пример #27
0
 /**
  * Refresh an access_token
  * @param  User   $user
  * @return object
  */
 public function refreshToken()
 {
     $response = $this->client->post('oauth2/token', ['body' => ['refresh_token' => $this->crypt->decrypt($this->token->refresh_token), 'client_id' => env('IMGUR_KEY'), 'client_secret' => env('IMGUR_SECRET'), 'grant_type' => 'refresh_token'], 'exceptions' => false]);
     $body = $response->getBody();
     return json_decode($body);
 }
Пример #28
0
 /**
  * Put an item into the storage.
  *
  * @param string $key
  * @param string $data
  *
  * @return void
  */
 public function put($key, $data)
 {
     $this->store->put($key, $this->encrypter->encrypt($data));
 }
 /**
  * Prepare the serialized session data for storage.
  *
  * @param  string  $data
  * @return string
  */
 protected function prepareForStorage($data)
 {
     return $this->encrypter->encrypt($data);
 }
 /**
  * Handle the command.
  *
  * @param Encrypter $encrypter
  * @return string
  */
 public function handle(Encrypter $encrypter)
 {
     $email = $encrypter->encrypt($this->user->getEmail());
     $code = $encrypter->encrypt($this->user->getResetCode());
     return "/users/password/reset?email={$email}&code={$code}&redirect={$this->redirect}";
 }