Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
992a9ff7
Commit
992a9ff7
authored
Aug 09, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak password reminders, fixes #271
parent
e527c5d6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
64 deletions
+97
-64
DatabaseReminderRepository.php
src/Jenssegers/Mongodb/Auth/DatabaseReminderRepository.php
+29
-3
AuthTest.php
tests/AuthTest.php
+60
-0
TestCase.php
tests/TestCase.php
+4
-1
User.php
tests/models/User.php
+4
-60
No files found.
src/Jenssegers/Mongodb/Auth/DatabaseReminderRepository.php
View file @
992a9ff7
<?php
namespace
Jenssegers\Mongodb\Auth
;
use
DateTime
;
use
MongoDate
;
class
DatabaseReminderRepository
extends
\Illuminate\Auth\Reminders\DatabaseReminderRepository
{
/**
* Build the record payload for the table.
*
* @param string $email
* @param string $token
* @return array
*/
protected
function
getPayload
(
$email
,
$token
)
{
return
array
(
'email'
=>
$email
,
'token'
=>
$token
,
'created_at'
=>
new
MongoDate
);
}
/**
* Determine if the reminder has expired.
*
...
...
@@ -16,10 +31,21 @@ class DatabaseReminderRepository extends \Illuminate\Auth\Reminders\DatabaseRemi
$reminder
=
(
array
)
$reminder
;
}
// Convert the DateTime object that got saved to MongoDB
if
(
is_array
(
$reminder
[
'created_at'
]))
// Convert MongoDate to a date string.
if
(
$reminder
[
'created_at'
]
instanceof
MongoDate
)
{
$date
=
new
DateTime
();
$date
->
setTimestamp
(
$reminder
[
'created_at'
]
->
sec
);
$reminder
[
'created_at'
]
=
$date
->
format
(
'Y-m-d H:i:s'
);
}
// DEPRECATED: Convert DateTime to a date string.
elseif
(
is_array
(
$reminder
[
'created_at'
]))
{
$reminder
[
'created_at'
]
=
$reminder
[
'created_at'
][
'date'
]
+
$reminder
[
'created_at'
][
'timezone'
];
$date
=
DateTime
::
__set_state
(
$reminder
[
'created_at'
]);
$reminder
[
'created_at'
]
=
$date
->
format
(
'Y-m-d H:i:s'
);
}
return
parent
::
reminderExpired
(
$reminder
);
...
...
tests/AuthTest.php
0 → 100644
View file @
992a9ff7
<?php
class
AuthTest
extends
TestCase
{
public
function
tearDown
()
{
User
::
truncate
();
DB
::
collection
(
'password_reminders'
)
->
truncate
();
}
public
function
testAuthAttempt
()
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'email'
=>
'john@doe.com'
,
'password'
=>
Hash
::
make
(
'foobar'
)
));
$this
->
assertTrue
(
Auth
::
attempt
(
array
(
'email'
=>
'john@doe.com'
,
'password'
=>
'foobar'
),
true
));
$this
->
assertTrue
(
Auth
::
check
());
}
public
function
testRemind
()
{
$mailer
=
Mockery
::
mock
(
'Illuminate\Mail\Mailer'
);
$this
->
app
->
instance
(
'mailer'
,
$mailer
);
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'email'
=>
'john@doe.com'
,
'password'
=>
Hash
::
make
(
'foobar'
)
));
$mailer
->
shouldReceive
(
'send'
)
->
once
();
Password
::
remind
(
array
(
'email'
=>
'john@doe.com'
));
$this
->
assertEquals
(
1
,
DB
::
collection
(
'password_reminders'
)
->
count
());
$reminder
=
DB
::
collection
(
'password_reminders'
)
->
first
();
$this
->
assertEquals
(
'john@doe.com'
,
$reminder
[
'email'
]);
$this
->
assertNotNull
(
$reminder
[
'token'
]);
$this
->
assertInstanceOf
(
'MongoDate'
,
$reminder
[
'created_at'
]);
$credentials
=
array
(
'email'
=>
'john@doe.com'
,
'password'
=>
'foobar'
,
'password_confirmation'
=>
'foobar'
,
'token'
=>
$reminder
[
'token'
]
);
$response
=
Password
::
reset
(
$credentials
,
function
(
$user
,
$password
)
{
$user
->
password
=
Hash
::
make
(
$password
);
$user
->
save
();
});
$this
->
assertEquals
(
'reminders.reset'
,
$response
);
$this
->
assertEquals
(
0
,
DB
::
collection
(
'password_reminders'
)
->
count
());
}
}
tests/TestCase.php
View file @
992a9ff7
...
...
@@ -9,7 +9,10 @@ class TestCase extends Orchestra\Testbench\TestCase {
*/
protected
function
getPackageProviders
()
{
return
array
(
'Jenssegers\Mongodb\MongodbServiceProvider'
);
return
array
(
'Jenssegers\Mongodb\MongodbServiceProvider'
,
'Jenssegers\Mongodb\Auth\ReminderServiceProvider'
,
);
}
/**
...
...
tests/models/User.php
View file @
992a9ff7
...
...
@@ -2,11 +2,15 @@
use
Jenssegers\Mongodb\Model
as
Eloquent
;
use
Illuminate\Auth\UserTrait
;
use
Illuminate\Auth\UserInterface
;
use
Illuminate\Auth\Reminders\RemindableTrait
;
use
Illuminate\Auth\Reminders\RemindableInterface
;
class
User
extends
Eloquent
implements
UserInterface
,
RemindableInterface
{
use
UserTrait
,
RemindableTrait
;
protected
$dates
=
array
(
'birthday'
,
'entry.date'
);
protected
static
$unguarded
=
true
;
...
...
@@ -60,66 +64,6 @@ class User extends Eloquent implements UserInterface, RemindableInterface {
return
$this
->
embedsOne
(
'User'
);
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public
function
getAuthIdentifier
()
{
return
$this
->
getKey
();
}
/**
* Get the password for the user.
*
* @return string
*/
public
function
getAuthPassword
()
{
return
$this
->
password
;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public
function
getReminderEmail
()
{
return
$this
->
email
;
}
/**
* Get the token value for the "remember me" session.
*
* @return string
*/
public
function
getRememberToken
()
{
return
$this
->
rememberToken
;
}
/**
* Set the token value for the "remember me" session.
*
* @param string $value
* @return void
*/
public
function
setRememberToken
(
$value
)
{
$this
->
rememberToken
=
$value
;
}
/**
* Get the column name for the "remember me" token.
*
* @return string
*/
public
function
getRememberTokenName
()
{
return
'remember_token'
;
}
protected
function
getDateFormat
()
{
return
'l jS \of F Y h:i:s A'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment