cotechsolution/laravel-access-user-account

Sometimes, in you Laravel application you need to manually logging in as a different user, then switching back to their own account. This package allows you to do the same thing with the permission of that user.

dev-master 2019-09-21 23:55 UTC

This package is auto-updated.

Last update: 2024-09-22 10:41:47 UTC


README

Sometimes, in you Laravel application you need to manually logging in as a different user, then switching back to their own account. This package allows you to do the same thing with the permission of that user. First, you request that user to give you the access of your account. First, you request that user to give you the access of your account. After getting acceptance from that user you can login to his/her account by clicking the single button and switch back to you own account at the same time. Once a person allows other person to access his/her account he/she can revoke the access anytime.

Features

This package provide you multiple features listed below:

  • Login with permission
  • Fully customizable
  • Theming
  • Work with any Laravel Project
  • Dynamic User Table Name
  • Dynamic User Attributes
  • Dynamic Number of Users to list down on single page
  • Success and Error notifications
  • Dynamic link for homepage
  • Enable disable email notifications
  • Enable/Disable Queueing email notifications
  • Searching / Sorting / Pagination
  • User Based Restrictions

Demo Application

Demo Application: http://laua.cotechsolution.com/system/users
Email: demo@cotechsolution.com
Password: demopass

Documentation, Installation, and Usage Instructions

  • Use following command to install:
composer require cotechsolution/laravel-access-user-account
  • Add the service provider to your $providers array in config/app.php file like:
Cotechsolution\LoginAsUser\LoginAsUserServiceProvider::class
  • Run the following command to publish configuration:
php artisan vendor:publish --provider "Cotechsolution\LoginAsUser\LoginAsUserServiceProvider"
  • Run the following command to run necessary migrations:
php artisan migrate
  • After installation, change the default settings of the package. Following is the code you will find in config/LoginAsUser.php, which you should update accordingly.
return [
    /**
     * This text will be visible on the tab of browser
     * Specific for access to screen
     */
    "access_to_tab_title"    => "Users you can access - ".env("APP_NAME"),

    /**
     * This text will be visible on the tab of browser
     * Specific for access by screen
     */
    "access_by_tab_title"    => "Users can access you - ".env("APP_NAME"),

    /**
     * This text will be visible as page heading
     * Specific for access to screen
     */
    "access_to_page_heading" => "Users you can access",

    /**
     * This text will be visible as page heading
     * Specific for access by screen
     */
    "access_by_page_heading" => "Users can access you",

    /**
     * Bootstrap table classes can be used here to change the theme of table
     * Specific for access to screen
     */
    "access_to_theme"        => "table-striped table-dark table-hover",

    /**
     * Bootstrap table classes can be used here to change the theme of table
     * Specific for access by screen
     */
    "access_by_theme"        => "table-striped table-dark table-hover",

    /**
     * You can restrict users here
     * Add comma separated string of the ids of users 
     * Only these users will be able to use the funcationality of this package
     * E.g. "1,2,3"
     * Leave empty for no restriction
     */
    "can_access"             => "",

    /**
     * You can restrict users here
     * Add comma separated string of the ids of users 
     * These users will not be able to use the funcationality of this package
     * E.g. "4,5,6"
     * Leave empty for no restriction
     */
    "cannot_access"          => "",

    /**
     * Name of users table, same as in your database 
     */
    "table_name"             => "users",

    /**
     * Attribute name of user's name, same as in your users table
     */
    "user_name_attribute"    => "name",

    /**
     * Attribute name of user's email, same as in your users table
     */
    "user_email_attribute"   => "email",

    /**
     * Total number of users you want to list on a single page
     */
    "user_per_page"          => 10,

    /**
     * Route or URL for the Homepage
     */
    "homepage_url"           => "/",

    /**
     * Enable or Disable the email notifications
     */
    "email_notifications"    => true
];

Usage Guide

How to get in the account of another user?

  • Login to your account.
  • Go to the page yourdomain.com/system/users
  • All the users will list down there.

image

  • If a user already given you the access of your account, you can simply login to other user account by clicking the button Get Me In but if you want to login to the account of a user who didn’t gave you the access, first you have to request the access of his account by clicking the button Request Access
  • Once you click on the request access button, the second person will receive an email with a link. By opening that link in the email, he/she will be redirected to a page where he/she can accept or decline the request generated by the first user to access his account.

image

  • If second user click on accept button then you will be authorized and you can access his account by clicking the button Get Me In as mentioned above.
  • After doing you work, you can switch back to your account easily by clicking the button switch back to my account on the page yourdomain.com/system/users

How to revoke the access from allowed users?

Once you allowed access to any user, you can definitely revoke the access from that user anytime.

  • Login to your account.
  • Go to the page yourdomain.com/system/users/allowed or click the button Switch to ACCESS BY mode on the top right corner.
  • All the users who can access your account will be list down there.

image

  • On this page all of the users will be list down who can access your account. If you want to revoke the access just click on the button Revoke Access. After doing this, your account will no longer be accessible by that user.

image

Suggestions / Bug Reporting

If you want us to add more features in this package or found a bug, please share with us at info@cotechsolution.com. Your suggestion will be appritiated.

Testing

composer test

License

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