2017 © Pedro Peláez
 

library confide-mongo

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

image

zizaco/confide-mongo

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  • Sunday, September 10, 2017
  • by Zizaco
  • Repository
  • 8 Watchers
  • 32 Stars
  • 13,045 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 0 Open issues
  • 16 Versions
  • 1 % Grown

The README.md

Confide Mongo (Laravel4 Package)

Confide Poster, (*1)

Build Status ProjectStatus, (*2)

Confide is a authentication solution for Laravel4 using MongoLid made to eliminate repetitive tasks involving the management of users: Account creation, login, logout, confirmation by e-mail, password reset, etc., (*3)

Confide aims to be simple to use, quick to configure and flexible., (*4)

Note: If you are NOT using MongoDB check Confide., (*5)

Features

Current: - Account confirmation (through confirmation link). - Password reset (sending email with a change password link). - Easily render forms for login, signup and password reset. - Generate customizable routes for login, signup, password reset, confirmation, etc. - Generate a customizable controller that handles the basic user account actions. - Contains a set of methods to help basic user features. - Integrated with the Laravel Auth component/configs. - Field/model validation. - Login throttling. - Redirecting to previous route after authentication., (*6)

If you are looking for user roles and permissions see Entrust, (*7)

Planned: - Captcha in user signup and password reset. - General improvements., (*8)

Quick start

Required setup

In the require key of composer.json file add the following, (*9)

"zizaco/confide-mongo": "dev-master"

Run the Composer update comand, (*10)

$ composer update

In your config/app.php add 'Zizaco\ConfideMongo\ConfideMongoServiceProvider' to the end of the $providers array, (*11)

'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'Zizaco\ConfideMongo\ConfideMongoServiceProvider',

),

At the end of config/app.php add 'Confide' => 'Zizaco\Confide\ConfideFacade' to the $aliases array, (*12)

'aliases' => array(

    'App'        => 'Illuminate\Support\Facades\App',
    'Artisan'    => 'Illuminate\Support\Facades\Artisan',
    ...
    'Confide'    => 'Zizaco\Confide\ConfideFacade',

),

Configuration

Set the driver to "mongoLid" in config/auth.php as stated in MongoLid Authentication:, (*13)

    ...

    'driver' => 'mongoLid',

    ...

This values contained in config/auth.php will be used by Confide Mongo to generate the controllers and routes., (*14)

Set the address and name from the from array in config/mail.php. Those will be used to send account confirmation and password reset emails to the users., (*15)

User model

Change your User model in app/models/User.php to:, (*16)

<?php

use Zizaco\ConfideMongo\ConfideMongoUser;

class User extends ConfideMongoUser {

}

ConfideMongoUser class will take care of some behaviors of the user model., (*17)

Dump the default acessors

Least, you can dump a default controller and the default routes for Confide., (*18)

$ php artisan confide:controller
$ php artisan confide:routes

Don't forget to dump composer autoload, (*19)

$ composer dump-autoload

And you are ready to go. Access http://yourapp/user/create to create your first user. Check the app/routes.php to see the available routes., (*20)

Usage in detail

Basic setup:, (*21)

  1. Mongo database connection in config/database.php running properly.
  2. Set the auth driver to "mongoLid" in config/auth.php.
  3. Check and correct the model and collection names in config/auth.php. They will be used by Confide all the time.
  4. from configuration in config/mail.php.

Configuration:, (*22)

  1. ConfideMongoServiceProvider and ConfideFacade entry in config/app.php 'providers' and 'aliases' respectively.
  2. User model (with the same name as in config/auth.php) should extend ConfideMongoUser class. This will cause to methods like resetPassword(), confirm() and a overloaded save() to be available.

Optional steps:, (*23)

  1. Use Confide facade to dump login and signup forms easly with makeLoginForm() and makeSignupForm(). You can render the forms within your views by doing {{ Confide::makeLoginForm()->render() }}.
  2. Generate a controller with the template contained in Confide throught the artisan command $ php artisan confide:controller. If a controller with the same name exists it will NOT be overwritten.
  3. Generate routes matching the controller template throught the artisan command $ php artisan confide:routes. Your routes.php will NOT be overwritten.

Advanced

Using custom collection / model name

You can change the model name that will be authenticated in the config/auth.php file. Confide uses the values present in that configuration file., (*24)

To change the controller name when dumping the default controller template you can use the --name option., (*25)

$ php artisan confide:controller --name Employee

Will result in EmployeeController, (*26)

Then, when dumping the routes, you should use the --controller option to match the existing controller., (*27)

$ php artisan confide:routes --controller Employee

Using custom form or emails

First, publish the config files:, (*28)

$ php artisan config:publish zizaco/confide

