Working on default app structure. Login views.

This commit is contained in:
Taylor Otwell 2014-11-24 11:42:29 -06:00
parent b73e127ed0
commit fa978d0525
25 changed files with 515 additions and 63 deletions

View File

@ -1,5 +1,6 @@
<?php namespace App\Http\Controllers;
use App\User;
use Illuminate\Contracts\Auth\Guard;
use App\Http\Requests\LoginRequest;
@ -45,11 +46,15 @@ public function getRegister()
*/
public function postRegister(RegisterRequest $request)
{
// Registration form is valid, create user...
$user = User::forceCreate([
'name' => $request->name,
'email' => $request->email,
'password' => bcrypt($request->password),
]);
$this->auth->login($user);
return redirect('/');
return redirect('/dashboard');
}
/**
@ -72,12 +77,14 @@ public function postLogin(LoginRequest $request)
{
if ($this->auth->attempt($request->only('email', 'password')))
{
return redirect('/');
return redirect('/dashboard');
}
return redirect('/auth/login')->withErrors([
'email' => 'These credentials do not match our records.',
]);
return redirect('/auth/login')
->withInput($request->only('email'))
->withErrors([
'email' => 'These credentials do not match our records.',
]);
}
/**

View File

@ -0,0 +1,25 @@
<?php namespace App\Http\Controllers;
class DashboardController extends Controller {
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
return view('dashboard');
}
}

View File

@ -1,11 +1,20 @@
<?php namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\PasswordBroker;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class PasswordController extends Controller {
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* The password broker implementation.
*
@ -19,8 +28,9 @@ class PasswordController extends Controller {
* @param PasswordBroker $passwords
* @return void
*/
public function __construct(PasswordBroker $passwords)
public function __construct(Guard $auth, PasswordBroker $passwords)
{
$this->auth = $auth;
$this->passwords = $passwords;
$this->middleware('guest');
@ -33,7 +43,7 @@ public function __construct(PasswordBroker $passwords)
*/
public function getEmail()
{
return view('password.email');
return view('auth.password');
}
/**
@ -44,6 +54,8 @@ public function getEmail()
*/
public function postEmail(Request $request)
{
$this->validate($request, ['email' => 'required']);
switch ($response = $this->passwords->sendResetLink($request->only('email')))
{
case PasswordBroker::INVALID_USER:
@ -67,7 +79,7 @@ public function getReset($token = null)
throw new NotFoundHttpException;
}
return view('password.reset')->with('token', $token);
return view('auth.reset')->with('token', $token);
}
/**
@ -94,11 +106,26 @@ public function postReset(Request $request)
case PasswordBroker::INVALID_PASSWORD:
case PasswordBroker::INVALID_TOKEN:
case PasswordBroker::INVALID_USER:
return redirect()->back()->withErrors(['email' => trans($response)]);
return redirect()->back()
->withInput($request->only('email'))
->withErrors(['email' => trans($response)]);
case PasswordBroker::PASSWORD_RESET:
return redirect()->to('/');
return $this->loginAndRedirect($request->email);
}
}
/**
* 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('/dashboard');
}
}

View File

@ -1,6 +1,6 @@
<?php namespace App\Http\Controllers;
class HomeController extends Controller {
class WelcomeController extends Controller {
/*
|--------------------------------------------------------------------------
@ -11,13 +11,13 @@ class HomeController extends Controller {
| based routes. That's great! Here is an example controller method to
| get you started. To route to this controller, just add the route:
|
| $router->get('/', 'HomeController@showWelcome');
| $router->get('/', 'WelcomeController@index');
|
*/
public function index()
{
return view('hello');
return view('welcome');
}
}

View File

@ -10,7 +10,8 @@ class RegisterRequest extends Request {
public function rules()
{
return [
'email' => 'required|email|unique:users',
'name' => 'required|max:255',
'email' => 'required|max:255|email|unique:users',
'password' => 'required|confirmed|min:8',
];
}

View File

@ -11,7 +11,9 @@
|
*/
$router->get('/', 'HomeController@index');
$router->get('/', 'WelcomeController@index');
$router->get('/dashboard', 'DashboardController@index');
/*
|--------------------------------------------------------------------------

View File

@ -1,6 +1,7 @@
{
"name": "Laravel Application",
"dependencies": {
"bootstrap-sass-official": "~3.3.1"
"bootstrap-sass-official": "~3.3.1",
"font-awesome": "~4.2.0"
}
}

98
config/local/mail.php Normal file
View File

@ -0,0 +1,98 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "log"
|
*/
'driver' => 'smtp',
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => 'mailtrap.io',
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => 465,
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => ['address' => 'homestead@laravel.com', 'name' => 'Homestead'],
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => 'tls',
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => '',
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/
'password' => '',
];

View File

@ -15,6 +15,7 @@ public function up()
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();

View File

@ -13,6 +13,20 @@ var elixir = require('laravel-elixir');
elixir(function(mix) {
mix.sass("app.scss")
.phpUnit()
.publish("vendor/bower_components");
.publish(
'jquery/dist/jquery.min.js',
'public/js/vendor/jquery.js'
)
.publish(
'bootstrap-sass-official/assets/javascripts/bootstrap.js',
'public/js/vendor/bootstrap.js'
)
.publish(
'font-awesome/css/font-awesome.min.css',
'public/css/vendor/font-awesome.css'
)
.publish(
'font-awesome/fonts',
'public/css/vendor/fonts'
);
});

View File

