public function handle($request, Closure $next, $guard = null)
 {
     $setCookie = false;
     if (!$request->has('shop') && !$request->hasCookie('shopify_domain')) {
         return $next($request);
     }
     if (!$request->has('shop')) {
         $domain = $request->cookie('shopify_domain');
     } else {
         $domain = $request->input('shop');
         $setCookie = true;
     }
     $setup['SHOP_DOMAIN'] = $domain;
     $token = \App\Token::where('domain', $domain)->first();
     if ($token) {
         $setup['ACCESS_TOKEN'] = $token->token;
     }
     Sh::setup($setup);
     if ($setCookie) {
         $response = $next($request);
         $response->withCookie(cookie()->forever('shopify_domain', $domain));
         return $response;
     } else {
         return $next($request);
     }
 }
示例#2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param array $data
  *
  * @return User
  */
 protected function create(array $data)
 {
     $token = Token::where('token', '=', $data['registration_token'])->first();
     $city = City::where('id', '=', $token->city_id)->first();
     $user = User::create(['name_first' => $data['name_first'], 'name_last' => $data['name_last'], 'username' => $data['username'], 'bio' => $data['bio'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'city_id' => $city->id]);
     Event::fire(new PostSuccessfullAuth($data['registration_token']));
     return $user;
 }
 /**
  * Authenticate the given request token is valid or not.
  *
  * @param  string $token
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function authenticate($token)
 {
     $token = Token::where('token', '=', $token)->first();
     if (is_null($token) || $token->disable) {
         $msg = is_null($token) ? 'Invalid token' : 'Application is disable';
         return response_unauthorized($msg);
     }
     return response_ok($token);
 }
 public function handle($request, Closure $next)
 {
     $authToken = $request->header('Auth-token');
     if (!$authToken || !AuthService::tokenIsValid($authToken)) {
         //return abort(401, 'Not authorized.');
         return response('Not authorized.')->header('Status', 401);
     }
     AuthService::extendToken($authToken);
     Auth::login(Token::where('auth_token', $authToken)->first()->user);
     return $next($request);
 }
示例#5
0
 public function doPasswordReset($token)
 {
     $token = Token::where('token', '=', $token)->first();
     if ($token == null) {
         return Redirect::to('home')->with("bad", "Token expired, does not exist, or has already been used. Please check, and try again.");
     }
     $user = $token->user()->first();
     Auth::login($user);
     $token->delete();
     return view('users.edit', compact('user'))->with("good", "Successfully logged in using token - please change your password now");
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $route = app()->router->getCurrentRoute();
     $routeParam = $route->getParameter('token');
     $paramToken = Token::where('token', '=', $routeParam)->first();
     if ($paramToken) {
         return $next($request);
     } else {
         Notification::error('Your registration token has expired, please contact harry@madebyfieldwork.com for a new one');
         return redirect('/');
     }
 }
示例#7
0
 /**
  * Reset the given user's password.
  *
  * @param  Request  $request
  * @return Response
  */
 public function postReset(ResetRequest $request)
 {
     $credentials = $request->only('email', 'password', 'password_confirmation', 'token');
     $email = Token::where('token', '=', $request->get('token'))->first()->email;
     $credentials['email'] = $email;
     $response = $this->reminderService->reset($credentials);
     switch ($response) {
         case PasswordBroker::PASSWORD_RESET:
             return redirect()->back()->with('status', '');
         default:
             return redirect()->back()->withErrors(['email' => trans($response)]);
     }
 }
示例#8
0
 function __construct($connection_name)
 {
     $this->connection_name = $connection_name;
     $tk = Token::where('connection_name', $connection_name)->where('user_id', Auth::user()->id)->firstOrFail();
     $pvd = Providers::where("id", $tk->provider_id)->first();
     $this->provider_value = $pvd->reference_name;
     $this->provider_logo = $pvd->provider_logo;
     $this->owner = $tk->user_id;
     $this->token_id = $tk->id;
     $token = array('access_token' => $tk->access_token, 'expired_in' => $tk->expired_in, 'refresh_token' => $tk->refresh_token);
     $className = '\\App\\Library\\' . $this->provider_value . 'Interface';
     $this->connObj = new $className((object) $token);
 }
示例#9
0
 /**
  * 获得绑定Token
  * @return Token
  */
 public static function obtainBind()
 {
     if (Auth::guest()) {
         throw new UnauthorizedException(trans('errors.unauthorized'), 401);
     }
     $carbon = Carbon::create();
     $carbon->subMinute(1);
     //如果一分钟内已产生,使用之前的
     $recentToken = Token::where('created_at', '>', $carbon)->first();
     if ($recentToken) {
         return $recentToken;
     }
     return static::generate(Auth::id(), 30, static::$type_bind);
 }
示例#10
0
 function __construct($token = null)
 {
     if ($token != null) {
         $this->access_token = $token->access_token;
         $this->refresh_token = $token->refresh_token;
         $this->expired_in = $token->expired_in;
         if ($this->getAccessTokenStatus() != 1) {
             $keyValueStore = new KeyValueStore(new MemoryAdapter());
             $keyValueStore->set('access_token', $this->access_token);
             $keyValueStore->set('refresh_token', $this->refresh_token);
             $keyValueStore->expire('access_token', 0);
             $keyValueStore->expire('refresh_token', $this->expired_in + (5184000 - 3600) - time());
             #  60 days
             $oAuthClient = new OAuthClient($keyValueStore, $this->clientId, $this->clientSecret, $this->redirectUri);
             $oAuthClient->authorize();
             $keyValueStore = $oAuthClient->getKvs();
             Token::where('access_token', $this->access_token)->where('refresh_token', $this->refresh_token)->update(array('access_token' => $keyValueStore->get('access_token'), 'refresh_token' => $keyValueStore->get('refresh_token'), 'expired_in' => time() + $keyValueStore->getTtl('access_token')));
             $this->access_token = $keyValueStore->get('access_token');
             $this->refresh_token = $keyValueStore->get('refresh_token');
             $this->expired_in = time() + $keyValueStore->getTtl('access_token');
         }
     } else {
         $keyValueStore = new KeyValueStore(new MemoryAdapter());
         $oAuthClient = new OAuthClient($keyValueStore, $this->clientId, $this->clientSecret, $this->redirectUri);
         try {
             $oAuthClient->authorize();
             $keyValueStore = $oAuthClient->getKvs();
             $this->access_token = $keyValueStore->get('access_token');
             $this->refresh_token = $keyValueStore->get('refresh_token');
             $this->expired_in = time() + $keyValueStore->getTtl('access_token');
         } catch (ExitException $e) {
             # Location header has set (box's authorize page)
             # Instead of an exit call it throws an ExitException
             exit;
         } catch (OAuthException $e) {
             # e.g. Invalid user credentials
             # e.g. The user denied access to your application
         } catch (ClientException $e) {
             # e.g. if $_GET['code'] is older than 30 sec
         }
     }
     $this->state = (object) array('redirect_uri' => null, 'token' => null);
     $this->state->token = (object) array('obtained' => null, 'data' => (object) array('access_token' => $this->access_token));
 }
 function __construct($token = null)
 {
     $this->client = new Google_Client();
     $this->client->setClientId($this->client_id);
     $this->client->setClientSecret($this->client_secret);
     $this->client->setRedirectUri($this->redirect_uri);
     $this->client->setApprovalPrompt('force');
     $this->client->setAccessType("offline");
     $this->client->addScope("https://www.googleapis.com/auth/drive");
     if ($token != null) {
         $this->access_token = $token->access_token;
         $this->refresh_token = $token->refresh_token;
         $this->expired_in = $token->expired_in;
         if ($this->getAccessTokenStatus() != 1) {
             $this->client->refreshToken($this->refresh_token);
             $token = $this->client->getAccessToken();
             $token = (array) json_decode($token);
             $this->expired_in = time() + $token['expires_in'];
             Token::where('access_token', $this->access_token)->where('refresh_token', $this->refresh_token)->update(array('access_token' => $token['access_token'], 'expired_in' => $this->expired_in));
             $this->access_token = $token['access_token'];
         } else {
             $this->client->setAccessToken(json_encode($token));
         }
         $this->drive_service = new Google_Service_Drive($this->client);
     } else {
         if (isset($_GET['code'])) {
             $this->client->authenticate($_GET['code']);
             $token = $this->client->getAccessToken();
             $token = (array) json_decode($token);
             $this->access_token = $token['access_token'];
             $this->refresh_token = $token['refresh_token'];
             $this->expired_in = time() + $token['expires_in'];
             $this->drive_service = new Google_Service_Drive($this->client);
         } else {
             $authUrl = $this->client->createAuthUrl();
             header('Location: ' . $authUrl);
             die;
         }
     }
 }
 /**
  * Boot the authentication services for the application.
  *
  * @return void
  */
 public function boot()
 {
     // Here you may define how you wish users to be authenticated for your Lumen
     // application. The callback which receives the incoming request instance
     // should return either a User instance or null. You're free to obtain
     // the User instance via an API token or any other method necessary.
     $user = null;
     $this->app['auth']->viaRequest('api', function ($request) {
         if ($request->header("AuthToken")) {
             $tk = Token::where('api_token', $request->header("AuthToken"))->first();
             return User::where('id', $tk->user_id)->first();
         }
     });
     // Authorises the current user for particular requests
     Gate::define('getUser', function ($user, $userid) {
         // TODO allow user to get users matched with them
         return $user->id == $userid;
     });
     Gate::define('deleteUser', function ($user, $userid) {
         // TODO allow user to get users matched with them
         return $user->id == $userid;
     });
 }
示例#13
0
 public static function findByToken($token)
 {
     return Token::where('token', '=', $token)->firstOrFail();
 }
示例#14
0
 public function upload_dummy()
 {
     dump($_POST['real_store']);
     dump($_POST['dummy_path']);
     dump($_POST['dummy_store']);
     dump(User::find(Auth::user()->id)->token->where('connection_name', $_POST['real_store'])->first()->id);
     $tk = Token::where('connection_name', $_POST['real_store'])->where('user_id', Auth::user()->id)->firstOrFail();
     $des = $tk->gtc_folder;
     if ($_POST['dummy_path'] == "") {
         $des = "";
     }
     $proObj = new Provider($_POST['real_store']);
     $path = $proObj->uploadFile($_FILES['file'], $des);
     if ($_POST['dummy_store'] != 'all') {
         $dm = new DummyFile();
         $real_store = User::find(Auth::user()->id)->token->where('connection_name', $_POST['real_store'])->first()->id;
         $dummy_store = User::find(Auth::user()->id)->token->where('connection_name', $_POST['dummy_store'])->first()->id;
         $dm->path = $path[0]['path'];
         $dm->real_store = $real_store;
         $dm->dummy_path = $_POST['dummy_path'];
         $dm->dummy_store = $dummy_store;
         $dm->save();
     }
     return 'true';
 }
示例#15
0
 /**
  * Handle the event.
  *
  * @param  PostSuccessfullAuth  $event
  * @return void
  */
 public function handle(PostSuccessfullAuth $event)
 {
     $storedToken = Token::where('token', '=', $event->token)->first();
     $storedToken->delete();
     Notification::success('Registration successful, welcome to See+Do');
 }
 public function selectIn()
 {
     if (Auth::check()) {
         $id = $_GET['connection_name'];
         $any = $_GET['path'];
         $cname = 'all';
         $proObj = new Provider($id);
         $data = $proObj->getFiles($any);
         // dummy check
         $dummy_tk = Token::where('connection_name', $id)->where('user_id', Auth::user()->id)->firstOrFail();
         $dummy_files = DummyFile::where('dummy_store', $dummy_tk->id)->where('dummy_path', $any)->get();
         if (!empty($dummy_files)) {
             foreach ($dummy_files as $d) {
                 $real_tk = Token::where('id', $d->real_store)->where('user_id', Auth::user()->id)->firstOrFail();
                 $realProObj = new Provider($real_tk->connection_name);
                 $temp = $realProObj->getFiles($d->path);
                 $data = array_merge($data, $temp);
             }
         }
         if (!empty($data)) {
             foreach ($data as $key => $row) {
                 $is_dir[$key] = $row['is_dir'];
                 $name[$key] = $row['name'];
             }
             array_multisort($is_dir, SORT_DESC, $name, SORT_ASC, $data);
         }
         $parent = $this->getNavbar($cname, $proObj->getPathName($any), $any);
         return view('pages.gtl.components.gtl-board', ['data' => $data, "cname" => $cname, 'parent' => $parent, 'in' => $id]);
     } else {
         return Redirect::to('/');
     }
 }
示例#17
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $cliff = (new \DateTime())->modify('-5 minutes');
     \App\Token::where('created_at', '<', $cliff)->delete();
 }
 /**
  * Enable the application status.
  *
  * @param  string  $id
  * @return Response
  */
 public function enable($id)
 {
     $app = Application::find($id);
     if ($app->makeEnable()) {
         Token::where('app_id', $id)->drop('disable');
         session()->flash('success', 'Application is successfully enabled.');
     } else {
         session()->flash('error', 'Error occured to enable application.');
     }
     return back();
 }
 public static function extendToken($authToken)
 {
     $token = Token::where('auth_token', $authToken)->first();
     $token->expires_at = (new DateTime())->add(new DateInterval('PT10M'));
     $token->save();
 }
示例#20
0
 /**
  * @param $id
  * @return Token
  */
 public static function getToken($id)
 {
     $token = Token::where('id', '=', $id)->first();
     return $token;
 }