-
Notifications
You must be signed in to change notification settings - Fork 6
Send new Gitea account credentials via Mailtrap #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
|
|
||
| namespace App\Notifications; | ||
|
|
||
| use App\Notifications\Channels\MailtrapChannel; | ||
| use App\Notifications\Messages\MailtrapMessage; | ||
| use Illuminate\Bus\Queueable; | ||
| use Illuminate\Contracts\Queue\ShouldQueue; | ||
| use Illuminate\Notifications\Notification; | ||
| use Illuminate\Support\Facades\View; | ||
|
|
||
| class GiteaAccountCredentialsNotification extends Notification implements ShouldQueue | ||
| { | ||
| use Queueable; | ||
|
|
||
| public function __construct( | ||
| public string $giteaUsername, | ||
| public string $temporaryPassword, | ||
| ) {} | ||
|
|
||
| /** | ||
| * @return array<int, string> | ||
| */ | ||
| public function via(object $notifiable): array | ||
| { | ||
| return [MailtrapChannel::class]; | ||
| } | ||
|
|
||
| public function toMailtrap(object $notifiable): MailtrapMessage | ||
| { | ||
| $giteaUrl = config('services.gitea.url'); | ||
|
|
||
| $html = View::make('emails.gitea-account-credentials', [ | ||
| 'user' => $notifiable, | ||
| 'giteaUsername' => $this->giteaUsername, | ||
| 'temporaryPassword' => $this->temporaryPassword, | ||
| 'giteaUrl' => $giteaUrl, | ||
| ])->render(); | ||
|
|
||
| $textLines = [ | ||
| 'A Gitea account has been created for you on '.config('app.name').'.', | ||
| '', | ||
| 'Username: '.$this->giteaUsername, | ||
| 'Temporary password: '.$this->temporaryPassword, | ||
| '', | ||
| 'You must change this password when you first sign in to Gitea.', | ||
|
Comment on lines
+41
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The introductory sentence in the text version of the email differs from the HTML version, and it is missing the greeting. It's better to keep the messaging consistent across both formats to ensure a uniform user experience. 'Hello ' . $notifiable->name . ',',
'',
'A Gitea account has been created for you so you can collaborate on remote work repositories.',
'',
'Username: ' . $this->giteaUsername,
'Temporary password: ' . $this->temporaryPassword,
'',
'You must change this password when you first sign in to Gitea.', |
||
| ]; | ||
|
|
||
| if (filled($giteaUrl)) { | ||
| $textLines[] = ''; | ||
| $textLines[] = 'Sign in: '.rtrim((string) $giteaUrl, '/'); | ||
| } | ||
|
|
||
| return MailtrapMessage::create() | ||
| ->subject('Your Gitea account credentials') | ||
| ->text(implode("\n", $textLines)) | ||
| ->html($html) | ||
| ->category('Gitea Account'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| use App\Models\CompanyJobApplication; | ||
| use App\Models\Developer; | ||
| use App\Models\User; | ||
| use App\Notifications\GiteaAccountCredentialsNotification; | ||
| use Illuminate\Support\Str; | ||
| use RuntimeException; | ||
|
|
||
|
|
@@ -117,6 +118,8 @@ public function ensureUserHasGiteaAccount(User $user): void | |
| } | ||
|
|
||
| $user->forceFill(['gitea_username' => $login])->save(); | ||
|
|
||
| $user->notify(new GiteaAccountCredentialsNotification($login, $password)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The notification is dispatched after the |
||
| } | ||
|
|
||
| /** | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The temporary password is stored as a public property on a queued notification. When the notification is queued, these properties are serialized and stored in plain text in the queue storage (e.g., Redis or the
jobstable). This exposes sensitive credentials to anyone with access to the queue or logs. While it is a temporary password, consider encrypting this data or using a flow that doesn't involve sending plain-text passwords through the queue.