Download the PHP package seblhaire/specialauth without Composer

On this page you can find all versions of the php package seblhaire/specialauth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package specialauth

Specialauth

By Sébastien L'haire

This library is based on Laravel authentication libraries (login, logout, password reset procedure) provided in Laravel Breeze but does not contain registration process. Instead, application accounts are created by users with administrator rights.

Installation

  1. composer require seblhaire/specialauth
  2. Composer will automatically link the package with Laravel. But you still can explicitely add provider and facade to your config/app.php:

  3. Publish package: php artisan vendor:publish
  4. Config package (cf. below).
  5. See Formsboostrap package documentation to install it and set stylesheets and scripts.
  6. Complete templates.
  7. Apply database migrations.
  8. Adapt notifications.
  9. Create main admin account.
  10. Define user roles and profiles.

    Configuration

Configuration file specialauth

After publishing the package, modifiy file specialauth.php to adapt it for your application. The configuration is accessible through

Mail Configuration

Your application must be able to send mails by using one of the methods on Laravel official documentation.

Kernel.php

In file app/Http/Kernel.php, replace line guest by the following value:

auth.php

In file auth.php, replace value:

Templates

Web pages

After publishing the package, you can use and adapt the layout. You must include Formsboostrap package scripts to use password utilities. Files can be found in resources/views/vendor/specialauth/public.

Email templates

You should also adapt email templates to your application. Templates can be found in resources/views/vendor/specialauth/public/emails. You can define the header and footer for your application. All mails sent by your application can share the same layout. Finally, mail contents can be defined as in public/emails/email.blade.php. Feel free to adapt it to your needs. Mail contents sent by your app are described below.

Database migration

This package comes with a database migration 2014_10_12_000000_specialauth_create_users_table that includes all necessary Laravel migrations. Delete files in your app's database/migrations, since we modifiy Laravel default table structure. Then run php artisan migrate:install. Make sure that roles and profiles and finally run migration with php migrate --seed --seeder=UsersTableSeeder to create and fill tables. Later you will need create your first user.

Notifications

Our package uses two notification classes for two processes. The first one is usual password reset notification that sends a link to an user who has forgotten his/her password which allows to define a new password. The second sends a link to the same procedure, but it is send to users newly created by a website administrator.

Notification \Seblhaire\Specialauth\ResetPasswordNotification extends \Illuminate\Auth\Notifications\ResetPassword. It overloads method buildMailMessage that creates and returns an instance of \Illuminate\Notifications\Messages\MailMessage. Theme is the css template stored in resources/views/vendor/specialauth/pubic/emails/themes and markdown template in resources/views/vendor/specialauth/pubic/emails. If you need change this notification, define your own notification class in /App/Notification namespace. Refer to Laravel documentation to know how to format a notification mail.

Notification \Seblhaire\Specialauth\CreatePasswordNotification also extends \Illuminate\Auth\Notifications\ResetPassword, but extends more methods to customize mail. If you want to create your own notification class, we suggest that you extend our package class and rewrite method buildMailMessage.

You can use template and theme in other notification of your app.

Create main admin account

This package is designed for applications where users can not sign up to access to admin console, but must be invited by an administrator. When installing an app, you should create your webmaster account. In this package, we give an example file Createmainuser.php that you can adapt to your need and place in your app commands directory. Usually this command should be run only once. Then forms and routes in your application should be used to create users, using the same principles as in the command class.

User roles and profile

The package modifies default Laravel user model and adds role and profile tables. Model \Seblhaire\Specialauth\Models\User uses Laravel standard traits and adds Eloquent relationships to the Role and Profile model. If your app needs more relationships, such as links to logs, you can extend our User model.

Profile

You must first add profile names to the profiles table, such as skin to choose between themes, table_max_element to get the user favorite element number in a table, etc. When you create your app, you can define profiles items in seed them into the database. You can add new profiles to new versions of your app or do it in your app.

Profiles are attached to user through table profile_user. Profile value is stored in jsonvals pivot value. You just have to store a JSON object such as {"val": 20}, or more complex object structures.

Profiles can be attached to users with $user->profiles()->attach(1, ['jsonvals' => '{"val":' . config('tablebuilder.table.itemsperpage') . '}']) where value 1 refers to the id of the profile value in table profiles. The config value here refers to default table size value in package TableBuilder. To change this value, we suggest to first detach value with $user->roles()->detach(1); and attach new value.

If you need to access a profile value of the current user, use \Auth::user()->profile('table_max_element')->val to retrieve the value of this profile item.

Roles

First of all, you should define precisely differents roles for your app users. Usually, apps define super users who can run all actions and ordinary users that only can do ordinary tasks. But you can define more roles. When creating your application, database migrations chapter shows you how to automatically insert your app roles. However, when updating your app you can easily create new roles, or your app could also allow users to insert new roles.

Users should have at least one role, but table structure allows users to have several roles.

To assign a role to a user, use $user->roles()->attach(1) to attach role with id 1 in table roles. To update roles, first detach all roles with $user->roles()->detach() and re-attach updated list.

If you need to know if a user has a role, use $user->hasRole('administrator').

Then you must define how to use roles in your app.

Policies

Policies define conditions that must be met to allow actions that you can use in controllers. For eample, to update a user, your must either be this user or have adminstrator role. To display information on a user, you must be this user.

First, you must create a policy class:

Define policies as in this example and then use for example this method to refuse user update.

Dont' forget to register your policies in a Service provider file like this one. In this example, we also add Laravel gate rules that cas for example be used by a route middleware like this one.

Logout

Route to logout procedure is accessible with the POST method.

  1. Insert a link for the logout procedure, in a menu for example:

  2. Insert a hidden form that posts to your logout route.

  3. Submit the hidden form with your link. Here is an example that uses jQuery library.

All versions of specialauth with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
illuminate/http Version ^10.0|^11.0
seblhaire/formsbootstrap Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package seblhaire/specialauth contains the following files

Loading the files please wait ....