Git Product home page Git Product logo

laravel-impersonator's Introduction

Laravel Package codecov

Impersonator for Laravel

Impersonator for Laravel masthead image.

Supporting This Package

This is an MIT-licensed open source project with its ongoing development made possible by the support of the community. If you'd like to support this, and our other packages, please consider becoming a backer or sponsor on Patreon.

Pre-requisites

  • Laravel 8.0+
  • PHP 7.3+

Installation

composer require genealabs/laravel-impersonator

Configuration

  • genealabs-laravel-impersonator.layout: master blade layout view for your application (default layouts.app).
  • genealabs-laravel-impersonator.content-section: name of content section in master layout blade view (default content).
  • genealabs-laravel-impersonator.user-model: user model of your application (default config('auth.providers.users.model')).
  • genealabs-laravel-impersonator.middleware: the middleware to use for the impersonatee routes (default: ['web', 'auth']). You may specify only or except parameters. E.g. ['web', 'auth', 'password.confirm' => ['except' => 'destroy']]

If you need to customize these settings:

php artisan impersonator:publish --config

Usage

  1. Add trait GeneaLabs\LaravelImpersonator\Traits\Impersonatable to your user model.
  2. Override trait method public function getCanImpersonateAttribute() : bool that determines if a given user can impersonate other users.
  3. (optional) Override trait method public function getCanBeImpersonatedAttribute() : bool that determines if a given user can be impersonated.
  4. Use route('impersonatees.index') to view a list of all impersonatable users. You could add something like the following to your menu:
@if ((auth()->user()->canImpersonate ?? false) && ! session('impersonator'))
    <a class="dropdown-item" href="{{ route('impersonatees.index') }}">Impersonator</a>
@endif
  1. (optional) Add something like the following to your menu view to allow imporsonator to stop impersonating:
@if (session('impersonator'))
    <a href="{{ url('/logout') }}"
        class="dropdown-item"
        onclick="event.preventDefault(); document.getElementById('end-personation-session-form').submit();"
    >
        End Impersonation Session
    </a>
    <form action="{{ route('impersonatees.destroy', auth()->user()) }}"
        method="POST"
        style="display: none;"
        id="end-personation-session-form"
    >
        {{ csrf_field () }}
        {{ method_field ('DELETE') }}
    </form>
@else
    <a href="{!! route('logout') !!}"
        class="dropdown-item"
        onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
        Logout
    </a>
    <form method="POST"
        action="{{ route('logout') }}"
        accept-charset="UTF-8"
        id="logout-form"
        style="display:none;"
    >
        {{ csrf_field () }}
    </form>
@endif

Customization

php artisan impersonator:publish --views

Credits

In large part prodded and inspired by LaraCasts' tutorial: https://laracasts.com/series/how-do-i/episodes/17. Thank you @JeffreyWay!

laravel-impersonator's People

Contributors

gitter-badger avatar herroworrd avatar keoghan avatar mikebronner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-impersonator's Issues

View Form looks broken

Issue

Maybe related to #4 the view of /impersonatees looks broken.

impersonator-view

Environment

Laravel Version: 5.5
Laravel Impersonator Package Version:0.2.0
PHP Version: 7.0

No Laravel 5.6 ready

Issue

Seems to be that the package is not ready for Laravel 5.6

Environment

Laravel Version: 5.6
Laravel Impersonator Package Version: 0.2.1
PHP Version: 7.1

Stack Trace

composer require genealabs/laravel-impersonator
Using version ^0.2.1 for genealabs/laravel-impersonator
./composer.json has been updated
Loading composer repositories with package information                                                                                                   Updating dependencies (including require-dev)         Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for genealabs/laravel-impersonator ^0.2.1 -> satisfiable by genealabs/laravel-impersonator[0.2.1].
    - Conclusion: remove laravel/framework v5.6.15
    - Conclusion: don't install laravel/framework v5.6.15
    - genealabs/laravel-impersonator 0.2.1 requires illuminate/view 5.5.* -> satisfiable by laravel/framework[5.5.x-dev], illuminate/view[5.5.x-dev, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40].
    - Can only install one of: laravel/framework[5.5.x-dev, v5.6.15].
    - don't install illuminate/view 5.5.x-dev|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.0|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.16|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.17|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.2|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.28|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.33|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.34|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.35|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.36|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.37|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.39|don't install laravel/framework v5.6.15
    - don't install illuminate/view v5.5.40|don't install laravel/framework v5.6.15
    - Installation request for laravel/framework (locked at v5.6.15, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.15].


Installation failed, reverting ./composer.json to its original content.

php artisan impersonator:publish --views failes

Issue

" The "--views" option does not exist. " by using command php artisan impersonator:publish --views

Environment

Laravel Version: 5.5
Laravel Impersonator Package Version: 0.2.0
PHP Version: 7

Stack Trace

impersonator

Publishing of config files failes

Issue

No new config file is published when run artisan:

php artisan impersonator:publish --config
Publishing complete.

Environment

Laravel Version: 5.5
Laravel Impersonator Package Version: 0.2.0
PHP Version: 7

Impersonate destroy does not work for every user

Issue

I have a set of user who can be impersonated and a set of user who can impersonate. When a user impersonate another and then press end impersonate, a 403 permission dined is given.
This is due to the auth check in the ImpersonateeController. When you comment this line everything works fine. Further I would recommend a small error handling.:

   public function destroy() : RedirectResponse
    {
        /** This need to be comment **/
		//$this->authorize('impersonation', auth()->user());

        $impersonator = session('impersonator');
		if(!empty($impersonator)){
			$originalSession = session('impersonator-session-data');
			session()->flush();
			session($originalSession);
			auth()->login($impersonator);
			$msg = 'Impersonation Session end successfully.';			 // Message is optional and have to be implemented in layout first
			return back()->with('success',$msg); //using back instead of / 
		}
		else{
			$msg =  'No impersonation session located.';
			return back()->with('error',$msg);  //using back instead of / 
		}       
    }

Environment

Laravel Version: 5.5
Laravel Impersonator Package Version: 0.2.0
PHP Version: 7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.