项目作者: EscolaLMS

项目描述 :
Package for user authentication. Roles & Permission Management
高级语言: PHP
项目地址: git://github.com/EscolaLMS/Auth.git
创建时间: 2021-03-08T13:29:06Z
项目社区:https://github.com/EscolaLMS/Auth

开源协议:

下载


Auth

swagger
codecov
phpunit
downloads
downloads
downloads
Maintainability
Mutation testing badge

What does it do

Package for user authentication. In addition, the package includes:

  • user management,
  • group management,
  • profile management,
  • registration.

Installing

  • composer require escolalms/auth
  • php artisan migrate
  • php artisan db:seed --class="EscolaLms\Auth\Database\Seeders\AuthPermissionSeeder"

Optional:

  • Run command escolalms:admin.

Commands

  • escolalms:admin - create account with role admin

Database

  1. category_user - Table is used to store the user categories.
  2. groups - Table for storing groups.
  3. group_user - Table for storing groups assigned to the user.
  1. User 1 -> n Categories
  2. User 1 -> n Groups

Endpoints

All the endpoints are defined in swagger

Tests

Run ./vendor/bin/phpunit to run tests.
phpunit
codecov

Events

  • AccountBlocked - Event is dispatched after blocking the user’s account (is_active=false).
  • AccountConfirmed - Event is dispatched after the user verifies the account.
  • AccountDeleted - Event is dispatched after deleting the user.
  • AccountMustBeEnableByAdmin - Event is dispatched when the user registers and Config::get('escola_auth.account_must_be_enabled_by_admin') === SettingStatusEnum::ENABLED
  • AccountRegistered - Event is dispatched after the account is registered.
  • ForgotPassword - Event is dispatched when a password reset request is sent.
  • Login - Event is dispatched on successful login.
  • Logout - Event is dispatched after logout.
  • PasswordChanged - Event is dispatched after the password changed.
  • ResetPassword - Event is dispatched after resetting the password.
  • UserAddedToGroup - Event is dispatched after adding the user to the group.
  • UserRemovedFromGroup - Event is dispatched after removing the user from the group.

Listeners

  • CreatePasswordResetToken - The listener listens for the ForgotPassword event and executes the following method.

    1. public function handle(ForgotPassword $event): void
    2. {
    3. if (!is_callable(self::getRunEventForgotPassword()) || self::getRunEventForgotPassword()()) {
    4. $user = $event->getUser();
    5. $this->userRepository->update([
    6. 'password_reset_token' => Str::random(32),
    7. ], $user->getKey());
    8. $user->refresh();
    9. $user->notify(new ResetPassword($user->password_reset_token, $event->getReturnUrl()));
    10. }
    11. }

This is useful if you are using TemplateEmail and you don’t want to send the default e-mails.

  1. CreatePasswordResetToken::setRunEventForgotPassword(
  2. function () {
  3. $templateRepository = app(TemplateRepositoryContract::class);
  4. return empty($templateRepository->findTemplateDefault(
  5. ForgotPassword::class,
  6. EmailChannel::class
  7. ));
  8. }
  9. );
  • SendEmailVerificationNotification - The listener listens for the AccountRegistered event and executes the following method.
    1. public function handle(Registered $event)
    2. {
    3. if (!is_callable(self::getRunEventEmailVerification()) || self::getRunEventEmailVerification()()) {
    4. if ($event->user instanceof MustVerifyEmail && !$event->user->hasVerifiedEmail()) {
    5. $event->user->sendEmailVerificationNotification();
    6. }
    7. }
    8. }

How to use this on frontend

Admin panel

List of users
List of users

Creating/editing user
Creating/editing user

User categories
User categories

List of groups
List of groups

Creating/editing group
Creating/editing group

My profile
My profile

Permissions

Permissions are defined in seeder.