Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #13 from ollieread/dev
Browse files Browse the repository at this point in the history
Merging in reminders
  • Loading branch information
Ollie Read committed Feb 21, 2014
2 parents f720575 + 347bcc1 commit 6c9dfe0
Show file tree
Hide file tree
Showing 10 changed files with 675 additions and 6 deletions.
51 changes: 46 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Firstly you want to include this package in your composer.json file.

Next you open up app/config/app.php and replace the AuthServiceProvider with

Ollieread\Multiauth\MultiauthServiceProvider
"Ollieread\Multiauth\MultiauthServiceProvider"

Configuration is pretty easy too, take app/config/auth.php with its default values:

Expand Down Expand Up @@ -79,6 +79,51 @@ Now remove the first three options and replace as follows:

);

## Reminders ##

If you wish to use reminders, you will need to replace ReminderServiceProvider in you
app/config/app.php file with the following.

Ollieread\Multiauth\Reminders\ReminderServiceProvider

To generate the reminders table you will need to run the following command.

php artisan multiauth:reminders-table

The `reminders-controller` command has been removed, as it wouldn't work with the
way this package handles authentication. I do plan to look into this in the future.

The concept is the same as the default Auth reminders, except you access everything
the same way you do using the rest of this package, in that prefix methods with the
authentication type.

To send a reminder you would do the following.

Password::account()->remind(Input::only('email'), function($message) {
$message->subject('Password reminder');
});

And to reset a password you would do the following.

Password::account()->reset($credentials, function($user, $password) {
$user->password = Hash::make($password);
$user->save();
});

For simple identification of which token belongs to which user, as it's perfectly feasible
that we could have two different users, of different types, with the same token, I've modified my reminder
email to have a type attribute.

To reset your password, complete this form: {{ URL::to('password/reset', array($type, $token)) }}.

This generates a URL like the following.

http://laravel.ollieread.com/password/reset/account/27eb8fe5fe666b3b8d0521156bbf53266dbca572

Which matches the following route.

Route::any('/password/reset/{type}/{token}', 'Controller@method');


## Usage ##

Expand Down Expand Up @@ -116,10 +161,6 @@ And so on and so forth.

There we go, done! Enjoy yourselves.

## Known Bugs ##

Reminders don't currently work.

### License

This package inherits the licensing of its parent framework, Laravel, and as such is open-sourced
Expand Down
94 changes: 94 additions & 0 deletions src/Ollieread/Multiauth/Console/RemindersTableCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php namespace Ollieread\Multiauth\Console;

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;

class RemindersTableCommand extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'multiauth:reminders-table';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a migration for the password reminders table';

/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;

/**
* Create a new reminder table command instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @return void
*/
public function __construct(Filesystem $files)
{
parent::__construct();

$this->files = $files;
}

/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$fullPath = $this->createBaseMigration();

$this->files->put($fullPath, $this->getMigrationStub());

$this->info('Migration created successfully!');

$this->call('dump-autoload');
}

/**
* Create a base migration file for the reminders.
*
* @return string
*/
protected function createBaseMigration()
{
$name = 'create_password_reminders_table';

$path = $this->laravel['path'].'/database/migrations';

return $this->laravel['migration.creator']->create($name, $path);
}

/**
* Get the contents of the reminder migration stub.
*
* @return string
*/
protected function getMigrationStub()
{
$stub = $this->files->get(__DIR__.'/stubs/reminders.stub');

return str_replace('password_reminders', $this->getTable(), $stub);
}

/**
* Get the password reminder table name.
*
* @return string
*/
protected function getTable()
{
return $this->laravel['config']->get('auth.reminder.table');
}

}
34 changes: 34 additions & 0 deletions src/Ollieread/Multiauth/Console/stubs/reminders.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePasswordRemindersTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_reminders', function(Blueprint $table)
{
$table->string('type')->index();
$table->string('email')->index();
$table->string('token')->index();
$table->timestamp('created_at');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('password_reminders');
}

}
2 changes: 1 addition & 1 deletion src/Ollieread/Multiauth/MultiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct($app) {
}
}

public function __call($name, $arguments) {
public function __call($name, $arguments = array()) {
if(array_key_exists($name, $this->providers)) {
return $this->providers[$name];
}
Expand Down
1 change: 1 addition & 0 deletions src/Ollieread/Multiauth/MultiauthServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Ollieread\Multiauth;

use Illuminate\Support\ServiceProvider;
use Ollieread\Multiauth\Console\RemindersTableCommand;

class MultiauthServiceProvider extends ServiceProvider {

Expand Down
Loading

0 comments on commit 6c9dfe0

Please sign in to comment.