Laravel package for giving admin-created accounts to users via 'set-password' email.

Overview

Invytr

Build Status

When making a website where users are created instead of registering themselves, you are faced with the challenge of safely giving users the access to their newly created accounts. Invytr solves this task by sending an email with a link that will enable user to set a password for the account.

This package is mainly intended to be used together with Laravel's auth scaffolding and password resetting mechanism.

Usage

Install it:

$ composer require glaivepro/invytr

You can now send invitations to your users. They will receive an email with a link for the password setting.

// $user must extend Illuminate\Foundation\Auth\User
// Laravel's \App\User does this by default

\Invytr::invite($user);

Customization

Invite expiration

By default invite tokens will expire in the same time as password resets. The default of 60 minutes is usually not enough for invited users as they might not sign up immediately after their invite is sent.

To increase the expiration time for invites, you should add key invites_expire in passwords.users within config/auth.php. No you don't have to publish anything. Just add the time in minutes like this:

'passwords' => [
	'users' => [
		'provider' => 'users',
		'table' => 'password_resets',
		'expire' => 60,
		'invites_expire' => 4320,  // This let's invites be valid for 3 days
	],
],

Custom texts and localization

You can customize/localize the strings in your JSON localization files (found in resources/lang).

The invite email uses the following strings:

  • Account created as the subject.
  • An account for you has been created! Please set a password for your account! as the text.
  • Set Password as the action link.

The password setting page uses only a single string:

  • Set Password as the title of the panel (instead of Reset Password).

Responses to setting attempts uses these strings:

  • Your password has been set!
  • Passwords must be at least six characters and match the confirmation.
  • This token is invalid.
  • We can't find a user with that e-mail address.

Email

Similar to Laravel's reset password functionality, you can create a sendPasswordSetNotification method on your user model.

public function sendPasswordSetNotification($token)
{
	// By default we send this:
	\Notification::send($this, new \GlaivePro\Invytr\Notifications\SetPassword($token));
}

View

By default this package uses the same auth.passwords.reset view as the Laravel's reset functionality. If you want more customization, make a auth.passwords.set view that includes all the same fields and posts the same request as does auth.passwords.reset.

Password setting and responses

The resets are going through Laravel's password.update route and handled by the reset method on App\Http\Controllers\Auth\ResetPasswordController.

If you want to customize the handling and/or responses, edit that method. You can tell apart setting and resetting requests by checking the session.

// in the ResetPasswordController

public function reset(Request $request)
{
	// something something
	
	if ($request->session()->has('invytr'))
	{
		// this is an invited user setting the password
	}
	
	// something else
}

Warning

Doing php artisan auth:clear-resets will also flush your invite tokens if they are expired according to auth.passwords.users.expire config value. Your auth.passwords.users.invites_expire config value will be ignored.

Change log

1.0 is the inital version of this package. Laravel 5.7 with PHP7.1 and PHP7.2 supported.

See CHANGELOG for more information on what has changed recently.

TODO

Add a trait that sets a random password and sends an invite when creating a new user.

Try to set expiration by tinkering with created_at when making a token instead of how it's done now.

Publish language files?

Improve testing,

  • Thoroughly cover Invytr, Controller, Middleware with unit tests
  • Unit test the URL made in the notification
  • Create more feature tests. For the pw setting page.

Improve code quality and consistency:

  • fix docblocks
  • imports vs fully qualified class names
  • sort the imports
  • alignment when chaining... maybe use styleCI?
  • braces vs no braces for single line control structures
  • helpers vs facades vs ...
  • example: config() vs $request->session() vs \View::

Maybe expand the scope to also provide something like a MustResetPasswordOnNextVisit trait? Or that's another package?

License

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

You might also like...
This package was created to deal with laravel datatables and cruds using vuejs.
This package was created to deal with laravel datatables and cruds using vuejs.

datatable-cruds Installation This package was created to deal with laravel datatables and cruds using vuejs. Install the package through Composer. Run

A package that makes it easy to have the `artisan make:` commands open the newly created file in your editor of choice.

Open On Make A package that makes it easy to have the artisan make: commands open the newly created file in your editor of choice. Installation compos

Laravel breeze is a PHP Laravel library that provides Authentication features such as Login page , Register, Reset Password and creating all Sessions Required.

About Laravel breeze To give you a head start building your new Laravel application, we are happy to offer authentication and application starter kits

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel Common Password Validator

laravel-common-password-validator Laravel Common Password Validator An optimized and secure validator to check if a given password is too common. By d

This package gives you a set of conventions to make the most out of Hotwire in Laravel

