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) public function register(Request $request)
{ {
if (!UserConfig::get('allow_self_registration')) if (!UserConfig::get('allow_self_registration'))

View File

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

View File

@ -35,7 +35,7 @@ class TestMailConfig extends Mailable
{ {
$subject = trans('email.test_email_subject', ['app_name' => UserConfig::get('app_name')]); $subject = trans('email.test_email_subject', ['app_name' => UserConfig::get('app_name')]);
return $this->from($this->senderAddress, $this->senderName) return $this
->subject($subject) ->subject($subject)
->view(Theme::viewName('email.test_email')) ->view(Theme::viewName('email.test_email'))
->with(['subject' => $subject]); ->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')]); $subject = trans('email.activation_required_subject', ['app_name' => UserConfig::get('app_name')]);
return $this return $this
->from(UserConfig::get('sender_address'), UserConfig::get('sender_name'))
->subject($subject) ->subject($subject)
->view(Theme::viewName('email.user_activation_required')) ->view(Theme::viewName('email.user_activation_required'))
->with([ ->with([

View File

@ -9,6 +9,7 @@ use App\Helpers\ConfigHelper;
use App\Helpers\ImageHelper; use App\Helpers\ImageHelper;
use App\Helpers\ThemeHelper; use App\Helpers\ThemeHelper;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Mail\Mailer;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@ -78,8 +79,9 @@ class AppServiceProvider extends ServiceProvider
private function updateMailConfig() private function updateMailConfig()
{ {
/** @var \Swift_Mailer $swiftMailer */ /** @var Mailer $mailer */
$swiftMailer = $this->app->mailer->getSwiftMailer(); $mailer = $this->app->mailer;
$swiftMailer = $mailer->getSwiftMailer();
/** @var \Swift_SmtpTransport $transport */ /** @var \Swift_SmtpTransport $transport */
$transport = $swiftMailer->getTransport(); $transport = $swiftMailer->getTransport();
@ -92,5 +94,7 @@ class AppServiceProvider extends ServiceProvider
{ {
$transport->setEncryption('tls'); $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. | these language lines according to your application's requirements.
| |
*/ */
'failed' => 'These credentials do not match our records.', 'failed' => 'These credentials do not match our records.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', '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', 'delete_action' => 'Delete',
'description_label' => 'Description:', 'description_label' => 'Description:',
'edit_action' => 'Edit', 'edit_action' => 'Edit',
'email_label' => 'E-mail address:',
'login_action' => 'Login',
'name_label' => 'Name:', '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', 'upload_action' => 'Upload',
'save_action' => 'Save Changes' 'save_action' => 'Save Changes'
]; ];

View File

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

View File

@ -1,12 +1,12 @@
@extends('themes.base.layout') @extends('themes.base.layout')
<!-- Main Content --> @section('title', trans('auth.forgot_password_title'))
@section('content') @section('content')
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="col-md-8 col-md-offset-2">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Reset Password</div> <div class="panel-heading">@yield('title')</div>
<div class="panel-body"> <div class="panel-body">
@if (session('status')) @if (session('status'))
<div class="alert alert-success"> <div class="alert alert-success">
@ -18,7 +18,7 @@
{{ csrf_field() }} {{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}"> <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"> <div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}"> <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@ -32,8 +32,8 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-6 col-md-offset-4"> <div class="col-md-6 col-md-offset-4 text-right">
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-success">
Send Password Reset Link Send Password Reset Link
</button> </button>
</div> </div>
@ -43,5 +43,5 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
@endsection @endsection

View File

@ -1,11 +1,12 @@
@extends('themes.base.layout') @extends('themes.base.layout')
@section('title', trans('auth.reset_password_title'))
@section('content') @section('content')
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="col-md-8 col-md-offset-2">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Reset Password</div> <div class="panel-heading">@yield('title')</div>
<div class="panel-body"> <div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/password/reset') }}"> <form class="form-horizontal" role="form" method="POST" action="{{ url('/password/reset') }}">
@ -14,7 +15,7 @@
<input type="hidden" name="token" value="{{ $token }}"> <input type="hidden" name="token" value="{{ $token }}">
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}"> <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"> <div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ $email or old('email') }}" autofocus> <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') @extends('themes.base.layout')
@section('title', trans('auth.register_page_title'))
@section('content') @section('content')
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="col-md-8 col-md-offset-2">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Register</div> <div class="panel-heading">@yield('title')</div>
<div class="panel-body"> <div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}"> <form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{{ csrf_field() }} {{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}"> <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"> <div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" autofocus> <input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" autofocus>
@ -25,7 +26,7 @@
</div> </div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}"> <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"> <div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}"> <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@ -39,7 +40,7 @@
</div> </div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> <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"> <div class="col-md-6">
<input id="password" type="password" class="form-control" name="password"> <input id="password" type="password" class="form-control" name="password">
@ -53,7 +54,7 @@
</div> </div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}"> <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"> <div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation"> <input id="password-confirm" type="password" class="form-control" name="password_confirmation">
@ -67,10 +68,8 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-6 col-md-offset-4"> <div class="col-md-6 col-md-offset-4 text-right">
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-success">@lang('forms.register_action')</button>
Register
</button>
</div> </div>
</div> </div>
</form> </form>

View File

@ -33,7 +33,7 @@ Route::group(['prefix' => 'admin'], function () {
// Gallery // Gallery
Route::get('/', 'Gallery\DefaultController@index')->name('home'); 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}', 'Gallery\AlbumController@index')->name('viewAlbum');
Route::get('{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')->name('viewPhoto'); Route::get('{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')->name('viewPhoto');
Route::get('photo/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@download')->name('downloadPhoto'); Route::get('photo/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@download')->name('downloadPhoto');