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
f2279c02
Commit
f2279c02
authored
Oct 12, 2014
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scaffold authentication as default example.
parent
c6722869
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
347 additions
and
0 deletions
+347
-0
AuthController.php
app/Http/Controllers/Auth/AuthController.php
+107
-0
RemindersController.php
app/Http/Controllers/Auth/RemindersController.php
+114
-0
LoginRequest.php
app/Http/Requests/Auth/LoginRequest.php
+29
-0
RegisterRequest.php
app/Http/Requests/Auth/RegisterRequest.php
+30
-0
2014_10_12_000000_create_users_table.php
database/migrations/2014_10_12_000000_create_users_table.php
+34
-0
2014_10_12_100000_create_password_reminders_table.php
...ons/2014_10_12_100000_create_password_reminders_table.php
+33
-0
No files found.
app/Http/Controllers/Auth/AuthController.php
0 → 100644
View file @
f2279c02
<?php
namespace
App\Http\Controllers\Auth
;
use
Illuminate\Contracts\Auth\Authenticator
;
use
App\Http\Requests\Auth\LoginRequest
;
use
App\Http\Requests\Auth\RegisterRequest
;
/**
* @Middleware("csrf")
* @Middleware("guest", except={"logout"})
*/
class
AuthController
{
/**
* The authenticator implementation.
*
* @var Authenticator
*/
protected
$auth
;
/**
* Create a new authentication controller instance.
*
* @param Authenticator $auth
* @return void
*/
public
function
__construct
(
Authenticator
$auth
)
{
$this
->
auth
=
$auth
;
}
/**
* Show the application registration form.
*
* @Get("auth/register")
*
* @return Response
*/
public
function
showRegistrationForm
()
{
return
view
(
'auth.register'
);
}
/**
* Handle a registration request for the application.
*
* @Post("auth/register")
*
* @param RegisterRequest $request
* @return Response
*/
public
function
register
(
RegisterRequest
$request
)
{
// Registration form is valid, create user...
$this
->
auth
->
login
(
$user
);
return
redirect
(
'/'
);
}
/**
* Show the application login form.
*
* @Get("auth/login")
*
* @return Response
*/
public
function
showLoginForm
()
{
return
view
(
'auth.login'
);
}
/**
* Handle a login request to the application.
*
* @Post("auth/login")
*
* @param LoginRequest $request
* @return Response
*/
public
function
login
(
LoginRequest
$request
)
{
if
(
$this
->
auth
->
attempt
(
$request
->
only
(
'email'
,
'password'
)))
{
return
redirect
(
'/'
);
}
return
redirect
(
'/login'
)
->
withErrors
([
'email'
=>
'The credentials you entered did not match our records. Try again?'
,
]);
}
/**
* Log the user out of the application.
*
* @Get("auth/logout")
*
* @return Response
*/
public
function
logout
()
{
$this
->
auth
->
logout
();
return
redirect
(
'/'
);
}
}
app/Http/Controllers/Auth/RemindersController.php
0 → 100644
View file @
f2279c02
<?php
namespace
App\Http\Controllers\Auth
;
use
Illuminate\Http\Request
;
use
Illuminate\Contracts\Auth\PasswordBroker
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
/**
* @Middleware("csrf")
* @Middleware("guest")
*/
class
RemindersController
{
/**
* The password reminder implementation.
*
* @var PasswordBroker
*/
protected
$passwords
;
/**
* Create a new password reminder controller instance.
*
* @param PasswordBroker $passwords
* @return void
*/
public
function
__construct
(
PasswordBroker
$passwords
)
{
$this
->
passwords
=
$passwords
;
}
/**
* Display the password reminder view.
*
* @Get("password/remind")
*
* @return Response
*/
public
function
showReminderForm
()
{
return
view
(
'password.remind'
);
}
/**
* Handle a POST request to remind a user of their password.
*
* @Post("password/remind")
*
* @param Request $request
* @return Response
*/
public
function
sendPasswordResetEmail
(
Request
$request
)
{
switch
(
$response
=
$this
->
passwords
->
remind
(
$request
->
only
(
'email'
)))
{
case
PasswordBroker
::
INVALID_USER
:
return
redirect
()
->
back
()
->
with
(
'error'
,
trans
(
$response
));
case
PasswordBroker
::
REMINDER_SENT
:
return
redirect
()
->
back
()
->
with
(
'status'
,
trans
(
$response
));
}
}
/**
* Display the password reset view for the given token.
*
* @Get("password/reset")
*
* @param string $token
* @return Response
*/
public
function
showPasswordResetForm
(
$token
=
null
)
{
if
(
is_null
(
$token
))
{
throw
new
NotFoundHttpException
;
}
return
view
(
'password.reset'
)
->
with
(
'token'
,
$token
);
}
/**
* Handle a POST request to reset a user's password.
*
* @Post("password/reset")
*
* @param Request $request
* @return Response
*/
public
function
resetPassword
(
Request
$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
::
INVALID_PASSWORD
:
case
PasswordBroker
::
INVALID_TOKEN
:
case
PasswordBroker
::
INVALID_USER
:
return
redirect
()
->
back
()
->
with
(
'error'
,
trans
(
$response
));
case
PasswordBroker
::
PASSWORD_RESET
:
return
redirect
()
->
to
(
'/'
);
}
}
}
app/Http/Requests/Auth/LoginRequest.php
0 → 100644
View file @
f2279c02
<?php
namespace
App\Http\Requests\Auth
;
use
Illuminate\Foundation\Http\FormRequest
;
class
LoginRequest
extends
FormRequest
{
/**
* 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
0 → 100644
View file @
f2279c02
<?php
namespace
App\Http\Requests\Auth
;
use
Illuminate\Foundation\Http\FormRequest
;
class
RegisterRequest
extends
FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
'email'
=>
'required|email|unique:users'
,
'password'
=>
'required|confirmed|min:8'
,
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
}
database/migrations/2014_10_12_000000_create_users_table.php
0 → 100644
View file @
f2279c02
<?php
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
class
CreateUsersTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'users'
,
function
(
Blueprint
$table
)
{
$table
->
increments
(
'id'
);
$table
->
string
(
'email'
)
->
unique
();
$table
->
string
(
'password'
,
60
);
$table
->
timestamps
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
drop
(
'users'
);
}
}
database/migrations/2014_10_12_100000_create_password_reminders_table.php
0 → 100644
View file @
f2279c02
<?php
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
class
CreatePasswordRemindersTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'password_reminders'
,
function
(
Blueprint
$table
)
{
$table
->
string
(
'email'
)
->
index
();
$table
->
string
(
'token'
)
->
index
();
$table
->
timestamp
(
'created_at'
);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
drop
(
'password_reminders'
);
}
}
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