From 436c3d678737782d42f005cd2d0116744f53a95e Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 22 Jan 2020 21:05:31 +1100 Subject: [PATCH] Password Reset work --- .gitlab-ci.yml | 6 +-- .../Auth/ForgotPasswordController.php | 10 ---- .../Auth/ResetPasswordController.php | 24 ++------- .../ResetPasswordNotification.php | 52 ++++++++++++++----- composer.lock | 6 +-- .../views/email/user/passwordreset.blade.php | 12 ++--- .../views/vendor/mail/html/header.blade.php | 2 +- .../views/vendor/mail/html/message.blade.php | 2 +- .../views/vendor/mail/html/panel.blade.php | 6 ++- .../views/vendor/mail/html/themes/default.css | 14 +++-- 10 files changed, 72 insertions(+), 62 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b75b35..e38c67f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,13 +32,13 @@ before_script: # Add gnupg & zip - apt-get update -yqq && apt-get install gnupg2 unzip -yqq - # Upgrade to Node 9 - - curl -sL https://deb.nodesource.com/setup_9.x | bash - + # Upgrade to Node 12 + - curl -sL https://deb.nodesource.com/setup_12.x | bash - # Install dependencies #- apt-get install git nodejs libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev pkg-config libsnmp-dev snmp-mibs-downloader -yqq #- download-mibs - - apt-get install git nodejs -yqq + - apt-get install git autoconf nodejs -yqq # Install php extensions #- docker-php-ext-configure gd --with-freetype-dir=/usr/include/freetype2 --with-jpeg-dir=/usr/include/ diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 398ba7b..d5a8a42 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -20,16 +20,6 @@ class ForgotPasswordController extends Controller use SendsPasswordResetEmails; - /** - * Create a new controller instance. - * - * @return void - */ - public function __construct() - { - $this->middleware('guest'); - } - public function showLinkRequestForm() { return view('adminlte::auth.passwords.email'); diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 1c1d940..2077313 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -2,10 +2,12 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; +use App\Http\Controllers\Controller; +use App\Providers\RouteServiceProvider; + class ResetPasswordController extends Controller { /* @@ -26,26 +28,8 @@ class ResetPasswordController extends Controller * * @var string */ - protected $redirectTo = '/home'; + protected $redirectTo = RouteServiceProvider::HOME; - /** - * Create a new controller instance. - * - * @return void - */ - public function __construct() - { - $this->middleware('guest'); - } - - protected function rules() - { - return [ - 'token' => 'required', - 'email' => 'required|email|exists:users', - 'password' => 'required|confirmed|min:6', - ]; - } public function showResetForm(Request $request, $token = null) { return view('adminlte::auth.passwords.reset')->with( diff --git a/app/Notifications/ResetPasswordNotification.php b/app/Notifications/ResetPasswordNotification.php index 105560d..670209f 100644 --- a/app/Notifications/ResetPasswordNotification.php +++ b/app/Notifications/ResetPasswordNotification.php @@ -11,23 +11,36 @@ class ResetPasswordNotification extends Notification { use Queueable; - public $token; + /** + * The password reset token. + * + * @var string + */ + public $token; /** - * Create a new notification instance. + * The callback that should be used to build the mail message. * + * @var \Closure|null + */ + public static $toMailCallback; + + /** + * Create a notification instance. + * + * @param string $token * @return void */ public function __construct($token) { - $this->token = $token; + $this->token = $token; } /** - * Get the notification's delivery channels. + * Get the notification's channels. * * @param mixed $notifiable - * @return array + * @return array|string */ public function via($notifiable) { @@ -35,18 +48,33 @@ class ResetPasswordNotification extends Notification } /** - * Get the mail representation of the notification. + * Build the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { - $logo = config('SITE_SETUP')->site_logo; - $site_name = config('SITE_SETUP')->site_name; - $reset_link = route('password.reset', $this->token, true); + if (static::$toMailCallback) { + return call_user_func(static::$toMailCallback, $notifiable, $this->token); + } - return (new MailMessage) - ->markdown('email.user.passwordreset',compact('logo','site_name','reset_link')); + return (new MailMessage) + ->markdown('email.user.passwordreset',[ + 'site'=>config('SITE_SETUP'), + 'user'=>$notifiable, + 'reset_link'=>route('password.reset',$this->token,true), + ]); } -} \ No newline at end of file + + /** + * Set a callback that should be used when building the notification mail message. + * + * @param \Closure $callback + * @return void + */ + public static function toMailUsing($callback) + { + static::$toMailCallback = $callback; + } +} diff --git a/composer.lock b/composer.lock index 09e93b4..aa79149 100644 --- a/composer.lock +++ b/composer.lock @@ -2336,11 +2336,11 @@ }, { "name": "leenooks/laravel", - "version": "6.0.13", + "version": "6.0.14", "source": { "type": "git", "url": "https://dev.leenooks.net/leenooks/laravel", - "reference": "62f66d7eedaa4e86595965e146fb1cf3e9c341d8" + "reference": "176f680ff740d41b6e66723557e2e64721e0d51f" }, "require": { "creativeorange/gravatar": "^1.0", @@ -2377,7 +2377,7 @@ "laravel", "leenooks" ], - "time": "2020-01-14T10:43:40+00:00" + "time": "2020-01-22T09:48:42+00:00" }, { "name": "monolog/monolog", diff --git a/resources/views/email/user/passwordreset.blade.php b/resources/views/email/user/passwordreset.blade.php index 72f9229..d256bb3 100644 --- a/resources/views/email/user/passwordreset.blade.php +++ b/resources/views/email/user/passwordreset.blade.php @@ -1,19 +1,19 @@ -@component('mail::message',['site_name'=>$site_name,'logo'=>$logo]) -# Password Reset +@component('mail::message',['site'=>$site,'heading'=>'Password Reset']) +Hi {{ isset($user) ? $user->name.',' : '' }} You are receiving this email because we received a password reset request for your account. If you did not request a password reset, no further action is required. To reset your password, please follow this link, or click on the URL below: -@component('mail::button', ['url' => $reset_link]) +@component('mail::panel',['url'=>$reset_link]) Reset Password @endcomponent -@component('mail::panel') +@component('mail::subcopy') Reset password: {{ $reset_link }} @endcomponent Thanks,
-{{ $site_name }} -@endcomponent +{{ config('mail.from.name') }} +@endcomponent \ No newline at end of file diff --git a/resources/views/vendor/mail/html/header.blade.php b/resources/views/vendor/mail/html/header.blade.php index 6ab99c0..be315ec 100644 --- a/resources/views/vendor/mail/html/header.blade.php +++ b/resources/views/vendor/mail/html/header.blade.php @@ -1,6 +1,6 @@
-
+
{{ $slot }}
\ No newline at end of file diff --git a/resources/views/vendor/mail/html/message.blade.php b/resources/views/vendor/mail/html/message.blade.php index 78bb11e..1eb1576 100644 --- a/resources/views/vendor/mail/html/message.blade.php +++ b/resources/views/vendor/mail/html/message.blade.php @@ -1,7 +1,7 @@ @component('mail::layout') {{-- Header --}} @slot('header') - @component('mail::header', ['url' => config('app.url'),'logo'=>url($site->email_logo)]) + @component('mail::header',['site'=>$site]) {{ $heading }} @endcomponent @endslot diff --git a/resources/views/vendor/mail/html/panel.blade.php b/resources/views/vendor/mail/html/panel.blade.php index 6375910..68de62e 100644 --- a/resources/views/vendor/mail/html/panel.blade.php +++ b/resources/views/vendor/mail/html/panel.blade.php @@ -1,5 +1,9 @@
- {{ $slot }} + @isset($url) + {{ $slot }} + @else + {{ $slot }} + @endisset
\ No newline at end of file diff --git a/resources/views/vendor/mail/html/themes/default.css b/resources/views/vendor/mail/html/themes/default.css index 0fe0fcb..56e1dd2 100644 --- a/resources/views/vendor/mail/html/themes/default.css +++ b/resources/views/vendor/mail/html/themes/default.css @@ -41,8 +41,9 @@ body{ border-radius: 10px; padding: 10px; font-weight: 300; - margin-top: 20px; + margin-top: 10px; font-size: 0.8em; + margin-bottom: 10px; } .main-body{ background: #ffffff; @@ -74,13 +75,16 @@ body{ font-weight: 300; font-style: normal; } -/* -- TO VALIDATE -- */ -a{ +.panel a{ text-decoration: underline; - color: #1cbbb4 + color: #f4f4f4; +} +.panel a:hover{ + text-decoration: none; + color: #ffffff; } -a:hover{text-decoration: none;} +/* -- TO VALIDATE -- */ h1{ font-weight: 300; color: #121212;