Skip to content

Commit

Permalink
New Welcome Notification (#5146)
Browse files Browse the repository at this point in the history
* New Test Notification

Created Test Notification.
Updated Vendor Mail message.blade files.
Updated api settings controller to use Notification Façade.

* Add show URL in Emails condition

* New Welcome Notification
  • Loading branch information
fordster78 authored and snipe committed Mar 3, 2018
1 parent 30c5cc1 commit 688a325
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 8 deletions.
23 changes: 16 additions & 7 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Illuminate\Http\Request;
use Gate;
use Artisan;
use App\Notifications\WelcomeNotification;

/**
* This controller handles all actions related to Users for
Expand Down Expand Up @@ -148,11 +149,13 @@ public function store(SaveUserRequest $request)
$data['first_name'] = e($request->input('first_name'));
$data['password'] = e($request->input('password'));

Mail::send('emails.send-login', $data, function ($m) use ($user) {
$user->notify(new WelcomeNotification($data));

/* Mail::send('emails.send-login', $data, function ($m) use ($user) {
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
$m->subject(trans('mail.welcome', ['name' => $user->first_name]));
});
});*/
}
return redirect::route('users.index')->with('success', trans('admin/users/message.success.create'));
}
Expand Down Expand Up @@ -192,15 +195,17 @@ public function apiStore(SaveUserRequest $request)
// Send the credentials through email
$data = array();
$data['email'] = $request->input('email');
$data['username'] = $request->input('username');
$data['first_name'] = $request->input('first_name');
$data['last_name'] = $request->input('last_name');
$data['password'] = $request->input('password');

Mail::send('emails.send-login', $data, function ($m) use ($user) {
$user->notify(new WelcomeNotification($data));

/*Mail::send('emails.send-login', $data, function ($m) use ($user) {
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
$m->subject(trans('mail.welcome', ['name' => $user->first_name]));
});
});*/
}

return JsonResponse::create($user);
Expand Down Expand Up @@ -852,16 +857,20 @@ public function postImport()
// Send the credentials through email
if ($row[3] != '') {
$data = array();
$data['email'] = trim(e($row[4]));
$data['username'] = trim(e($row[2]));
$data['first_name'] = trim(e($row[0]));
$data['password'] = $pass;

if ($newuser['email']) {
Mail::send('emails.send-login', $data, function ($m) use ($newuser) {
$user = User::where('username', $row[2])->first();
$user->notify(new WelcomeNotification($data));

/*Mail::send('emails.send-login', $data, function ($m) use ($newuser) {
$m->to($newuser['email'], $newuser['first_name'] . ' ' . $newuser['last_name']);
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
$m->subject(trans('mail.welcome', ['name' => $newuser['first_name']]));
});
});*/
}
}
}
Expand Down
66 changes: 66 additions & 0 deletions app/Notifications/WelcomeNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class WelcomeNotification extends Notification
{
use Queueable;

private $_data = array();

/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(array $content)
{
$this->_data['email'] = $content['email'];
$this->_data['first_name'] = $content['first_name'];
$this->_data['username'] = $content['username'];
$this->_data['password'] = $content['password'];
$this->_data['url'] = url('/');
}

/**
* 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 mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject(trans('mail.welcome', ['name' => $this->_data['first_name'] ]))
->markdown('notifications.Welcome', $this->_data);
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
6 changes: 5 additions & 1 deletion resources/views/notifications/Test.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
{{ trans('mail.test_mail_text') }}

Thanks,<br>
{{ $snipeSettings->site_name }}
@if ($snipeSettings->show_url_in_emails=='1')
<p><a href="{{ url('/') }}">{{ $snipeSettings->site_name }}</a></p>
@else
<p>{{ $snipeSettings->site_name }}</p>
@endif
@endcomponent
19 changes: 19 additions & 0 deletions resources/views/notifications/Welcome.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@component('mail::message')
{{ trans('mail.hello') }} {{ $first_name }},

{{ trans('mail.admin_has_created', ['web' => $snipeSettings->site_name]) }}

{{ trans('mail.login') }} {{ $username }} <br>
{{ trans('mail.password') }} {{ $password }}

@component('mail::button', ['url' => $url])
Go To {{$snipeSettings->site_name}}
@endcomponent

{{ trans('mail.best_regards') }} <br>
@if ($snipeSettings->show_url_in_emails=='1')
<p><a href="{{ url('/') }}">{{ $snipeSettings->site_name }}</a></p>
@else
<p>{{ $snipeSettings->site_name }}</p>
@endif
@endcomponent

0 comments on commit 688a325

Please sign in to comment.