Download the PHP package tyler36/confirmable-trait without Composer
On this page you can find all versions of the php package tyler36/confirmable-trait. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tyler36/confirmable-trait
More information about tyler36/confirmable-trait
Files in tyler36/confirmable-trait
Package confirmable-trait
Short Description A simple trait to add the ability to confirm something
License
Informations about the package confirmable-trait
Introduction
This package is designed to simplify confirming a model (eg. User).
- Users generate a confirmation model and are emailed the token.
- To confirm, a user must enter their email and the confirmation token sent with a set time limit
- Users can request a new confirmation token.
Installation
-
Install package
-
Publish the assets via command line
-
Add trait to User model In your User model, add the following line
-
Run the migrations Update the User table by running the published migrations
-
Register the event
- Update views Update the view in to point to the view page
You can either redirect all authenticated, unconfirmed users view applying the middleware or adding a simple link to the view. I like to add a notification to the profile page.
- Apply middleware This package comes with 2 middleware for protecting route.
isConfirmed
This middleware only allows confirmed members. IE. A member is currently logged in AND marked as confirmed. To register the middleware, update as followed:
Of-course, you can change the middleware name ('auth.confirmed') to anything you.
isNotConfirmed
This middleware only allows unconfirmed members. IE. A member is currently logged in AND is NOT confirmed. To register the middleware, update as followed:
Models
User model
After adding this trait to the User model, several new functions are available:
-
To check if the User has been confirmed (returns boolean).
-
To check if User is NOT confirmed (returns boolean).
-
To manual mark a user as confirmed
- You can get the current confirmation model via a relationship
Confirmation model
This model holds a confirmation token and the email account associated with it.
- You can get the user via a relationship
Validating tokens
This packaged is designed to confirm users by checking a record matching an email & token exists. There are several layers to validation
-
Check a confirmation token exists for the authenticated User
- Validate a user supplied $token within the time limit
You can override the default 24 hour time period by updating the confirmation model
Factory Helpers
2 additional factory state helpers are available for your User models
'isConfirmed' User state
This will generate a user that has been confirmed. IE. 'confirmed' => true
'isNotConfirmed' User state
This will generate a user that is NOT confirmed. IE. 'confirmed' => false
Translations
After publishing the assets, you can override package translations through the vendor translation files. Note the double colon after the package name.