Coder Social home page Coder Social logo

lucasvllima / nova-impersonate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kabbouchi/nova-impersonate

0.0 0.0 0.0 1.67 MB

A Laravel Nova field allows you to authenticate as your users.

License: MIT License

PHP 59.49% JavaScript 2.62% HTML 4.00% Vue 33.90%

nova-impersonate's Introduction

Nova Impersonate Field

Latest Version on Packagist Total Downloads

This field allows you to authenticate as your users.

screenshot1 screenshot2 screenshot3

Behind the scenes 404labfr/laravel-impersonate is used.

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require kabbouchi/nova-impersonate

Usage

Add Impersonate::make($this) field in App\Nova\User.php

<?php

namespace App\Nova;

use KABBOUCHI\NovaImpersonate\Impersonate;

...

class User extends Resource
{
	...
	
	public function fields(Request $request)
	{
		return [
			ID::make()->sortable(),

			Gravatar::make(),

			Text::make('Name')
				->sortable()
				->rules('required', 'max:255'),

			Text::make('Email')
				->sortable()
				->rules('required', 'email', 'max:255')
				->creationRules('unique:users,email')
				->updateRules('unique:users,email,{{resourceId}}'),

			Password::make('Password')
				->onlyOnForms()
				->creationRules('required', 'string', 'min:6')
				->updateRules('nullable', 'string', 'min:6'),


			Impersonate::make($this),  // <---
		
			// or
		
			Impersonate::make($this)->withMeta([
			    'hideText' => false,
			]),
		
			// or
		
			Impersonate::make($this)->withMeta([
			    'redirect_to' => '/custom-redirect-url'
			]),

		];
	}

    ...
}

Advanced Usage

By default all users can impersonate an user.
You need to add the method canImpersonate() to your user model:

    /**
     * @return bool
     */
    public function canImpersonate()
    {
        // For example
        return $this->is_admin == 1;
    }

By default all users can be impersonated.
You need to add the method canBeImpersonated() to your user model to extend this behavior: Please make sure to pass instance Model or Nova Resource Impersonate::make($this) Impersonate::make($this->resource)

    /**
     * @return bool
     */
    public function canBeImpersonated()
    {
        // For example
        return $this->can_be_impersonated == 1;
    }

Events

You can hook onto the underlying package events

May be userful for things like setting session data

  • Lab404\Impersonate\Events\TakeImpersonation
  • Lab404\Impersonate\Events\LeaveImpersonation

You can optionally publish the config file with:

php artisan vendor:publish --tag=nova-impersonate-config

This is the default content of the config file published at config/nova-impersonate.php:

<?php

return [
	'enable_middleware' => true, // To inject the 'nova-impersonate::reverse' view in every route when impersonating 
	'redirect_back'     => true, // false (nova path), true or <url>
	'redirect_to'       => '/',
	'key_down'          => 'i', // Press `i` to impersonate user in details page
	'middleware'        => [
            'base' => 'web', // Middleware used for nova-impersonate routes
            'leave'  => 'auth', // Extra middleware used for leave route
    ],
];

You can publish and customize the nova-impersonate::reverse view

php artisan vendor:publish --tag=nova-impersonate-views

Credits

The MIT License (MIT). Please see License File for more information.

nova-impersonate's People

Contributors

kabbouchi avatar paras-malhotra avatar brentkozjak avatar janicerar avatar joselara avatar mbardelmeijer avatar pravk avatar andreschwarzer avatar dennis-fransen avatar dmyers avatar jankremlacek avatar japseyz avatar jubeki avatar laurencei avatar

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.