Skip to content

Commit ad2e69b

Browse files
committed
Adding support for mongodb password reminders, fixes #37
1 parent ad9dc56 commit ad2e69b

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ Supported operations are:
127127

128128
Read more about the schema builder on http://laravel.com/docs/schema
129129

130+
Auth
131+
----
132+
133+
If you want to use Laravel's native Auth functionality, register this included service provider:
134+
135+
'Jenssegers\Mongodb\Auth\ReminderServiceProvider',
136+
137+
This service provider will slightly modify the internal DatabaseReminderRepository to add support for MongoDB based password reminders. If you don't use password reminders, you don't have to register this service provider and everything else should work just fine.
138+
130139
Sessions
131140
--------
132141

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php namespace Jenssegers\Mongodb\Auth;
2+
3+
class DatabaseReminderRepository extends \Illuminate\Auth\Reminders\DatabaseReminderRepository {
4+
5+
/**
6+
* Determine if the reminder has expired.
7+
*
8+
* @param object $reminder
9+
* @return bool
10+
*/
11+
protected function reminderExpired($reminder)
12+
{
13+
// Convert to object so that we can pass it to the parent method
14+
if (is_array($reminder))
15+
{
16+
$reminder = (object) $reminder;
17+
}
18+
19+
// Convert the DateTime object that got saved to MongoDB
20+
if (is_array($reminder->created_at))
21+
{
22+
$reminder->created_at = $reminder->created_at['date'] + $reminder->created_at['timezone'];
23+
}
24+
25+
return parent::reminderExpired($reminder);
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php namespace Jenssegers\Mongodb\Auth;
2+
3+
use Jenssegers\Mongodb\Auth\DatabaseReminderRepository as DbRepository;
4+
5+
class ReminderServiceProvider extends \Illuminate\Auth\Reminders\ReminderServiceProvider {
6+
7+
/**
8+
* Register the reminder repository implementation.
9+
*
10+
* @return void
11+
*/
12+
protected function registerReminderRepository()
13+
{
14+
$this->app->bindShared('auth.reminder.repository', function($app)
15+
{
16+
$connection = $app['db']->connection();
17+
18+
// The database reminder repository is an implementation of the reminder repo
19+
// interface, and is responsible for the actual storing of auth tokens and
20+
// their e-mail addresses. We will inject this table and hash key to it.
21+
$table = $app['config']['auth.reminder.table'];
22+
23+
$key = $app['config']['app.key'];
24+
25+
$expire = $app['config']->get('auth.reminder.expire', 60);
26+
27+
return new DbRepository($connection, $table, $key, $expire);
28+
});
29+
}
30+
31+
}

src/Jenssegers/Mongodb/MongodbServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ public function register()
3131
});
3232
}
3333

34-
}
34+
}

0 commit comments

Comments
 (0)