Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
laravel-adminpanel
Commits
fa096ef8
Commit
fa096ef8
authored
Dec 26, 2017
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test Cases for Reset Password
parent
0534f76d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
140 additions
and
6 deletions
+140
-6
helpers.php
app/Helpers/helpers.php
+19
-0
ResetPasswordController.php
...ttp/Controllers/Frontend/Auth/ResetPasswordController.php
+25
-3
UserRepository.php
app/Repositories/Frontend/Access/User/UserRepository.php
+16
-0
LoginTest.php
tests/Feature/Auth/LoginTest.php
+1
-1
RegistrationTest.php
tests/Feature/Auth/RegistrationTest.php
+2
-2
ResetPasswordTest.php
tests/Feature/Auth/ResetPasswordTest.php
+77
-0
No files found.
app/Helpers/helpers.php
View file @
fa096ef8
...
...
@@ -17,6 +17,25 @@ function generateUuid()
return
uuid
::
uuid4
();
}
if
(
!
function_exists
(
'homeRoute'
))
{
/**
* Return the route to the "home" page depending on authentication/authorization status.
*
* @return string
*/
function
homeRoute
()
{
if
(
access
()
->
allow
(
'view-backend'
))
{
return
'admin.dashboard'
;
}
elseif
(
auth
()
->
check
())
{
return
'frontend.user.dashboard'
;
}
return
'frontend.index'
;
}
}
/*
* Global helpers file with misc functions.
*/
...
...
app/Http/Controllers/Frontend/Auth/ResetPasswordController.php
View file @
fa096ef8
...
...
@@ -50,9 +50,20 @@ class ResetPasswordController extends Controller
*/
public
function
showResetForm
(
$token
=
null
)
{
return
view
(
'frontend.auth.passwords.reset'
)
->
withToken
(
$token
)
->
withEmail
(
$this
->
user
->
getEmailForPasswordToken
(
$token
));
if
(
!
$token
)
{
return
redirect
()
->
route
(
'frontend.auth.password.email'
);
}
$user
=
$this
->
user
->
findByPasswordResetToken
(
$token
);
if
(
$user
&&
app
()
->
make
(
'auth.password.broker'
)
->
tokenExists
(
$user
,
$token
))
{
return
view
(
'frontend.auth.passwords.reset'
)
->
withToken
(
$token
)
->
withEmail
(
$user
->
email
);
}
return
redirect
()
->
route
(
'frontend.auth.password.email'
)
->
withFlashDanger
(
trans
(
'exceptions.frontend.auth.password.reset_problem'
));
}
/**
...
...
@@ -80,4 +91,15 @@ class ResetPasswordController extends Controller
'password.regex'
=>
'Password must contain at least 1 uppercase letter and 1 number.'
,
];
}
/**
* Get the response for a successful password reset.
*
* @param string $response
* @return \Illuminate\Http\RedirectResponse
*/
protected
function
sendResetResponse
(
$response
)
{
return
redirect
()
->
route
(
homeRoute
())
->
withFlashSuccess
(
trans
(
$response
));
}
}
app/Repositories/Frontend/Access/User/UserRepository.php
View file @
fa096ef8
...
...
@@ -323,4 +323,20 @@ class UserRepository extends BaseRepository
return
$token
;
}
/**
* @param $token
*
* @return mixed
*/
public
function
findByPasswordResetToken
(
$token
)
{
foreach
(
DB
::
table
(
config
(
'auth.passwords.users.table'
))
->
get
()
as
$row
)
{
if
(
password_verify
(
$token
,
$row
->
token
))
{
return
$this
->
findByEmail
(
$row
->
email
);
}
}
return
false
;
}
}
tests/Feature/LoginTest.php
→
tests/Feature/
Auth/
LoginTest.php
View file @
fa096ef8
<?php
namespace
Tests\Feature
;
namespace
Tests\Feature
\Auth
;
use
App\Events\Frontend\Auth\UserLoggedIn
;
use
Illuminate\Support\Facades\Auth
;
...
...
tests/Feature/RegistrationTest.php
→
tests/Feature/
Auth/
RegistrationTest.php
View file @
fa096ef8
<?php
namespace
Tests\Feature
;
namespace
Tests\Feature
\Auth
;
use
App\Events\Frontend\Auth\UserRegistered
;
use
App\Models\Access\User\User
;
...
...
@@ -47,7 +47,7 @@ class RegistrationTest extends BrowserKitTestCase
*/
/** @test */
public
function
test_registration_form
()
public
function
user_can_register
()
{
// Make sure our events are fired
Event
::
fake
();
...
...
tests/Feature/Auth/ResetPasswordTest.php
0 → 100644
View file @
fa096ef8
<?php
namespace
Tests\Feature\Auth
;
use
Tests\BrowserKitTestCase
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\Event
;
use
App\Events\Frontend\Auth\UserLoggedIn
;
use
Illuminate\Support\Facades\Notification
;
use
App\Notifications\Frontend\Auth\UserNeedsPasswordReset
;
class
ResetPasswordTest
extends
BrowserKitTestCase
{
/** @test */
public
function
forgot_password_page_loads_properly
()
{
$this
->
visit
(
'/password/reset'
)
->
see
(
'Email'
)
->
see
(
'Reset Password'
);
}
/** @test **/
public
function
forgot_password_fails_when_a_required_field_is_not_filled_in
()
{
$this
->
visit
(
'/password/reset'
)
->
type
(
''
,
'email'
)
->
press
(
'Send Password Reset Link'
)
->
seePageIs
(
'/password/reset'
)
->
see
(
'The email field is required.'
);
}
/** @test **/
public
function
users_can_request_a_password_reset_link
()
{
Notification
::
fake
();
$this
->
visit
(
'password/reset'
)
->
type
(
$this
->
user
->
email
,
'email'
)
->
press
(
'Send Password Reset Link'
)
->
seePageIs
(
'password/reset'
)
->
see
(
'We have e-mailed your password reset link!'
)
->
seeInDatabase
(
'password_resets'
,
[
'email'
=>
$this
->
user
->
email
]);
Notification
::
assertSentTo
(
[
$this
->
user
],
UserNeedsPasswordReset
::
class
);
}
/** @test **/
public
function
reset_password_fails_when_a_required_field_is_not_filled_in
()
{
$token
=
$this
->
app
->
make
(
'auth.password.broker'
)
->
createToken
(
$this
->
user
);
$this
->
visit
(
'password/reset/'
.
$token
)
->
see
(
$this
->
user
->
email
)
->
type
(
''
,
'password'
)
->
type
(
''
,
'password_confirmation'
)
->
press
(
'Reset Password'
)
->
see
(
'The password field is required.'
);
}
/** @test **/
public
function
users_can_reset_password
()
{
$token
=
$this
->
app
->
make
(
'auth.password.broker'
)
->
createToken
(
$this
->
user
);
$this
->
visit
(
'password/reset/'
.
$token
)
->
see
(
$this
->
user
->
email
)
->
type
(
'12345678'
,
'password'
)
->
type
(
'12345678'
,
'password_confirmation'
)
->
press
(
'Reset Password'
)
->
see
(
$this
->
user
->
first_name
);
}
}
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