Git Product home page Git Product logo

signature's Introduction

Signature

Latest Version on Packagist Tests Total Downloads

This laravel package gives you the ability to create action links that can be used everywhere on your site (including emails).

A simple url can be created by the example below. The first parameter is the class to execute the action when the user visits the link, the second parameter is an array that holds all the data to be provided to the action class. The payload automatically gets encrypted when entering the database.

$url = SignatureFacade::make(Action::class, ['email' => '[email protected]'])->get();

The get() function returns a complete url based on the APP_URL in the .env file and the 'action_route' in the signature config

Example action class:

class Action 
{
    public function __invoke($payload)
    {
        // Do something      

        return redirect('login');
    }
}

Installation

You can install the package via composer:

composer require uteq/signature

You can publish and run the migrations with:

php artisan vendor:publish --provider="Uteq\Signature\SignatureServiceProvider" --tag="migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Uteq\Signature\SignatureServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    /*
     * This will be the url Signature will use to handle the actions
     * if the action_route is action the url will for example be https://example.com/action/{key}
     */
    'action_route' => '/action/{key}',
    
    /*
    * Here you can optionaly define the actions, for example: 'action => '\App\SignatureActions\Action'
    * When making a url you can provide the key instead of the class path, 
    * when using the example above it would look like SignatureFacade::make('action', $payload)->get();
    */
    'actions' => [
        
    ]
];

Usage

You can create a link with the examples provided below. All options are optional and can be used independently.

$urlExample = SignatureFacade::make(Action::class)
    ->payload(['variable_1' => 'information', 'variable_2' => 'even more information'])
    ->expirationDate(now()->addWeek())
    ->password('secretPassword')
    ->oneTimeLink()
    ->get();

$longerKeyUrlExample = SignatureFacade::make(Action::class)
    ->longerKey(64)
    ->group('1234')
    ->get();
    
$customKeyExample = SignatureFacade::make(Action::class)
    ->customKey('veryCoolCustomKey')
    ->get();
  • payload(): Alternative way to pass variables to the link

  • expirationDate(): Option to allow you to specify the expiration date (defaults to 2 weeks from creating the link)

  • password(): Protects the link by asking for the password set in this function when using the link

  • oneTimeLink(): Deletes the link when the action has successfully executed

  • get(): Makes a complete url based on the APP_URL in the .env file and the 'action_route' in the signature config (defaults to /action/{key})

  • longerKey(): uses a longer key in the url with changeable length (max. 254). This is recommended when handling sensitive data.

  • group(): groups signatures together via the string given to the function, when a signature is deleted, all signatures with the same group also get deleted.

  • customKey(): grants the ability to use a custom key, if both longerKey() and customKey() are used in the same signature, the last function will override the other.

Action class:

class Action
{
    public function __invoke($payload)
    {
        // from here on you can use the variables in $payload to make the link actually do something;

        return redirect('/login'); // If no return is provided the user will be redirected to "/".
    }

}

Commands

This command deletes all the signatures that have expired.

php artisan signature:clean

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

signature's People

Contributors

stef1904berg avatar nathanjansen avatar

Stargazers

 avatar Luca Benati avatar moneya avatar Roman Hossain Shaon avatar Braunson Yager avatar Nick Zhang avatar Davor Minchorov avatar LogikIO avatar Rifki Aria Gumelar avatar Flávio H. Ferreira avatar Flavius Constantin avatar  avatar Hardik Shah avatar Tom White avatar Luca Patera avatar Mark Townsend avatar Mark Townsend avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

nathanjansen

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.