Giter Site home page Giter Site logo

spark-invite's Introduction

Spark Invite

Spark Invite is designed for the use case where user account can been pre-populated, e.g. through information provided by a 3rd party, and an invitation needs to be sent so the prospective user can 'claim' their account.

For example, within a system bulk creation of new user accounts may be required to ensure security, consistency and for convenience. Once a new user account has been created the SparkInvite package can be used to manage the process of the account being claimed. The stages are:

  • A referrer, on a referral team (as the referrer may be a member of more than one team), invites the new user account. This is encapsulated in the Invitation model.
  • An invite event is fired, allowing for code outside of the SparkInvite package to verify the invite before issuing any communication. For example, automatic checks for email address domains or manual verification potentially requiring communication by telephone prior to invitation issue.
  • An issued event is fired allowing for accept/reject links to be issued. The actual sending of the invitation is done outside of the SparkInvites package, allowing your system to use your preference of package/method of communication.
  • If the user accepts the invitation the user is immediately asked to reset their password using Spark's standard password reset mechanism. A user may also reject an invitation.
  • An invitation can expire, and either soft-expiry (allows for recovery of the invitation unless expired invitations are manually cleaned up) or hard-expiry (once an invitation has expired it cannot be used).

Installation

  1. Require in the package
composer require zinethq/spark-invite dev-master
  1. Edit config\app.php to have:
    ...
    'providers' => [
        ...
        ZiNETHQ\SparkInvite\SparkInviteServiceProvider::class,
        ...
    ],
    ...
    'aliases' => [
        ...
        'SparkInvite' => ZiNETHQ\SparkInvite\Facades\SparkInvite::class,
        ...
    ],
    ...
  1. Run the command:
php artisan vendor:publish --provider="ZiNETHQ\SparkInvite\SparkInviteServiceProvider"

This will publish the following files:

  • /database/migrations/TIMESTAMP_create_user_invitations_table.php
  • /database/migrations/TIMESTAMP_create_invitation_status_table.php
  • /config/sparkinvite.php
  • /app/Listeners/InvitationListener.php
  • /app/InvitationStatus.php
  1. Migrate the database

  2. Add the following to your App\Providers\EventServiceProvider class:

    protected $listen = [
        ...
        'spark.invite.*' => [
            'App\Listeners\InvitationListener',
        ],
        ...
    ];

Managing errors

When there is an issue with a token, e.g. doesn't exist or has been revoked, the invitation controller redirects back to the route defined in the configuration setting sparkinvites.routes.on-error. When redirecting the user one of the sparkinvites.messages is passed under the variable name configured by sparkinvite.flash, which can be displayed in your view. For example, using Vue.js and Notify.js (plus underscore.string/lodash for capitalization and sprintf for string creation) the following component will do this:

Vue.component('alert', {

    props: {
        message: {
            type: Object,
            required: false,
            default: null
        }
    },

    computed: {
        title: function () {
            return sprintf('<strong>%s</strong>', _string.capitalize(this.message.type));
        },

        type: function () {
            switch (this.message.type) {
                case 'error':
                    return 'danger';
                case 'warning':
                    return 'warning';
                case 'success':
                    return 'success';
                case 'info':
                    return 'info';
                default:
                    return 'danger';
            }
        },

        icon: function() {
            switch (this.type) {
                case 'danger':
                    return 'fa fa-times-circle';
                case 'warning':
                    return 'fa fa-exclamation-triangle';
                case 'success':
                    return 'fa fa-check-circle';
                case 'info':
                    return 'fa fa-info-circle';
                default:
                    return 'fa fa-times-circle';
            }
        }
    },

    template: '',

    created: function () {
        this.$nextTick(function () {
            if (this.message) {
                $.notify({
                    icon: this.icon,
                    title: this.title,
                    message: this.message.content
                },{
                    type: this.type,
                    timer: 3000,
                });
            }
        });
    }

});

When used like so on your view page:

<alert :message="{{ json_encode(session()->get('alert'), null) }}"></alert>

spark-invite's People

Contributors

blomdahldaniel avatar drjonnicholson avatar

Watchers

 avatar  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.