diff --git a/app/Http/Controllers/Auth/ContactForgotPasswordController.php b/app/Http/Controllers/Auth/ContactForgotPasswordController.php index 24481f476713..cb5e4212334d 100644 --- a/app/Http/Controllers/Auth/ContactForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ContactForgotPasswordController.php @@ -12,8 +12,10 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use App\Libraries\MultiDB; use Illuminate\Contracts\View\Factory; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Password; use Illuminate\View\View; @@ -65,4 +67,31 @@ class ContactForgotPasswordController extends Controller { return Password::broker('contacts'); } + + public function sendResetLinkEmail(Request $request) + { + //MultiDB::userFindAndSetDb($request->input('email')); + + $user = MultiDB::hasContact(['email' => $request->input('email')]); + + $this->validateEmail($request); + + // We will send the password reset link to this user. Once we have attempted + // to send the link, we will examine the response then see the message we + // need to show to the user. Finally, we'll send out a proper response. + $response = $this->broker()->sendResetLink( + $this->credentials($request) + ); + + if ($request->ajax()) { + return $response == Password::RESET_LINK_SENT + ? response()->json(['message' => 'Reset link sent to your email.', 'status' => true], 201) + : response()->json(['message' => 'Email not found', 'status' => false], 401); + } + + return $response == Password::RESET_LINK_SENT + ? $this->sendResetLinkResponse($request, $response) + : $this->sendResetLinkFailedResponse($request, $response); + } + } diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 7044ace379fe..4d81705ea3f6 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use App\Libraries\MultiDB; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; use Illuminate\Http\Request; use Illuminate\Support\Facades\Password; @@ -103,6 +104,10 @@ class ForgotPasswordController extends Controller */ public function sendResetLinkEmail(Request $request) { + //MultiDB::userFindAndSetDb($request->input('email')); + + $user = MultiDB::hasUser(['email' => $request->input('email')]); + $this->validateEmail($request); // We will send the password reset link to this user. Once we have attempted diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 2fed0652a6b9..3240283af898 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -142,6 +142,31 @@ class MultiDB return null; } + /** + * @param array $data + * @return User|null + */ + public static function hasContact(array $data) : ?ClientContact + { + if (! config('ninja.db.multi_db_enabled')) { + return ClientContact::where($data)->withTrashed()->first(); + } + + foreach (self::$dbs as $db) { + self::setDB($db); + + $user = ClientContacts::where($data)->withTrashed()->first(); + + if ($user) { + return $user; + } + } + + self::setDefaultDatabase(); + + return null; + } + public static function contactFindAndSetDb($token) :bool { foreach (self::$dbs as $db) { @@ -160,7 +185,7 @@ class MultiDB public static function userFindAndSetDb($email) : bool { - //multi-db active + //multi-db active foreach (self::$dbs as $db) { if (User::on($db)->where(['email' => $email])->get()->count() >= 1) { // if user already exists, validation will fail return true; diff --git a/app/Mail/Admin/ResetPasswordObject.php b/app/Mail/Admin/ResetPasswordObject.php new file mode 100644 index 000000000000..ec19c4cafd6c --- /dev/null +++ b/app/Mail/Admin/ResetPasswordObject.php @@ -0,0 +1,53 @@ +token = $token; + $this->user = $user; + $this->company = $company; + } + + public function build() + { + + $data = [ + 'title' => ctrans('texts.your_password_reset_link'), + 'message' => ctrans('texts.reset_password'), + 'url' => route('password.reset', ['token' => $this->token, 'email' => $this->user->email]), + 'button' => ctrans('texts.reset'), + 'signature' => $this->company->settings->email_signature, + 'settings' => $this->company->settings, + 'logo' => $this->company->present()->logo(), + ]; + + $mail_obj = new \stdClass; + $mail_obj->subject = ctrans('texts.your_password_reset_link'); + $mail_obj->data = $data; + $mail_obj->markdown = 'email.admin.generic'; + $mail_obj->tag = $this->company->company_key; + + return $mail_obj; + } +} \ No newline at end of file diff --git a/app/Models/User.php b/app/Models/User.php index 9e0133057188..f5e94281a502 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -11,6 +11,10 @@ namespace App\Models; +use App\Jobs\Mail\NinjaMailer; +use App\Jobs\Mail\NinjaMailerJob; +use App\Jobs\Mail\NinjaMailerObject; +use App\Mail\Admin\ResetPasswordObject; use App\Models\Presenters\UserPresenter; use App\Notifications\ResetPasswordNotification; use App\Utils\Traits\MakesHash; @@ -371,6 +375,15 @@ class User extends Authenticatable implements MustVerifyEmail */ public function sendPasswordResetNotification($token) { - $this->notify(new ResetPasswordNotification($token)); + + $nmo = new NinjaMailerObject; + $nmo->mailable = new NinjaMailer( (new ResetPasswordObject($token, $this, $this->account->default_company))->build()); + $nmo->to_user = $this; + $nmo->settings = $this->account->default_company->settings; + $nmo->company = $this->account->default_company; + + NinjaMailerJob::dispatch($nmo); + + //$this->notify(new ResetPasswordNotification($token)); } } diff --git a/app/Notifications/GmailTestNotification.php b/app/Notifications/GmailTestNotification.php deleted file mode 100644 index c815830389c5..000000000000 --- a/app/Notifications/GmailTestNotification.php +++ /dev/null @@ -1,73 +0,0 @@ -line('The introduction to the notification.') - ->action('Notification Action', url('/')) - ->line('Thank you for using our application!'); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} diff --git a/app/Notifications/NewAccountCreated.php b/app/Notifications/NewAccountCreated.php index 3f692c009a59..d21fc554bb7a 100644 --- a/app/Notifications/NewAccountCreated.php +++ b/app/Notifications/NewAccountCreated.php @@ -20,6 +20,7 @@ use Illuminate\Notifications\Notification; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +//@deprecated class NewAccountCreated extends Notification { //use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; @@ -50,7 +51,7 @@ class NewAccountCreated extends Notification */ public function via($notifiable) { - return ['slack', 'mail']; + return ['slack']; } /** @@ -61,26 +62,6 @@ class NewAccountCreated extends Notification */ public function toMail($notifiable) { - $user_name = $this->user->first_name.' '.$this->user->last_name; - $email = $this->user->email; - $ip = $this->user->ip; - - $data = [ - 'title' => ctrans('texts.new_signup'), - 'message' => ctrans('texts.new_signup_text', ['user' => $user_name, 'email' => $email, 'ip' => $ip]), - 'url' => config('ninja.web_url'), - 'button' => ctrans('texts.account_login'), - 'signature' => $this->company->settings->email_signature, - 'logo' => $this->company->present()->logo(), - 'settings' => $this->company->settings, - ]; - - return (new MailMessage) - ->subject(ctrans('texts.new_signup')) - ->withSwiftMessage(function ($message) { - $message->getHeaders()->addTextHeader('Tag', $this->company->company_key); - }) - ->markdown('email.admin.generic', $data); } /** diff --git a/app/Notifications/ResetPasswordNotification.php b/app/Notifications/ResetPasswordNotification.php index ff1162fa2dd6..387e79441539 100644 --- a/app/Notifications/ResetPasswordNotification.php +++ b/app/Notifications/ResetPasswordNotification.php @@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; +//@deprecated class ResetPasswordNotification extends Notification { // use Queueable; @@ -30,7 +31,7 @@ class ResetPasswordNotification extends Notification */ public function via($notifiable) { - return ['mail']; + return []; } /** diff --git a/resources/views/email/auth/password-reset.blade.php b/resources/views/email/auth/password-reset.blade.php index 2f366cf1f224..ac5ebb54e274 100644 --- a/resources/views/email/auth/password-reset.blade.php +++ b/resources/views/email/auth/password-reset.blade.php @@ -1,19 +1,14 @@ @component('email.template.master', ['design' => 'light', 'whitelabel' => false]) @slot('header') - @include('email.components.header', ['logo' => 'https://www.invoiceninja.com/wp-content/uploads/2015/10/logo-white-horizontal-1.png']) + @include('email.components.header', ['logo' => $logo]) @endslot -
You are receiving this email because we received a password reset request for your account.
+{{ ctrans('texts.reset_password') }}
- Reset Password + {{ ctrans('texts.reset') }} -- If you’re having trouble clicking the "Reset Password" button, copy and paste the URL below into your web - browser: -
- {{ $link }} @endcomponent