Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
9083f48e
Commit
9083f48e
authored
Nov 29, 2014
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on removing authentication boilerplate.
parent
e0afdf4c
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
91 additions
and
336 deletions
+91
-336
AuthController.php
app/Http/Controllers/Auth/AuthController.php
+13
-95
PasswordController.php
app/Http/Controllers/Auth/PasswordController.php
+13
-120
HomeController.php
app/Http/Controllers/HomeController.php
+11
-0
WelcomeController.php
app/Http/Controllers/WelcomeController.php
+11
-0
EmailPasswordLinkRequest.php
app/Http/Requests/Auth/EmailPasswordLinkRequest.php
+0
-29
LoginRequest.php
app/Http/Requests/Auth/LoginRequest.php
+0
-29
RegisterRequest.php
app/Http/Requests/Auth/RegisterRequest.php
+0
-31
ResetPasswordRequest.php
app/Http/Requests/Auth/ResetPasswordRequest.php
+0
-31
AppServiceProvider.php
app/Providers/AppServiceProvider.php
+4
-1
Registrar.php
app/Services/Registrar.php
+39
-0
No files found.
app/Http/Controllers/Auth/AuthController.php
View file @
9083f48e
<?php
namespace
App\Http\Controllers\Auth
;
use
App\User
;
use
App\Http\Requests
;
use
App\Http\Controllers\Controller
;
use
Illuminate\
Contracts\Auth\Guard
;
use
Illuminate\
Foundation\Auth\AuthenticatesAndRegistersUsers
;
class
AuthController
extends
Controller
{
/**
* The Guard implementation.
*
* @var Guard
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
protected
$auth
;
/**
* Create a new authentication controller instance.
*
* @param Guard $auth
* @return void
*/
public
function
__construct
(
Guard
$auth
)
{
$this
->
auth
=
$auth
;
$this
->
middleware
(
'guest'
,
[
'except'
=>
'getLogout'
]);
}
/**
* Show the application registration form.
*
* @return Response
*/
public
function
getRegister
()
{
return
view
(
'auth.register'
);
}
/**
* Handle a registration request for the application.
*
* @param RegisterRequest $request
* @return Response
*/
public
function
postRegister
(
Requests\Auth\RegisterRequest
$request
)
{
$user
=
User
::
forceCreate
([
'name'
=>
$request
->
name
,
'email'
=>
$request
->
email
,
'password'
=>
bcrypt
(
$request
->
password
),
]);
$this
->
auth
->
login
(
$user
);
return
redirect
(
'/home'
);
}
/**
* Show the application login form.
*
* @return Response
*/
public
function
getLogin
()
{
return
view
(
'auth.login'
);
}
/**
* Handle a login request to the application.
*
* @param LoginRequest $request
* @return Response
*/
public
function
postLogin
(
Requests\Auth\LoginRequest
$request
)
{
$credentials
=
$request
->
only
(
'email'
,
'password'
);
if
(
$this
->
auth
->
attempt
(
$credentials
,
$request
->
has
(
'remember'
)))
{
return
redirect
(
'/home'
);
}
return
redirect
(
'/auth/login'
)
->
withInput
(
$request
->
only
(
'email'
))
->
withErrors
([
'email'
=>
'These credentials do not match our records.'
,
]);
}
/**
* Log the user out of the application.
*
* @return Response
*/
public
function
getLogout
()
{
$this
->
auth
->
logout
();
return
redirect
(
'/'
);
}
use
AuthenticatesAndRegistersUsers
;
}
app/Http/Controllers/Auth/PasswordController.php
View file @
9083f48e
<?php
namespace
App\Http\Controllers\Auth
;
use
App\User
;
use
App\Http\Requests
;
use
App\Http\Controllers\Controller
;
use
Illuminate\Contracts\Auth\Guard
;
use
Illuminate\Contracts\Auth\PasswordBroker
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Illuminate\Foundation\Auth\ResetsPasswords
;
class
PasswordController
extends
Controller
{
/**
* The Guard implementation.
*
* @var Guard
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
protected
$auth
;
/**
* The password broker implementation.
*
* @var PasswordBroker
*/
protected
$passwords
;
/**
* Create a new password controller instance.
*
* @param PasswordBroker $passwords
* @return void
*/
public
function
__construct
(
Guard
$auth
,
PasswordBroker
$passwords
)
{
$this
->
auth
=
$auth
;
$this
->
passwords
=
$passwords
;
$this
->
middleware
(
'guest'
);
}
/**
* Display the form to request a password reset link.
*
* @return Response
*/
public
function
getEmail
()
{
return
view
(
'auth.password'
);
}
/**
* Send a reset link to the given user.
*
* @param EmailPasswordLinkRequest $request
* @return Response
*/
public
function
postEmail
(
Requests\Auth\EmailPasswordLinkRequest
$request
)
{
switch
(
$response
=
$this
->
passwords
->
sendResetLink
(
$request
->
only
(
'email'
)))
{
case
PasswordBroker
::
RESET_LINK_SENT
:
return
redirect
()
->
back
()
->
with
(
'status'
,
trans
(
$response
));
case
PasswordBroker
::
INVALID_USER
:
return
redirect
()
->
back
()
->
withErrors
([
'email'
=>
trans
(
$response
)]);
}
}
/**
* Display the password reset view for the given token.
*
* @param string $token
* @return Response
*/
public
function
getReset
(
$token
=
null
)
{
if
(
is_null
(
$token
))
{
throw
new
NotFoundHttpException
;
}
return
view
(
'auth.reset'
)
->
with
(
'token'
,
$token
);
}
/**
* Reset the given user's password.
*
* @param ResetPasswordRequest $request
* @return Response
*/
public
function
postReset
(
Requests\Auth\ResetPasswordRequest
$request
)
{
$credentials
=
$request
->
only
(
'email'
,
'password'
,
'password_confirmation'
,
'token'
);
$response
=
$this
->
passwords
->
reset
(
$credentials
,
function
(
$user
,
$password
)
{
$user
->
password
=
bcrypt
(
$password
);
$user
->
save
();
});
switch
(
$response
)
{
case
PasswordBroker
::
PASSWORD_RESET
:
return
$this
->
loginAndRedirect
(
$request
->
email
);
default
:
return
redirect
()
->
back
()
->
withInput
(
$request
->
only
(
'email'
))
->
withErrors
([
'email'
=>
trans
(
$response
)]);
}
}
/**
* Login the user with the given e-mail address and redirect home.
*
* @param string $email
* @return Response
*/
protected
function
loginAndRedirect
(
$email
)
{
$this
->
auth
->
login
(
User
::
where
(
'email'
,
$email
)
->
firstOrFail
());
return
redirect
(
'/home'
);
}
use
ResetsPasswords
;
}
app/Http/Controllers/HomeController.php
View file @
9083f48e
...
...
@@ -2,6 +2,17 @@
class
HomeController
extends
Controller
{
/*
|--------------------------------------------------------------------------
| Home Controller
|--------------------------------------------------------------------------
|
| This controller renders your application's "dashboard" for users that
| are authenticated. Of course, you are free to change or remove the
| controller as you wish. It is just here to get your app started!
|
*/
/**
* Create a new controller instance.
*
...
...
app/Http/Controllers/WelcomeController.php
View file @
9083f48e
...
...
@@ -2,6 +2,17 @@
class
WelcomeController
extends
Controller
{
/*
|--------------------------------------------------------------------------
| Welcome Controller
|--------------------------------------------------------------------------
|
| This controller renders the "marketing page" for the application and
| is configured to only allow guests. Like most of the other sample
| controllers, you are free to modify or remove it as you desire.
|
*/
/**
* Create a new controller instance.
*
...
...
app/Http/Requests/Auth/EmailPasswordLinkRequest.php
deleted
100644 → 0
View file @
e0afdf4c
<?php
namespace
App\Http\Requests\Auth
;
use
App\Http\Requests\Request
;
class
EmailPasswordLinkRequest
extends
Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
'email'
=>
'required'
,
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
}
app/Http/Requests/Auth/LoginRequest.php
deleted
100644 → 0
View file @
e0afdf4c
<?php
namespace
App\Http\Requests\Auth
;
use
App\Http\Requests\Request
;
class
LoginRequest
extends
Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
'email'
=>
'required'
,
'password'
=>
'required'
,
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
}
app/Http/Requests/Auth/RegisterRequest.php
deleted
100644 → 0
View file @
e0afdf4c
<?php
namespace
App\Http\Requests\Auth
;
use
App\Http\Requests\Request
;
class
RegisterRequest
extends
Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
'name'
=>
'required|max:255'
,
'email'
=>
'required|email|max:255|unique:users'
,
'password'
=>
'required|min:6|confirmed'
,
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
}
app/Http/Requests/Auth/ResetPasswordRequest.php
deleted
100644 → 0
View file @
e0afdf4c
<?php
namespace
App\Http\Requests\Auth
;
use
App\Http\Requests\Request
;
class
ResetPasswordRequest
extends
Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
'token'
=>
'required'
,
'email'
=>
'required'
,
'password'
=>
'required|confirmed'
,
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
}
app/Providers/AppServiceProvider.php
View file @
9083f48e
...
...
@@ -21,7 +21,10 @@ class AppServiceProvider extends ServiceProvider {
*/
public
function
register
()
{
//
$this
->
app
->
bind
(
'Illuminate\Contracts\Auth\Registrar'
,
'App\Services\Registrar'
);
}
}
app/Services/Registrar.php
0 → 100644
View file @
9083f48e
<?php
namespace
App\Services
;
use
App\User
;
use
Validator
;
use
Illuminate\Contracts\Auth\Registrar
as
RegistrarContract
;
class
Registrar
implements
RegistrarContract
{
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
public
function
validator
(
array
$data
)
{
return
Validator
::
make
(
$data
,
[
'name'
=>
'required|max:255'
,
'email'
=>
'required|email|max:255|unique:users'
,
'password'
=>
'required|confirmed|min:6'
,
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
public
function
create
(
array
$data
)
{
return
User
::
forceCreate
([
'name'
=>
$data
[
'name'
],
'email'
=>
$data
[
'email'
],
'password'
=>
bcrypt
(
$data
[
'password'
]),
]);
}
}
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