Implemented the activation controller

This commit is contained in:
Andy Heathershaw 2016-09-06 14:19:16 +01:00
parent 57bc8d86cc
commit eb49f3230d
13 changed files with 133 additions and 72 deletions

View File

@ -0,0 +1,48 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\RedirectsUsers;
use Illuminate\Support\Facades\App;
class ActivateController extends Controller
{
use RedirectsUsers;
/**
* Where to redirect users after activation.
*
* @var string
*/
protected $redirectTo = '/login';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function activate($token)
{
/** @var User $user */
$user = User::where(['is_activated' => false, 'activation_token' => $token])->first();
if (is_null($user))
{
App::abort(404);
return null;
}
$user->is_activated = true;
$user->activation_token = null;
$user->save();
return redirect($this->redirectPath());
}
}

View File

@ -89,11 +89,6 @@ class RegisterController extends Controller
));
}
public function activate($token)
{
return Theme::render('auth.activate');
}
public function register(Request $request)
{
if (!UserConfig::get('allow_self_registration'))

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Auth;
use App\Facade\Theme;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
class ResetPasswordController extends Controller
{
@ -21,6 +22,13 @@ class ResetPasswordController extends Controller
use ResetsPasswords;
/**
* Where to redirect users after a password reset.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*

View File

@ -35,9 +35,9 @@ class TestMailConfig extends Mailable
{
$subject = trans('email.test_email_subject', ['app_name' => UserConfig::get('app_name')]);
return $this->from($this->senderAddress, $this->senderName)
->subject($subject)
->view(Theme::viewName('email.test_email'))
->with(['subject' => $subject]);
return $this
->subject($subject)
->view(Theme::viewName('email.test_email'))
->with(['subject' => $subject]);
}
}

View File

@ -36,7 +36,6 @@ class UserActivationRequired extends Mailable
$subject = trans('email.activation_required_subject', ['app_name' => UserConfig::get('app_name')]);
return $this
->from(UserConfig::get('sender_address'), UserConfig::get('sender_name'))
->subject($subject)
->view(Theme::viewName('email.user_activation_required'))
->with([

View File

@ -9,6 +9,7 @@ use App\Helpers\ConfigHelper;
use App\Helpers\ImageHelper;
use App\Helpers\ThemeHelper;
use Illuminate\Database\QueryException;
use Illuminate\Mail\Mailer;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
@ -78,8 +79,9 @@ class AppServiceProvider extends ServiceProvider
private function updateMailConfig()
{
/** @var \Swift_Mailer $swiftMailer */
$swiftMailer = $this->app->mailer->getSwiftMailer();
/** @var Mailer $mailer */
$mailer = $this->app->mailer;
$swiftMailer = $mailer->getSwiftMailer();
/** @var \Swift_SmtpTransport $transport */
$transport = $swiftMailer->getTransport();
@ -92,5 +94,7 @@ class AppServiceProvider extends ServiceProvider
{
$transport->setEncryption('tls');
}
$mailer->alwaysFrom(UserConfig::get('sender_address'), UserConfig::get('sender_name'));
}
}

View File

@ -12,8 +12,11 @@ return [
| these language lines according to your application's requirements.
|
*/
'failed' => 'These credentials do not match our records.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
'forgot_password_link' => 'Forgotten your password?',
'forgot_password_title' => 'Send password reset link',
'login_page_title' => 'Login',
'register_page_title' => 'Create an account'
];

View File

@ -5,7 +5,14 @@ return [
'delete_action' => 'Delete',
'description_label' => 'Description:',
'edit_action' => 'Edit',
'email_label' => 'E-mail address:',
'login_action' => 'Login',
'name_label' => 'Name:',
'password_label' => 'Password:',
'password_confirm_label' => 'Confirm password:',
'realname_label' => 'Your name:',
'register_action' => 'Create account',
'remember_me_label' => 'Remember me',
'upload_action' => 'Upload',
'save_action' => 'Save Changes'
];

View File

@ -1,17 +1,18 @@
@extends('themes.base.layout')
@section('title', trans('auth.login_page_title'))
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Login</div>
<div class="panel-heading">@yield('title')</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<label for="email" class="col-md-4 control-label">@lang('forms.email_label')</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" autofocus>
@ -25,7 +26,7 @@
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<label for="password" class="col-md-4 control-label">@lang('forms.password_label')</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password">
@ -42,21 +43,17 @@
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
<input type="checkbox" name="remember"> @lang('forms.remember_me_label')
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<div class="col-md-6 col-md-offset-4 text-right">
<a class="btn btn-link" href="{{ url('/password/reset') }}">@lang('auth.forgot_password_link')</a>
<a class="btn btn-link" href="{{ url('/password/reset') }}">
Forgot Your Password?
</a>
<button type="submit" class="btn btn-success">@lang('forms.login_action')</button>
</div>
</div>
</form>

View File

@ -1,47 +1,47 @@
@extends('themes.base.layout')
<!-- Main Content -->
@section('title', trans('auth.forgot_password_title'))
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Reset Password</div>
<div class="panel-body">
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('/password/email') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">@yield('title')</div>
<div class="panel-body">
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
</div>
@endif
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Send Password Reset Link
</button>
<form class="form-horizontal" role="form" method="POST" action="{{ url('/password/email') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">@lang('forms.email_label')</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
</div>
</form>
<div class="form-group">
<div class="col-md-6 col-md-offset-4 text-right">
<button type="submit" class="btn btn-success">
Send Password Reset Link
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@ -1,11 +1,12 @@
@extends('themes.base.layout')
@section('title', trans('auth.reset_password_title'))
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Reset Password</div>
<div class="panel-heading">@yield('title')</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/password/reset') }}">
@ -14,7 +15,7 @@
<input type="hidden" name="token" value="{{ $token }}">
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<label for="email" class="col-md-4 control-label">@lang('forms.email_label')</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ $email or old('email') }}" autofocus>

View File

@ -1,17 +1,18 @@
@extends('themes.base.layout')
@section('title', trans('auth.register_page_title'))
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-heading">@yield('title')</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Name</label>
<label for="name" class="col-md-4 control-label">@lang('forms.realname_label')</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" autofocus>
@ -25,7 +26,7 @@
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<label for="email" class="col-md-4 control-label">@lang('forms.email_label')</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@ -39,7 +40,7 @@
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<label for="password" class="col-md-4 control-label">@lang('forms.password_label')</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password">
@ -53,7 +54,7 @@
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<label for="password-confirm" class="col-md-4 control-label">@lang('forms.password_confirm_label')</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation">
@ -67,10 +68,8 @@
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
<div class="col-md-6 col-md-offset-4 text-right">
<button type="submit" class="btn btn-success">@lang('forms.register_action')</button>
</div>
</div>
</form>

View File

@ -33,7 +33,7 @@ Route::group(['prefix' => 'admin'], function () {
// Gallery
Route::get('/', 'Gallery\DefaultController@index')->name('home');
Route::get('/activate/{token}', 'Auth\RegisterController@activate')->name('auth.activate');
Route::get('/activate/{token}', 'Auth\ActivateController@activate')->name('auth.activate');
Route::get('{albumUrlAlias}', 'Gallery\AlbumController@index')->name('viewAlbum');
Route::get('{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')->name('viewPhoto');
Route::get('photo/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@download')->name('downloadPhoto');