@ -1 +1,9 @@
$font-family-sans-serif: "Lato", Helvetica, Arial, sans-serif;
@import "bootstrap";
@import "partials/auth";
@import "partials/navigation";
.fa-btn {
margin-right: 10px;
}

View File

@ -0,0 +1,4 @@
.forgot-password {
padding-top: 7px;
vertical-align: middle;
}

View File

@ -0,0 +1,5 @@
.navbar-avatar {
border-radius: 999px;
margin: -11px 10px -10px 0;
padding: 0;
}

View File

@ -19,7 +19,7 @@
"token" => "This password reset token is invalid.",
"sent" => "Password reminder sent!",
"sent" => "Password reset link sent!",
"reset" => "Password has been reset!",

View File

@ -0,0 +1,49 @@
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Login</div>
<div class="panel-body">
@include('partials.errors.basic')
<form class="form-horizontal" role="form" method="POST" action="/auth/login">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Email</label>
<div class="col-sm-6">
<input type="email" id="email" name="email" class="form-control" placeholder="Email" autocapitalize="off" value="{{ old('email') }}">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">Password</label>
<div class="col-sm-6">
<input type="password" name="password" class="form-control" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<button type="submit" class="btn btn-primary"><i class="fa fa-btn fa-sign-in"></i>Login</button>
</div>
<div class="col-sm-3">
<div class="forgot-password text-right"><a href="/password/email">Forgot Your Password?</a></div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@stop

View File

@ -0,0 +1,37 @@
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Forgotten Password</div>
<div class="panel-body">
@include('partials.errors.basic')
@if (Session::has('status'))
<div class="alert alert-success">
{{ Session::get('status') }}
</div>
@endif
<form class="form-horizontal" role="form" method="POST" action="/password/email">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Email</label>
<div class="col-sm-6">
<input type="email" id="email" name="email" class="form-control" placeholder="Email" autocapitalize="off" value="{{ old('email') }}">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<button type="submit" class="btn btn-primary"><i class="fa fa-btn fa-envelope"></i>Send Reset Password Link</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@stop

View File

@ -0,0 +1,49 @@
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-body">
@include('partials.errors.basic')
<form class="form-horizontal" role="form" method="POST" action="/auth/register">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Name</label>
<div class="col-sm-6">
<input type="text" id="name" name="name" class="form-control" placeholder="Name" value="{{ old('name') }}">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Email</label>
<div class="col-sm-6">
<input type="email" id="email" name="email" class="form-control" placeholder="Email" autocapitalize="off" value="{{ old('email') }}">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">Password</label>
<div class="col-sm-6">
<input type="password" name="password" class="form-control" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">Confirm Password</label>
<div class="col-sm-6">
<input type="password" name="password_confirmation" class="form-control" placeholder="Confirm Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<button type="submit" class="btn btn-primary"><i class="fa fa-btn fa-user"></i>Register</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@stop

View File

@ -0,0 +1,44 @@
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Reset Password</div>
<div class="panel-body">
@include('partials.errors.basic')
<form class="form-horizontal" role="form" method="POST" action="/password/reset">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="token" value="{{ $token }}">
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Email</label>
<div class="col-sm-6">
<input type="email" id="email" name="email" class="form-control" placeholder="Email" autocapitalize="off" value="{{ old('email') }}">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">Password</label>
<div class="col-sm-6">
<input type="password" name="password" class="form-control" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">Confirm Password</label>
<div class="col-sm-6">
<input type="password" name="password_confirmation" class="form-control" placeholder="Confirm Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<button type="submit" class="btn btn-primary"><i class="fa fa-btn fa-refresh"></i>Reset Password</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@stop

View File

@ -0,0 +1,16 @@
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="panel-body">
Application dashboard.
</div>
</div>
</div>
</div>
@stop

View File

@ -7,7 +7,7 @@
<h2>Password Reset</h2>
<div>
To reset your password, complete this form: {{ url('password/reset', [$token]) }}.<br/>
To reset your password, complete this form: {{ url('password/reset', [$token]) }}.<br><br>
This link will expire in {{ config('auth.reminder.expire', 60) }} minutes.
</div>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<!-- FavIcon -->
<link rel="icon" href="../../favicon.ico">
<!-- Application Title -->
<title>Laravel Application</title>
<!-- Bootstrap CSS -->
<link href="/css/app.css" rel="stylesheet">
<link href="/css/vendor/font-awesome.css" rel="stylesheet">
<!-- Web Fonts -->
<link href='http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic' rel='stylesheet' type='text/css'>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Static navbar -->
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Laravel</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
</ul>
@if (Auth::check())
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="https://www.gravatar.com/avatar/{{{ md5(strtolower(Auth::user()->email)) }}}?s=35" height="35" width="35" class="navbar-avatar">
{{ Auth::user()->name }} <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="/auth/logout"><i class="fa fa-btn fa-sign-out"></i>Logout</a></li>
</ul>
</li>
</ul>
@else
<ul class="nav navbar-nav navbar-right">
<li><a href="/auth/login"><i class="fa fa-btn fa-sign-in"></i>Login</a></li>
<li><a href="/auth/register"><i class="fa fa-btn fa-user"></i>Register</a></li>
</ul>
@endif
</div>
</div>
</nav>
<div class="container-fluid">
@yield('content')
</div>
<!-- Bootstrap JavaScript -->
<script src="/js/vendor/jquery.js"></script>
<script src="/js/vendor/bootstrap.js"></script>
</body>
</html>

View File

@ -0,0 +1,10 @@
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

View File

@ -0,0 +1,16 @@
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Home</div>
<div class="panel-body">
Welcome To Laravel.
</div>
</div>
</div>
</div>
@stop