Then edit the view names in app/config/packages/zizaco/confide/config.php., (*29)

Update an User

To update an user already in the database you'll want to either pass in an different rule set or use the amend function., (*30)

$user = new User;
$user->username = 'newUserName';

// Save
$user->save($this->getUpdateRules());

Validate model fields

To change the validation rules of the User model you can take a look at Laravel 4 Validations. For example:, (*31)

<?php

use Zizaco\ConfideMongo\ConfideMongoUser;

class User extends ConfideMongoUser {

    /**
     * Validation rules
     */
    public static $rules = array(
        'email' => 'required|email',
        'password' => 'required|between:4,11|confirmed',
    );

}

Feel free to add more fields to your collection and to the validation array. Then you should build your own sign-up form with the additional fields., (*32)

Passing additional information to the make methods

If you want to pass additional parameters to the forms, you can use an alternate syntax to achieve this., (*33)

Instead of using the make method:, (*34)

Confide::makeResetPasswordForm( $token ):

You would use:, (*35)

View::make(Config::get('confide::reset_password_form'))
    ->with('token', $token);

It produces the same output, but you would be able to add more inputs using 'with' just like any other view., (*36)

RESTful controller

If you want to generate a RESTful controller you can use the aditional --restful or -r option., (*37)

$ php artisan confide:controller --restful

Will result in a RESTful controller, (*38)

Then, when dumping the routes, you should use the --restful option to match the existing controller., (*39)

$ php artisan confide:routes --restful

User roles and permissions

In order not to bloat Confide with not related features, the role and permission was developed as another package: Entrust. This package couples very well with Confide., (*40)

See Entrust, (*41)

Note: Entrust is not yet available for MongoLid / MongoDB, (*42)

Redirecting to previous route after login

When defining your filter you should set the 'loginRedirect' session variable. For example:, (*43)

// filters.php

Route::filter('auth', function()
{
    if ( Auth::guest() ) // If the user is not logged in
    {
        // Set the loginRedirect session variable
        Session::put( 'loginRedirect', Request::url() );

        // Redirect back to user login
        return Redirect::to( 'user/login' );
    }
});

// Only authenticated users will be able to access routes that begins with
// 'admin'. Ex: 'admin/posts', 'admin/categories'.
Route::when('admin*', 'auth'); 

or, if you are using Entrust ;), (*44)

// filters.php

Entrust::routeNeedsRole( 'admin*', 'Admin', function(){
    Session::put( 'loginRedirect', Request::url() );
    return Redirect::to( 'user/login' );
} );

Validating a route

If you want to validate whether a route exists, the Confide::checkAction function is what you are looking for., (*45)

Currently it is used within the views to determine Non-RESTful vs RESTful routes., (*46)

Troubleshooting

"'confirmation_code' required" when creating a user, (*47)

If you overwrite the save() method in your model, make sure to call parent::save():, (*48)

public function save( $forced = false ){

    parent::save( $forced) // Don't forget this

    // Your stuff
}

Confirmation link is not sent when user signup, (*49)

If you overwrite the afterSave() method in your model, make sure to call parent::afterSave(), (*50)

Users are able to login without confirming account, (*51)

If you want only confirmed users to login, in your UserController, instead of simply calling logAttempt( $input ), call logAttempt( $input, true ). The second parameter stands for "confirmed_only"., (*52)

License

Confide is free software distributed under the terms of the MIT license, (*53)

Aditional information

Any questions, feel free to contact me or ask here, (*54)

Any issues, please report here, (*55)

The Versions

10/09 2017

dev-develop

dev-develop

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

06/09 2017

v0.16.2

0.16.2.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

16/08 2017

v0.16.1

0.16.1.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

09/06 2017

v0.16.0

0.16.0.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

15/05 2017

v0.15.0

0.15.0.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

15/05 2017

v0.14.4

0.14.4.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

27/03 2017

v0.14.3

0.14.3.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

27/03 2017

v0.14.2

0.14.2.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

14/12 2016

v0.13.2

0.13.2.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

09/12 2016

v0.14.1

0.14.1.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

18/08 2016

v0.14.0

0.14.0.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

21/07 2016

v0.13.1

0.13.1.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

30/06 2016

v0.13.0

0.13.0.0

Confide Mongo is a authentication solution for Laravel that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

29/01 2016

v0.12

0.12.0.0

Confide Mongo is a authentication solution for Laravel 4 that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

28/08 2015

dev-master

9999999-dev

Confide Mongo is a authentication solution for Laravel 4 that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate

03/06 2013

v0.11beta

0.11.0.0-beta

Confide Mongo is a authentication solution for Laravel 4 that uses mongolid-laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel auth illuminate