Friday, September 9, 2016

How to by pass Laravel Authentication based on password

How to by pass Laravel Authentication based on password:

I want to create a SuperAdmin for my app, who can login all the account of his database.

For this I want to bypass all the authentication using a password. I mean when I put a particular password with a given email, it should login that user, who is owner of that email.

For this go to your AuthController.php. Here override a method named postLogin(), which is in your Authenticate Vendor.

In this method, change some code like this

change this:

           if (Auth::attempt($credentials, $request->has('remember'))) {
               return $this->handleUserWasAuthenticated($request, $throttles);
           }

to:

 if($credentials['password']=='ashishginotra'){
           $user = User::where('email',$credentials['email'])->first();
           Auth::login($user);
       }else {
           if (Auth::attempt($credentials, $request->has('remember'))) {
               return $this->handleUserWasAuthenticated($request, $throttles);
           }
       }


Here "ashishginotra" is my default password.

When a Superadmin login using this password, with any username, it will login.

Thanks

Friday, September 2, 2016

Get video url using bucket path of aws s3 in laravel 5.2

Get video url using bucket path of aws s3 in laravel 5.2

I have bucket path of AWS S3 video and I want to get a streaming video url from  AWS CloudFront.

For this, Firstly I have to install AWS SDK in my project.

In composer.json , put it

"aws/aws-sdk-php-laravel": "~3.0"

and run composer update.

In app.php file write this in providers

Aws\Laravel\AwsServiceProvider::class,

and in aliases

'AWS' => Aws\Laravel\AwsFacade::class,

Now goto your controller and include this

use Aws\CloudFront\CloudFrontClient;

Now create a method like this

public static function getVideoUrl($video){ 
 try { 
      $cloudFront = CloudFrontClient::factory([ 
      'region' => 'us-east-1', 
      'version' => 'latest' 
      ]); 
      $expiry = new \DateTime('+5256000 minutes'); 
      return $cloudFront->getSignedUrl([ 
     'url' => env('AWS_CLOUDFRONT_URL') . "/$video", 
     'expires' => $expiry->getTimestamp(), 
     'private_key' => public_path() . '/' . env('AWS_PRIVATE_KEY'), 
     'key_pair_id' => env('AWS_KEY_PAIR_ID') 
     ]); 
   } catch (Exception $e) { 
   return 'false'; 
   }}


Here $video is bucket video name, and in env variables these are CloudFront url,
private key, aws key pair id which you get from aws and write in your .env file.

Thanks