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
698e166b
Commit
698e166b
authored
Jan 11, 2015
by
duxet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix auth and password resetting
parent
6d7aa1dc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
51 deletions
+89
-51
DatabaseTokenRepository.php
src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
+41
-0
PasswordResetServiceProvider.php
src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php
+27
-0
AuthTest.php
tests/AuthTest.php
+13
-43
TestCase.php
tests/TestCase.php
+2
-2
User.php
tests/models/User.php
+6
-6
No files found.
src/Jenssegers/Mongodb/Auth/Database
Reminder
Repository.php
→
src/Jenssegers/Mongodb/Auth/Database
Token
Repository.php
View file @
698e166b
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
use
DateTime
;
use
DateTime
;
use
MongoDate
;
use
MongoDate
;
class
Database
ReminderRepository
extends
\Illuminate\Auth\Reminders\DatabaseReminder
Repository
{
class
Database
TokenRepository
extends
\Illuminate\Auth\Passwords\DatabaseToken
Repository
{
/**
/**
* Build the record payload for the table.
* Build the record payload for the table.
...
@@ -14,36 +14,28 @@ class DatabaseReminderRepository extends \Illuminate\Auth\Reminders\DatabaseRemi
...
@@ -14,36 +14,28 @@ class DatabaseReminderRepository extends \Illuminate\Auth\Reminders\DatabaseRemi
*/
*/
protected
function
getPayload
(
$email
,
$token
)
protected
function
getPayload
(
$email
,
$token
)
{
{
return
array
(
'email'
=>
$email
,
'token'
=>
$token
,
'created_at'
=>
new
MongoDate
)
;
return
[
'email'
=>
$email
,
'token'
=>
$token
,
'created_at'
=>
new
MongoDate
]
;
}
}
/**
/**
* Determine if the
reminder
has expired.
* Determine if the
token
has expired.
*
*
* @param
object $reminder
* @param
array $token
* @return bool
* @return bool
*/
*/
protected
function
reminderExpired
(
$reminder
)
protected
function
tokenExpired
(
$token
)
{
{
// Convert MongoDate to a date string.
// Convert MongoDate to a date string.
if
(
$
reminder
[
'created_at'
]
instanceof
MongoDate
)
if
(
$
token
[
'created_at'
]
instanceof
MongoDate
)
{
{
$date
=
new
DateTime
;
$date
=
new
DateTime
;
$date
->
setTimestamp
(
$
reminder
[
'created_at'
]
->
sec
);
$date
->
setTimestamp
(
$
token
[
'created_at'
]
->
sec
);
$
reminder
[
'created_at'
]
=
$date
->
format
(
'Y-m-d H:i:s'
);
$
token
[
'created_at'
]
=
$date
->
format
(
'Y-m-d H:i:s'
);
}
}
// Convert DateTime to a date string (backwards compatibility).
return
parent
::
tokenExpired
(
$token
);
elseif
(
is_array
(
$reminder
[
'created_at'
]))
{
$date
=
DateTime
::
__set_state
(
$reminder
[
'created_at'
]);
$reminder
[
'created_at'
]
=
$date
->
format
(
'Y-m-d H:i:s'
);
}
return
parent
::
reminderExpired
(
$reminder
);
}
}
}
}
src/Jenssegers/Mongodb/Auth/
Reminder
ServiceProvider.php
→
src/Jenssegers/Mongodb/Auth/
PasswordReset
ServiceProvider.php
View file @
698e166b
<?php
namespace
Jenssegers\Mongodb\Auth
;
<?php
namespace
Jenssegers\Mongodb\Auth
;
use
Jenssegers\Mongodb\Auth\Database
Reminder
Repository
as
DbRepository
;
use
Jenssegers\Mongodb\Auth\Database
Token
Repository
as
DbRepository
;
class
ReminderServiceProvider
extends
\Illuminate\Auth\Reminders\Reminder
ServiceProvider
{
class
PasswordResetServiceProvider
extends
\Illuminate\Auth\Passwords\PasswordReset
ServiceProvider
{
/**
/**
* Register the
reminder
repository implementation.
* Register the
token
repository implementation.
*
*
* @return void
* @return void
*/
*/
protected
function
register
Reminder
Repository
()
protected
function
register
Token
Repository
()
{
{
$this
->
app
->
bindShared
(
'auth.reminder.repository
'
,
function
(
$app
)
$this
->
app
->
singleton
(
'auth.password.tokens
'
,
function
(
$app
)
{
{
$connection
=
$app
[
'db'
]
->
connection
();
$connection
=
$app
[
'db'
]
->
connection
();
// The database token repository is an implementation of the token repository
// The database reminder repository is an implementation of the reminder repo
// interface, and is responsible for the actual storing of auth tokens and
// interface, and is responsible for the actual storing of auth tokens and
// their e-mail addresses. We will inject this table and hash key to it.
// their e-mail addresses. We will inject this table and hash key to it.
$table
=
$app
[
'config'
][
'auth.reminder.table'
];
$table
=
$app
[
'config'
][
'auth.password.table'
];
$key
=
$app
[
'config'
][
'app.key'
];
$key
=
$app
[
'config'
][
'app.key'
];
$expire
=
$app
[
'config'
]
->
get
(
'auth.password.expire'
,
60
);
$expire
=
$app
[
'config'
]
->
get
(
'auth.reminder.expire'
,
60
);
return
new
DbRepository
(
$connection
,
$table
,
$key
,
$expire
);
return
new
DbRepository
(
$connection
,
$table
,
$key
,
$expire
);
});
});
}
}
...
...
tests/AuthTest.php
View file @
698e166b
<?php
<?php
use
Illuminate\Auth\Passwords\PasswordBroker
;
class
AuthTest
extends
TestCase
{
class
AuthTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
...
@@ -23,7 +25,10 @@ class AuthTest extends TestCase {
...
@@ -23,7 +25,10 @@ class AuthTest extends TestCase {
public
function
testRemind
()
public
function
testRemind
()
{
{
$mailer
=
Mockery
::
mock
(
'Illuminate\Mail\Mailer'
);
$mailer
=
Mockery
::
mock
(
'Illuminate\Mail\Mailer'
);
$this
->
app
->
instance
(
'mailer'
,
$mailer
);
$tokens
=
$this
->
app
->
make
(
'auth.password.tokens'
);
$users
=
$this
->
app
[
'auth'
]
->
driver
()
->
getProvider
();
$broker
=
new
PasswordBroker
(
$tokens
,
$users
,
$mailer
,
''
);
$user
=
User
::
create
(
array
(
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'name'
=>
'John Doe'
,
...
@@ -32,10 +37,10 @@ class AuthTest extends TestCase {
...
@@ -32,10 +37,10 @@ class AuthTest extends TestCase {
));
));
$mailer
->
shouldReceive
(
'send'
)
->
once
();
$mailer
->
shouldReceive
(
'send'
)
->
once
();
Password
::
remind
(
array
(
'email'
=>
'john@doe.com'
));
$broker
->
sendResetLink
(
array
(
'email'
=>
'john@doe.com'
));
$this
->
assertEquals
(
1
,
DB
::
collection
(
'password_re
minder
s'
)
->
count
());
$this
->
assertEquals
(
1
,
DB
::
collection
(
'password_re
set
s'
)
->
count
());
$reminder
=
DB
::
collection
(
'password_re
minder
s'
)
->
first
();
$reminder
=
DB
::
collection
(
'password_re
set
s'
)
->
first
();
$this
->
assertEquals
(
'john@doe.com'
,
$reminder
[
'email'
]);
$this
->
assertEquals
(
'john@doe.com'
,
$reminder
[
'email'
]);
$this
->
assertNotNull
(
$reminder
[
'token'
]);
$this
->
assertNotNull
(
$reminder
[
'token'
]);
$this
->
assertInstanceOf
(
'MongoDate'
,
$reminder
[
'created_at'
]);
$this
->
assertInstanceOf
(
'MongoDate'
,
$reminder
[
'created_at'
]);
...
@@ -47,49 +52,14 @@ class AuthTest extends TestCase {
...
@@ -47,49 +52,14 @@ class AuthTest extends TestCase {
'token'
=>
$reminder
[
'token'
]
'token'
=>
$reminder
[
'token'
]
);
);
$response
=
Password
::
reset
(
$credentials
,
function
(
$user
,
$password
)
$response
=
$broker
->
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
());
}
public
function
testDeprecatedRemind
()
{
$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'
));
DB
::
collection
(
'password_reminders'
)
->
update
(
array
(
'created_at'
=>
new
DateTime
));
$reminder
=
DB
::
collection
(
'password_reminders'
)
->
first
();
$this
->
assertTrue
(
is_array
(
$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
->
password
=
bcrypt
(
$password
);
$user
->
save
();
$user
->
save
();
});
});
$this
->
assertEquals
(
'
reminder
s.reset'
,
$response
);
$this
->
assertEquals
(
'
password
s.reset'
,
$response
);
$this
->
assertEquals
(
0
,
DB
::
collection
(
'password_re
minder
s'
)
->
count
());
$this
->
assertEquals
(
0
,
DB
::
collection
(
'password_re
set
s'
)
->
count
());
}
}
}
}
tests/TestCase.php
View file @
698e166b
...
@@ -11,7 +11,7 @@ class TestCase extends Orchestra\Testbench\TestCase {
...
@@ -11,7 +11,7 @@ class TestCase extends Orchestra\Testbench\TestCase {
{
{
return
array
(
return
array
(
'Jenssegers\Mongodb\MongodbServiceProvider'
,
'Jenssegers\Mongodb\MongodbServiceProvider'
,
'Jenssegers\Mongodb\Auth\
Reminder
ServiceProvider'
,
'Jenssegers\Mongodb\Auth\
PasswordReset
ServiceProvider'
,
);
);
}
}
...
@@ -36,7 +36,7 @@ class TestCase extends Orchestra\Testbench\TestCase {
...
@@ -36,7 +36,7 @@ class TestCase extends Orchestra\Testbench\TestCase {
$app
[
'config'
]
->
set
(
'database.connections.mysql'
,
$config
[
'connections'
][
'mysql'
]);
$app
[
'config'
]
->
set
(
'database.connections.mysql'
,
$config
[
'connections'
][
'mysql'
]);
$app
[
'config'
]
->
set
(
'database.connections.mongodb'
,
$config
[
'connections'
][
'mongodb'
]);
$app
[
'config'
]
->
set
(
'database.connections.mongodb'
,
$config
[
'connections'
][
'mongodb'
]);
// overwrite cache configuration
$app
[
'config'
]
->
set
(
'auth.model'
,
'User'
);
$app
[
'config'
]
->
set
(
'cache.driver'
,
'array'
);
$app
[
'config'
]
->
set
(
'cache.driver'
,
'array'
);
}
}
...
...
tests/models/User.php
View file @
698e166b
...
@@ -2,14 +2,14 @@
...
@@ -2,14 +2,14 @@
use
Jenssegers\Mongodb\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Model
as
Eloquent
;
use
Illuminate\Auth\
UserTrait
;
use
Illuminate\Auth\
Authenticatable
;
use
Illuminate\Auth\
UserInterface
;
use
Illuminate\Auth\
Passwords\CanResetPassword
;
use
Illuminate\
Auth\Reminders\RemindableTrai
t
;
use
Illuminate\
Contracts\Auth\Authenticatable
as
AuthenticatableContrac
t
;
use
Illuminate\
Auth\Reminders\RemindableInterface
;
use
Illuminate\
Contracts\Auth\CanResetPassword
as
CanResetPasswordContract
;
class
User
extends
Eloquent
implements
UserInterface
,
RemindableInterface
{
class
User
extends
Eloquent
implements
AuthenticatableContract
,
CanResetPasswordContract
{
use
UserTrait
,
RemindableTrait
;
use
Authenticatable
,
CanResetPassword
;
protected
$dates
=
array
(
'birthday'
,
'entry.date'
);
protected
$dates
=
array
(
'birthday'
,
'entry.date'
);
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
...
...
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