Unverified Commit aae971c8 authored by Vipul Basapati's avatar Vipul Basapati Committed by GitHub

Merge pull request #279 from bvipul/develop

Mailables and New Flash function
parents f685c403 04e8d0d3
APP_NAME="Laravel Admin Panel" APP_NAME="Laravel Admin Panel"
APP_SHORT_NAME="LAP"
APP_ENV=local APP_ENV=local
APP_KEY=base64:O+TrollIDwasHEREtMG9kBc+/Q32exQLusNVhnq558w= APP_KEY=base64:O+TrollIDwasHEREtMG9kBc+/Q32exQLusNVhnq558w=
APP_DEBUG=true APP_DEBUG=true
......
...@@ -9,4 +9,29 @@ use Exception; ...@@ -9,4 +9,29 @@ use Exception;
*/ */
class GeneralException extends Exception class GeneralException extends Exception
{ {
/**
* message.
*
* @var string
*/
public $message;
/**
* dontHide.
*
* @var bool
*/
public $dontHide;
/**
* Constructor function.
*
* @param string $message
* @param bool $dontHide
*/
public function __construct($message, $dontHide = false)
{
$this->message = $message;
$this->dontHide = $dontHide;
}
} }
...@@ -53,7 +53,6 @@ class Handler extends ExceptionHandler ...@@ -53,7 +53,6 @@ class Handler extends ExceptionHandler
*/ */
public function render($request, Exception $exception) public function render($request, Exception $exception)
{ {
//dd($exception);
if (strpos($request->url(), '/api/') !== false) { if (strpos($request->url(), '/api/') !== false) {
\Log::debug('API Request Exception - '.$request->url().' - '.$exception->getMessage().(!empty($request->all()) ? ' - '.json_encode($request->except(['password'])) : '')); \Log::debug('API Request Exception - '.$request->url().' - '.$exception->getMessage().(!empty($request->all()) ? ' - '.json_encode($request->except(['password'])) : ''));
...@@ -112,6 +111,8 @@ class Handler extends ExceptionHandler ...@@ -112,6 +111,8 @@ class Handler extends ExceptionHandler
* All instances of GeneralException redirect back with a flash message to show a bootstrap alert-error * All instances of GeneralException redirect back with a flash message to show a bootstrap alert-error
*/ */
if ($exception instanceof GeneralException) { if ($exception instanceof GeneralException) {
session()->flash('dontHide', $exception->dontHide);
return redirect()->back()->withInput()->withFlashDanger($exception->getMessage()); return redirect()->back()->withInput()->withFlashDanger($exception->getMessage());
} }
......
...@@ -31,7 +31,7 @@ class PagesController extends APIController ...@@ -31,7 +31,7 @@ class PagesController extends APIController
{ {
$limit = $request->get('paginate') ? $request->get('paginate') : 25; $limit = $request->get('paginate') ? $request->get('paginate') : 25;
$orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC'; $orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC';
$sortBy = $request->get('sortBy') ? $request->get('sortBy') : 'created_at'; $sortBy = $request->get('sortBy') ? $request->get('sortBy') : config('module.pages.table', 'pages').'created_at';
return PagesResource::collection( return PagesResource::collection(
$this->repository->getForDataTable()->orderBy($sortBy, $orderBy)->paginate($limit) $this->repository->getForDataTable()->orderBy($sortBy, $orderBy)->paginate($limit)
......
...@@ -21,7 +21,7 @@ class LoginController extends Controller ...@@ -21,7 +21,7 @@ class LoginController extends Controller
use AuthenticatesUsers; use AuthenticatesUsers;
/** /**
* @var CMSPagesRepository * @var \App\Http\Utilities\PushNotification
*/ */
protected $notification; protected $notification;
...@@ -74,7 +74,7 @@ class LoginController extends Controller ...@@ -74,7 +74,7 @@ class LoginController extends Controller
if (!$user->isConfirmed()) { if (!$user->isConfirmed()) {
access()->logout(); access()->logout();
throw new GeneralException(trans('exceptions.frontend.auth.confirmation.resend', ['user_id' => $user->id])); throw new GeneralException(trans('exceptions.frontend.auth.confirmation.resend', ['user_id' => $user->id]), true);
} elseif (!$user->isActive()) { } elseif (!$user->isActive()) {
access()->logout(); access()->logout();
......
...@@ -95,11 +95,12 @@ class ResetPasswordController extends Controller ...@@ -95,11 +95,12 @@ class ResetPasswordController extends Controller
/** /**
* Get the response for a successful password reset. * Get the response for a successful password reset.
* *
* @param \Illuminate\Http\Request $request
* @param string $response * @param string $response
* *
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
*/ */
protected function sendResetResponse($response) protected function sendResetResponse($request, $response)
{ {
return redirect()->route(homeRoute())->withFlashSuccess(trans($response)); return redirect()->route(homeRoute())->withFlashSuccess(trans($response));
} }
......
...@@ -34,21 +34,6 @@ class UserEventListener ...@@ -34,21 +34,6 @@ class UserEventListener
\Log::info('User Registered: '.$event->user->full_name); \Log::info('User Registered: '.$event->user->full_name);
} }
/**
* @param $event
*/
/*public function onRegistered($event)
{
\Log::info('User Registered: '.$event->user->first_name);
// Send email to the user
$options = [
'data' => $event->user,
'email_template_type' => 1,
];
createNotification('', 1, 2, $options);
}*/
/** /**
* @param $event * @param $event
*/ */
......
...@@ -147,23 +147,22 @@ trait UserAttribute ...@@ -147,23 +147,22 @@ trait UserAttribute
switch ($this->status) { switch ($this->status) {
case 0: case 0:
if (access()->allow('activate-user')) { if (access()->allow('activate-user')) {
$name = $class == '' ? 'Active' : ''; $name = $class == '' ? 'Activate' : '';
return '<a class="'.$class.'" href="'.route('admin.access.user.mark', [$this, 1]).'"><i class="fa fa-check-square" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.activate').'"></i>'.$name.'</a>'; return '<a class="'.$class.'" href="'.route('admin.access.user.mark', [$this, 1]).'"><i class="fa fa-check-square" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.activate').'"></i>'.$name.'</a>';
} }
// No break break;
case 1: case 1:
if (access()->allow('deactivate-user')) { if (access()->allow('deactivate-user')) {
$name = ($class == '') ? 'Deactive' : ''; $name = ($class == '') ? 'Deactivate' : '';
return '<a class="'.$class.'" href="'.route('admin.access.user.mark', [$this, 0]).'"><i class="fa fa-square" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.deactivate').'"></i>'.$name.'</a>'; return '<a class="'.$class.'" href="'.route('admin.access.user.mark', [$this, 0]).'"><i class="fa fa-square" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.deactivate').'"></i>'.$name.'</a>';
} }
// No break break;
default: default:
return ''; return '';
// No break
} }
} }
......
<?php
namespace App\Notifications\Frontend\Auth;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
/**
* Class UserChangedPassword.
*/
class UserChangedPassword extends Notification
{
use Queueable;
/**
* @var
*/
protected $password;
/**
* UserChangedPassword constructor.
*
* @param $password
*/
public function __construct($password)
{
$this->password = $password;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param \App\Models\Access\User\User $user
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($user)
{
return (new MailMessage())
->view('emails.changed-password', ['password' => $this->password]);
}
}
...@@ -52,6 +52,6 @@ class UserNeedsConfirmation extends Notification ...@@ -52,6 +52,6 @@ class UserNeedsConfirmation extends Notification
$confirmation_url = route('frontend.auth.account.confirm', $user->confirmation_code); $confirmation_url = route('frontend.auth.account.confirm', $user->confirmation_code);
return (new MailMessage()) return (new MailMessage())
->view('emails.template', ['confirmation_url' => $confirmation_url]); ->view('emails.user-confirmation', ['confirmation_url' => $confirmation_url]);
} }
} }
...@@ -50,10 +50,9 @@ class UserNeedsPasswordReset extends Notification ...@@ -50,10 +50,9 @@ class UserNeedsPasswordReset extends Notification
*/ */
public function toMail($notifiable) public function toMail($notifiable)
{ {
$reset_password_route = route('frontend.auth.password.reset.form', $this->token);
return (new MailMessage()) return (new MailMessage())
->subject(app_name().': '.trans('strings.emails.auth.password_reset_subject')) ->view('emails.reset-password', ['reset_password_url' => $reset_password_route]);
->line(trans('strings.emails.auth.password_cause_of_email'))
->action(trans('buttons.emails.auth.reset_password'), route('frontend.auth.password.reset.form', $this->token))
->line(trans('strings.emails.auth.password_if_not_requested'));
} }
} }
...@@ -6,6 +6,7 @@ use App\Events\Frontend\Auth\UserConfirmed; ...@@ -6,6 +6,7 @@ use App\Events\Frontend\Auth\UserConfirmed;
use App\Exceptions\GeneralException; use App\Exceptions\GeneralException;
use App\Models\Access\User\SocialLogin; use App\Models\Access\User\SocialLogin;
use App\Models\Access\User\User; use App\Models\Access\User\User;
use App\Notifications\Frontend\Auth\UserChangedPassword;
use App\Notifications\Frontend\Auth\UserNeedsConfirmation; use App\Notifications\Frontend\Auth\UserNeedsConfirmation;
use App\Repositories\Backend\Access\Role\RoleRepository; use App\Repositories\Backend\Access\Role\RoleRepository;
use App\Repositories\BaseRepository; use App\Repositories\BaseRepository;
...@@ -286,13 +287,7 @@ class UserRepository extends BaseRepository ...@@ -286,13 +287,7 @@ class UserRepository extends BaseRepository
$user->password = bcrypt($input['password']); $user->password = bcrypt($input['password']);
if ($user->save()) { if ($user->save()) {
$input['email'] = $user->email; $user->notify(new UserChangedPassword($input['password']));
// Send email to the user
$options = [
'data' => $input,
'email_template_type' => 4,
];
createNotification('', $user->id, 2, $options);
return true; return true;
} }
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<script> <script>
export default { export default {
props: ["message", "type"], props: ["message", "type", "dontHide"],
data() { data() {
return { return {
...@@ -17,9 +17,10 @@ export default { ...@@ -17,9 +17,10 @@ export default {
}, },
created() { created() {
var context = this; const context = this;
if (this.message && this.type) { if (this.message && this.type) {
this.flash(this.message, this.type); this.flash(this.message, this.type, this.dontHide);
} }
window.events.$on("flash", function(message, type) { window.events.$on("flash", function(message, type) {
...@@ -28,7 +29,7 @@ export default { ...@@ -28,7 +29,7 @@ export default {
}, },
methods: { methods: {
flash(message, type) { flash(message, type, dontHide = false) {
if (! type) { if (! type) {
type = "info"; type = "info";
...@@ -38,7 +39,9 @@ export default { ...@@ -38,7 +39,9 @@ export default {
this.typeClass = "alert alert-" + type; this.typeClass = "alert alert-" + type;
this.show = true; this.show = true;
if(! dontHide) {
this.hide(); this.hide();
}
}, },
hide() { hide() {
......
@extends('emails.layouts.app')
@section('content')
<div class="content">
<td align="left">
<table border="0" width="80%" align="center" cellpadding="0" cellspacing="0" class="container590">
<tr>
<td align="left" style="color: #888888; width:20px; font-size: 16px; line-height: 24px;">
<!-- section text ======-->
<p style="line-height: 24px; margin-bottom:15px;">
Hello!
</p>
<p style="line-height: 24px; margin-bottom:20px;">
Your Password has successfully been changed to : {{ $password }}
</p>
<p style="line-height: 24px; margin-bottom:20px;">
If you did not change your password, try resetting your password using above password.
</p>
<p style="line-height: 24px">
Regards,</br>
@yield('title', app_name())
</p>
<br/>
@include('emails.layouts.footer')
</td>
</tr>
</table>
</td>
</div>
@endsection
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" /> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
<meta name="viewport" content="width=600,initial-scale = 2.3,user-scalable=no"> <meta name="viewport" content="width=600,initial-scale = 2.3,user-scalable=no">
<!--[if !mso]><!-- --> <!--<![if !mso]-->
<link href="https://fonts.googleapis.com/css?family=Fira+Sans|Fira+Sans+Condensed|Raleway" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Fira+Sans|Fira+Sans+Condensed|Raleway" rel="stylesheet">
<!--<![endif]--> <!--<![endif]-->
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
font-size: 14px; font-size: 14px;
border: 0; border: 0;
padding:10px; padding:10px;
width: 100%;
} }
.lap{ .lap{
...@@ -67,9 +68,30 @@ ...@@ -67,9 +68,30 @@
margin-right: 25px; margin-right: 25px;
} }
.content{ .main-header {
color: #343434;
font-size: 24px;
font-weight:300;
line-height: 35px;
}
.main-header .brand {
letter-spacing: 5px;
font-size: 28px;
}
.main-header .tagline {
font-size: 16px;
}
.small {
font-size: 10px;
}
.center {
text-align: center;
} }
/* ----------- responsivity ----------- */ /* ----------- responsivity ----------- */
@media only screen and (max-width: 640px) { @media only screen and (max-width: 640px) {
...@@ -133,8 +155,6 @@ ...@@ -133,8 +155,6 @@
} }
</style> </style>
</head> </head>
<body class="respond" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <body class="respond" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div class="container"> <div class="container">
...@@ -143,26 +163,19 @@ ...@@ -143,26 +163,19 @@
<td align="center"> <td align="center">
<table border="0" align="center" width="590" cellpadding="0" cellspacing="0" class="container590"> <table border="0" align="center" width="590" cellpadding="0" cellspacing="0" class="container590">
<tr> <tr>
<td align="center" style="color: #343434; font-size: 24px; font-family: Quicksand, Calibri, sans-serif; font-weight:700;letter-spacing: 3px; line-height: 35px;" <td align="center">
<table border="0" width="40" align="center" cellpadding="0" cellspacing="0" bgcolor="eeeeee">
<tr>
<td align="center" style=""
class="main-header"> class="main-header">
<!-- section text ======--> <!-- section text ======-->
<div class="brand">{{ env('APP_SHORT_NAME', 'LAP') }}</div>
<div style="line-height: 35px"> <div class="tagline">
{{ app_name() }} {{ app_name() }}
</div> </div>
</td> </td>
</tr> </tr>
<tr>
<td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
</tr>
<tr>
<td align="center">
<table border="0" width="40" align="center" cellpadding="0" cellspacing="0" bgcolor="eeeeee">
<tr>
<td height="2" style="font-size: 2px; line-height: 2px;">&nbsp;</td>
</tr>
</table> </table>
</td> </td>
</tr> </tr>
...@@ -172,72 +185,7 @@ ...@@ -172,72 +185,7 @@
</tr> </tr>
<tr> <tr>
<div class="content"> @yield('content')
<td align="left">
<table border="0" width="80%" align="center" cellpadding="0" cellspacing="0" class="container590">
<tr>
<td align="left" style="color: #888888; width:20px; font-size: 16px; font-family: 'Work Sans', Calibri, sans-serif; line-height: 24px;">
<!-- section text ======-->
<p style="line-height: 24px; margin-bottom:15px;">
Hello!
</p>
<p style="line-height: 24px; margin-bottom:20px;">
Click here to confirm your account:
</p>
<table border="0" align="center" width="180" cellpadding="0" cellspacing="0" bgcolor="5caad2" style="margin-bottom:20px;">
<tr>
<td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
</tr>
<tr>
<td align="center" style="color: #ffffff; font-size: 14px; font-family: 'Work Sans', Calibri, sans-serif; line-height: 22px; letter-spacing: 2px;">
<!-- main section button -->
<div style="line-height: 22px;">
<a href="{{ $confirmation_url }}" style="color: #ffffff; text-decoration: none;">Confirm Account</a>
</div>
</td>
</tr>
<tr>
<td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
</tr>
</table>
<p style="line-height: 24px; margin-bottom:20px;">
Thank you for using our application!
</p>
<p style="line-height: 24px">
Regards,</br>
@yield('title', app_name())
</p>
<br><br>
<p style="line-height: 24px; margin-bottom:20px;">
If you’re having trouble clicking the "Confirm Account" button, copy and paste the URL below into your web browser:
</p>
<p style="line-height: 24px; margin-bottom:20px;">
<a href="{{ $confirmation_url }}" target="_blank" class="lap">
{{ $confirmation_url}}
</a>
</p>
<p style="line-height: 24px; margin-bottom: 20px;">
©2018 <a href="" target="_blank" class="lap">@yield('title', app_name())</a>
All Rights are Reserved.
</p>
</td>
</tr>
</table>
</td>
</div>
</tr> </tr>
</table> </table>
</td> </td>
......
<p class="small center" style="line-height: 24px; margin-bottom: 20px;">
©2018 <a href="{{ url('/') }}" target="_blank" class="lap">@yield('title', app_name())</a>
All Rights are Reserved.
</p>
\ No newline at end of file
@extends('emails.layouts.app')
@section('content')
<div class="content">
<td align="left">
<table border="0" width="80%" align="center" cellpadding="0" cellspacing="0" class="container590">
<tr>
<td align="left" style="color: #888888; width:20px; font-size: 16px; line-height: 24px;">
<!-- section text ======-->
<p style="line-height: 24px; margin-bottom:15px;">
Hello!
</p>
<p style="line-height: 24px; margin-bottom:20px;">
You are receiving this email because we received a password reset request for your account.
</p>
<table border="0" align="center" width="180" cellpadding="0" cellspacing="0" bgcolor="5caad2" style="margin-bottom:20px; background: #003bd7; border-radius: 5px;">
<tr>
<td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
</tr>
<tr>
<td align="center" style="color: #ffffff; font-size: 14px; line-height: 22px;letter-spacing: 1px;font-weight: bold;">
<!-- main section button -->
<div style="line-height: 22px;">
<a href="{{ $reset_password_url }}" style="color: #ffffff; text-decoration: none;">Reset Password</a>
</div>
</td>
</tr>
<tr>
<td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
</tr>
</table>
<p style="line-height: 24px; margin-bottom:20px;">
If you did not request a password reset, no further action is required.
</p>
<p style="line-height: 24px">
Regards,</br>
@yield('title', app_name())
</p>
<br/>
<p class="small" style="line-height: 24px; margin-bottom:20px;">
If you’re having trouble clicking the "Reset Password" button, copy and paste the URL below into your web browser:
</p>
<p class="small" style="line-height: 24px; margin-bottom:20px;">
<a href="{{ $reset_password_url }}" target="_blank" class="lap">
{{ $reset_password_url}}
</a>
</p>
@include('emails.layouts.footer')
</td>
</tr>
</table>
</td>
</div>
@endsection
\ No newline at end of file
@extends('emails.layouts.app')
@section('content')
<div class="content">
<td align="left">
<table border="0" width="80%" align="center" cellpadding="0" cellspacing="0" class="container590">
<tr>
<td align="left" style="color: #888888; width:20px; font-size: 16px; line-height: 24px;">
<!-- section text ======-->
<p style="line-height: 24px; margin-bottom:15px;">
Hello!
</p>
<p style="line-height: 24px; margin-bottom:20px;">
Click here to confirm your account:
</p>
<table border="0" align="center" width="180" cellpadding="0" cellspacing="0" bgcolor="5caad2" style="margin-bottom:20px; background: #003bd7; border-radius: 5px;">
<tr>
<td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
</tr>
<tr>
<td align="center" style="color: #ffffff; font-size: 14px; line-height: 22px;letter-spacing: 1px;font-weight: bold;">
<!-- main section button -->
<div style="line-height: 22px;">
<a href="{{ $confirmation_url }}" style="color: #ffffff; text-decoration: none;">Confirm Account</a>
</div>
</td>
</tr>
<tr>
<td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
</tr>
</table>
<p style="line-height: 24px; margin-bottom:20px;">
Thank you for using our application!
</p>
<p style="line-height: 24px">
Regards,</br>
@yield('title', app_name())
</p>
<br/>
<p class="small" style="line-height: 24px; margin-bottom:20px;">
If you’re having trouble clicking the "Confirm Account" button, copy and paste the URL below into your web browser:
</p>
<p class="small" style="line-height: 24px; margin-bottom:20px;">
<a href="{{ $confirmation_url }}" target="_blank" class="lap">
{{ $confirmation_url}}
</a>
</p>
@include('emails.layouts.footer')
</td>
</tr>
</table>
</td>
</div>
@endsection
\ No newline at end of file
@php @php
$message = ''; $message = '';
$type = ''; $type = '';
@endphp $dontHide = false;
if(session()->has('dontHide')) {
$dontHide = session()->get('dontHide');
}
@endphp
@if ($errors->any()) @if ($errors->any())
@php @php
$type = 'danger'; $type = 'danger';
...@@ -80,4 +84,4 @@ ...@@ -80,4 +84,4 @@
@endif @endif
<!-- Flash Message Vue component --> <!-- Flash Message Vue component -->
<flash message="{!! $message !!}" type="{{ $type }}"></flash> <flash message="{!! $message !!}" type="{{ $type }}" dont-hide="{{ $dontHide }}"></flash>
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment