Skip to content

Commit

Permalink
#8 add notification for a new created proposal, the applicant and use…
Browse files Browse the repository at this point in the history
…rs get a notification. smtp needs to be configured in env
  • Loading branch information
scammo committed Apr 21, 2024
1 parent 5a3e557 commit 314e2f3
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 361 deletions.
29 changes: 3 additions & 26 deletions backend/.env.example.local.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
FRONTEND_URL="http://localhost:5173/#"

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
Expand All @@ -20,10 +21,6 @@ SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
Expand All @@ -32,27 +29,7 @@ MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MAIL_REPLY_TO="[email protected]"

JWT_SECRET=DgShc8SKxGUlu5px5PjnMjkTCQVZUsS8ZkW3gEMfwImdbCsQIH6apWtEyYCZlLGp
JWT_ALGO=HS256
JWT_ALGO=HS256
21 changes: 20 additions & 1 deletion backend/app/Http/Controllers/ProposalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

namespace App\Http\Controllers;

use App\Mail\ConfirmProposalCreated;
use App\Mail\InfoProposalCreated;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use App\Models\Track;
use App\Models\Proposal;
use App\Models\Opinion;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;

class ProposalController extends Controller
{
public function create(Request $request)
{
$track = Track::where('slug', $request->slug)->firstOrFail();
$track = Track::where('slug', $request->slug)
->with('users')
->firstOrFail();
$proposal = new Proposal();
$proposal->track_id = $track->id;
$proposal->name = $request->name;
Expand All @@ -21,6 +27,19 @@ public function create(Request $request)
$proposal->status = 'created';
$proposal->save();

try{
if($request->email){
// send recipent emails
Mail::to($request->email)->send(new ConfirmProposalCreated($proposal->id));
// send email to the track users
foreach($track->users as $user){
Mail::to($user->email)->send(new InfoProposalCreated($proposal->id, $proposal->name, env('FRONTEND_URL').'/proposal/'.$proposal->id));
}
}
}catch(\Exception $e){
Log::error($e);
}

return $proposal->only('id');
}

Expand Down
1 change: 1 addition & 0 deletions backend/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function updatePassword(User $user, Request $request){
}

public function createInitialRootUser(){
return;
if(User::where('username', 'root')->first()){
abort(403);
}
Expand Down
59 changes: 59 additions & 0 deletions backend/app/Mail/ConfirmProposalCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Queue\SerializesModels;

class ConfirmProposalCreated extends Mailable
{
use Queueable, SerializesModels;

public int $proposalId;

/**
* Create a new message instance.
*/
public function __construct($proposalId)
{
$this->proposalId = $proposalId;
}

/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Bewerbung erhalten | Application received',
replyTo: [
new Address(env('MAIL_REPLY_TO', env('MAIL_FROM_NAME'))),
],
);
}

/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.confirmProposal',
);
}

/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
59 changes: 59 additions & 0 deletions backend/app/Mail/InfoProposalCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class InfoProposalCreated extends Mailable
{
use Queueable, SerializesModels;

public int $proposalId;
public string $proposalName;
public string $pathToProposal;

/**
* Create a new message instance.
*/
public function __construct($proposalId, $proposalName, $pathToProposal)
{
$this->proposalId = $proposalId;
$this->proposalName = $proposalName;
$this->pathToProposal = $pathToProposal;
}

/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Es gibt eine neue Bewerbung '. $this->proposalId .' | There is a new application '. $this->proposalId,
);
}

/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.infoProposalCreated',
);
}

/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
Loading

0 comments on commit 314e2f3

Please sign in to comment.