Skip to content

Commit

Permalink
New First Admin Notification (#5147)
Browse files Browse the repository at this point in the history
* New First Admin Notification

* Include Last name in Welcome and First admin Notifications
  • Loading branch information
fordster78 authored and snipe committed Mar 3, 2018
1 parent 688a325 commit 68a9855
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 4 deletions.
14 changes: 12 additions & 2 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use App\Http\Requests\ImageUploadRequest;
use App\Http\Requests\SettingsLdapRequest;
use App\Helpers\Helper;
use App\Notifications\FirstAdminNotification;

/**
* This controller handles all actions related to Settings for
Expand Down Expand Up @@ -186,11 +187,20 @@ public function postSaveFirstAdmin(SetupUserRequest $request)
$settings->save();

if (Input::get('email_creds')=='1') {
Mail::send(['text' => 'emails.firstadmin'], $data, function ($m) use ($data) {
$data = array();
$data['email'] = $user->email;
$data['username'] = $user->username;
$data['first_name'] = $user->first_name;
$data['last_name'] = $user->last_name;
$data['password'] = $user->password;

$user->notify(new FirstAdminNotification($data));

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


Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function store(SaveUserRequest $request)
$data['email'] = e($request->input('email'));
$data['username'] = e($request->input('username'));
$data['first_name'] = e($request->input('first_name'));
$data['last_name'] = e($request->input('last_name'));
$data['password'] = e($request->input('password'));

$user->notify(new WelcomeNotification($data));
Expand Down Expand Up @@ -197,6 +198,7 @@ public function apiStore(SaveUserRequest $request)
$data['email'] = $request->input('email');
$data['username'] = $request->input('username');
$data['first_name'] = $request->input('first_name');
$data['last_name'] = e($request->input('last_name'));
$data['password'] = $request->input('password');

$user->notify(new WelcomeNotification($data));
Expand Down Expand Up @@ -860,6 +862,7 @@ public function postImport()
$data['email'] = trim(e($row[4]));
$data['username'] = trim(e($row[2]));
$data['first_name'] = trim(e($row[0]));
$data['last_name'] = trim(e($row[1]));
$data['password'] = $pass;

if ($newuser['email']) {
Expand Down
67 changes: 67 additions & 0 deletions app/Notifications/FirstAdminNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Notifications;

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

class FirstAdminNotification 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['last_name'] = $content['last_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'] . ' ' . $this->_data['last_name'] ]))
->markdown('notifications.FirstAdmin', $this->_data);
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
3 changes: 2 additions & 1 deletion app/Notifications/WelcomeNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(array $content)
{
$this->_data['email'] = $content['email'];
$this->_data['first_name'] = $content['first_name'];
$this->_data['last_name'] = $content['last_name'];
$this->_data['username'] = $content['username'];
$this->_data['password'] = $content['password'];
$this->_data['url'] = url('/');
Expand All @@ -47,7 +48,7 @@ public function via($notifiable)
public function toMail($notifiable)
{
return (new MailMessage)
->subject(trans('mail.welcome', ['name' => $this->_data['first_name'] ]))
->subject(trans('mail.welcome', ['name' => $this->_data['first_name'] . ' ' . $this->_data['last_name'] ]))
->markdown('notifications.Welcome', $this->_data);
}

Expand Down
17 changes: 17 additions & 0 deletions resources/views/notifications/FirstAdmin.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@component('mail::message')
{{ trans('mail.hello') }} {{ $first_name }} {{$last_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
2 changes: 1 addition & 1 deletion resources/views/notifications/Welcome.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@component('mail::message')
{{ trans('mail.hello') }} {{ $first_name }},
{{ trans('mail.hello') }} {{ $first_name }} {{$last_name}},

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

Expand Down

0 comments on commit 68a9855

Please sign in to comment.