commit 242098894796da87540934e37270d300990f4a9b Author: smarcet Date: Mon Oct 12 14:48:19 2020 -0300 Fixed email wording Change-Id: I640c5ce1d39265830ec72e5ae13037d5980121bd Signed-off-by: smarcet diff --git a/app/Mail/WelcomeNewUserEmail.php b/app/Mail/WelcomeNewUserEmail.php index 5f55d85..88bede3 100644 --- a/app/Mail/WelcomeNewUserEmail.php +++ b/app/Mail/WelcomeNewUserEmail.php @@ -17,6 +17,8 @@ use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\URL; + /** * Class WelcomeNewUserEmail * @package App\Mail @@ -38,13 +40,26 @@ final class WelcomeNewUserEmail extends Mailable public $user_fullname; /** + * @var string + */ + public $verification_link; + + /** + * @var string + */ + public $bio_link; + + /** * WelcomeNewUserEmail constructor. * @param User $user + * @param string|null $verification_link */ - public function __construct(User $user) + public function __construct(User $user, ?string $verification_link) { $this->user_email = $user->getEmail(); $this->user_fullname = $user->getFullName(); + $this->verification_link = $verification_link; + $this->bio_link = URL::action("UserController@getLogin"); } /** diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 69e2c53..ff9ef82 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -77,14 +77,16 @@ final class EventServiceProvider extends ServiceProvider if(is_null($user)) return; if(! $user instanceof User) return; $user_service = App::make(IUserService::class); + if(!$user_service instanceof IUserService) return; + $user_service->generateIdentifier($user); - Mail::queue(new WelcomeNewUserEmail($user)); + $verification_link = $user_service->sendWelcomeEmail($user); if(!$user->isEmailVerified()) { if (!$user->hasCreator()) - $user_service->sendVerificationEmail($user); + $user_service->sendVerificationEmail($user, $verification_link); } else{ // email is already verified diff --git a/app/Services/Auth/IUserService.php b/app/Services/Auth/IUserService.php index 666bd05..327f231 100644 --- a/app/Services/Auth/IUserService.php +++ b/app/Services/Auth/IUserService.php @@ -47,10 +47,11 @@ interface IUserService /** * @param User $user - * @return User + * @param string|null $verification_link * @throws ValidationException + * @return User */ - public function sendVerificationEmail(User $user): User; + public function sendVerificationEmail(User $user, string $verification_link = null): User; /** * @param User $user @@ -98,4 +99,10 @@ interface IUserService * @return void */ public function recalculateUserSpamType(User $user):void; + + /** + * @param User $user + * @return string|null + */ + public function sendWelcomeEmail(User $user):?string; } \ No newline at end of file diff --git a/app/Services/Auth/UserService.php b/app/Services/Auth/UserService.php index 50bcf21..2dc872a 100644 --- a/app/Services/Auth/UserService.php +++ b/app/Services/Auth/UserService.php @@ -22,6 +22,7 @@ use App\libs\Auth\Repositories\IUserPasswordResetRequestRepository; use App\libs\Auth\Repositories\IUserRegistrationRequestRepository; use App\Mail\UserEmailVerificationRequest; use App\Mail\UserPasswordResetRequestMail; +use App\Mail\WelcomeNewUserEmail; use App\Services\AbstractService; use Auth\IUserNameGeneratorService; use Auth\Repositories\IUserRepository; @@ -178,31 +179,55 @@ final class UserService extends AbstractService implements IUserService /** * @param User $user - * @return User - * @throws ValidationException + * @return string */ - public function sendVerificationEmail(User $user): User - { - return $this->tx_service->transaction(function() use($user){ - if($user->isEmailVerified()) - throw new ValidationException - ( - sprintf - ( - "User %s (%s) has already verified his/her email.", - $user->getEmail(), - $user->getId() - ) - ); + private function generateVerificationLink(User $user):string{ + + return $this->tx_service->transaction(function() use($user) { //generate unique token - do{ + do { $token = $user->generateEmailVerificationToken(); $former_user = $this->user_repository->getByVerificationEmailToken($token); - if(is_null($former_user)) break; - } while(true); + if (is_null($former_user)) break; + } while (true); + + return URL::route("verification_verify", ["token" => $token]); + }); + } + + /** + * @param User $user + * @return string|null + * @throws \Exception + */ + public function sendWelcomeEmail(User $user):?string { + + return $this->tx_service->transaction(function() use($user){ + + $verification_link = null; + + if(!$user->isEmailVerified()) + $verification_link = $this->generateVerificationLink($user); + + Mail::queue(new WelcomeNewUserEmail($user, $verification_link)); + + return $verification_link; + }); + } + + /** + * @param User $user + * @param string|null $verification_link + * @return User + * @throws \Exception + */ + public function sendVerificationEmail(User $user, string $verification_link = null): User + { + return $this->tx_service->transaction(function() use($user, $verification_link){ - $verification_link = URL::route("verification_verify", ["token" => $token]); + if(empty($verification_link)) + $verification_link = $this->generateVerificationLink($user); Mail::queue(new UserEmailVerificationRequest($user, $verification_link)); diff --git a/app/libs/Auth/Models/User.php b/app/libs/Auth/Models/User.php index 260926c..c208cd9 100644 --- a/app/libs/Auth/Models/User.php +++ b/app/libs/Auth/Models/User.php @@ -1491,10 +1491,15 @@ SQL; } /** - * @return String + * @return string + * @throws ValidationException */ public function generateEmailVerificationToken(): string { + if($this->isEmailVerified()){ + throw new ValidationException(sprintf("User %s (%s) is already verified.", $this->id, $this->email)); + } + $generator = new RandomGenerator(); $token = strval($this->id) . $generator->randomToken(); $this->email_verified_token_hash = self::createConfirmationTokenHash($token); diff --git a/config/app.php b/config/app.php index 005e49b..7782d27 100644 --- a/config/app.php +++ b/config/app.php @@ -221,7 +221,7 @@ return [ 'version' => env('APP_VERSION', 'XX.XX.XX'), 'app_name' => env('APP_NAME', 'OpenStackID'), - 'tenant_name' => env('TENANT_NAME', 'OpenStack'), + 'tenant_name' => env('TENANT_NAME', 'Open Infrastructure'), 'logo_url' => env('LOGO_URL', '/assets/img/openstack-logo-full.svg'), 'tenant_favicon' => env('TENANT_FAV_ICON_URL', '/assets/img/favicon-32x32.png'), 'help_email' => env('HELP_EMAIL', 'support@openstack.org'), diff --git a/resources/views/emails/auth/email_verification_request.blade.php b/resources/views/emails/auth/email_verification_request.blade.php index 22e90b6..662a076 100644 --- a/resources/views/emails/auth/email_verification_request.blade.php +++ b/resources/views/emails/auth/email_verification_request.blade.php @@ -6,7 +6,7 @@

Dear {!!$user_fullname!!},

- Thank you for your interest in joining the Open Infrastructure community! In order to verify your email, + Thank you for your interest in joining the {!! Config::get('app.tenant_name') !!} community! In order to verify your email, please click the verification link: Verify Email Address.

diff --git a/resources/views/emails/welcome_new_user_email.blade.php b/resources/views/emails/welcome_new_user_email.blade.php index 490738a..d326bf6 100644 --- a/resources/views/emails/welcome_new_user_email.blade.php +++ b/resources/views/emails/welcome_new_user_email.blade.php @@ -6,10 +6,15 @@

Dear {!!$user_fullname!!},

- You will use this account to access all Open Infrastructure community apps and websites that require an {!! Config::get('app.app_name') !!}, + You will use this account to access all {!! Config::get('app.tenant_name') !!} community apps and websites that require an {!! Config::get('app.app_name') !!}, including the virtual Open Infrastructure Summit. Your user details are associated with your {!! Config::get('app.app_name') !!} and you are able to grant access to that information to each app at your discretion.

+@if($verification_link) +

+ In order to verify your email, please click the verification link: Verify Email Address. +

+@endif

To edit your profile just click here. You may update your photo, add a bio, and other information you wish to share.