Introduction This package gives you a set of conventions to make the most out of Hotwire in Laravel (inspired by the turbo-rails gem). There is a comp

This Laravel 8 package makes it possible for you to set your website in
This Laravel 8 package makes it possible for you to set your website in "Under Construction" mode.

Laravel Under Construction This Laravel package makes it possible to set your website in "Under Construction" mode. Only users with the correct 4 digi

Laravel SEO - This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

Comments
  • Set user's email_verified_at after setting password

    Set user's email_verified_at after setting password

    Fixes #3

    Took a crack at implementing it, seems to work for my situation. I didn't write any tests though, would probably be best to do so. The logic is mostly taken from the MustVerifyEmail trait built into the Laravel auth.

    opened by francislavoie 5
  • Tests crash on L7.*

    Tests crash on L7.*

    There were 2 errors:
    1) GlaivePro\Invytr\Tests\Unit\ControllerTest::testSessionVariable
    InvalidArgumentException: Attribute [auth] does not exist.
    /home/travis/build/GlaivePro/Invytr/vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php:92
    /home/travis/build/GlaivePro/Invytr/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1236
    /home/travis/build/GlaivePro/Invytr/vendor/laravel/framework/src/Illuminate/Support/Facades/Auth.php:52
    /home/travis/build/GlaivePro/Invytr/tests/Unit/ControllerTest.php:16
    2) GlaivePro\Invytr\Tests\Unit\ControllerTest::testShowSetForm
    InvalidArgumentException: Attribute [auth] does not exist.
    /home/travis/build/GlaivePro/Invytr/vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php:92
    /home/travis/build/GlaivePro/Invytr/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1236
    /home/travis/build/GlaivePro/Invytr/vendor/laravel/framework/src/Illuminate/Support/Facades/Auth.php:52
    /home/travis/build/GlaivePro/Invytr/tests/Unit/ControllerTest.php:30
    
    opened by tontonsb 1
  • Email not marked as verified after setting password

    Email not marked as verified after setting password

    My assumption was that the user would have email_verified_at set once they've set their password. Since they use the link in the email, they're as good as verified at that point. I'd also like to piggy-back off that field to know when the user accepted the invite and joined.

    Should this be done in handleAfterRedirect of the middleware? Seems like the right place to put it, since the current user should be known at that point.

    opened by francislavoie 0
Releases(1.0.9)
Owner
GlaivePro
GlaivePro
Open source for selling social media accounts or accounts on other platforms.

SELLACC - Open Source Selling Accounts SELLACC is open source for selling social media accounts or accounts on other platforms. ⚠️ We not update sourc

PHAM DUC THANH 6 Nov 17, 2022
This package allows you to render livewire components like a blade component, giving it attributes, slots etc

X-livewire This package allows you to render livewire components like a blade component, giving it attributes, slots etc. Assuming you wanted to creat

null 7 Nov 15, 2022
LERN is a Laravel package that will record exceptions into a database and will notify you via Email, Pushover or Slack.

LERN is a Laravel package that will record exceptions into a database and will notify you via Email, Pushover or Slack.

Tyler Arbon 437 Nov 17, 2022
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Laravel Verify New Email Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When

Protone Media 300 Dec 30, 2022
Laravel Users | A Laravel Users CRUD Management Package

A Users Management Package that includes all necessary routes, views, models, and controllers for a user management dashboard and associated pages for managing Laravels built in user scaffolding. Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6.0, 7.0 and 8.0.

Jeremy Kenedy 393 Nov 28, 2022
Trigger email failures to assert what happens on your Laravel Application when an email fails to send

Laravel Email Failer composer require --dev rogervila/laravel-email-failer About Trigger email failures to assert what happens on your Laravel Applica

Roger Vilà 30 Jul 17, 2022
How to get cookies from users' browser and send the information to your email address and telegram bot

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

MAXWELL 3 Dec 3, 2022
🥳🔐 This package is a Laravel package that checks if an email address is a spammer

This package is a Laravel package that checks if an email address is a spammer. It verifies your signups and form submissions to confirm that they are legitimate.

Endurance, the Martian 15 Dec 19, 2022
A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache.

Laravel OTP Introduction A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache. The ca

Lim Teck Wei 52 Sep 6, 2022
A Laravel URL Shortener package that provides URL redirects with optionally protected URL password, URL expiration, open limits before expiration

A Laravel URL Shortener package that provides URL redirects with optionally protected URL password, URL expiration, open limits before expiration, ability to set feature activation dates, and click tracking out of the box for your Laravel applications.

YorCreative 53 Jan 4, 2023