diff --git a/README.md b/README.md index 211105c..36e95cd 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,12 @@ Import accounts previously exported as a JSON file. Accounts previously imported accounts:import-externals {file_path} +## Custom email templaces + +Some email templates can be customized. + +To do so, copy and rename the existing `*_custom.blade.php.example` files into `*custom.blade.php` and adapt the content of the email (HTML and text versions), those files will then replace the default ones. + ## Provisioning FlexiAPI is providing endpoints to provision Liblinphone powered devices. You can find more documentation about it on the `/api#provisioning` documentation page. diff --git a/flexiapi/app/Account.php b/flexiapi/app/Account.php index ba14374..c5d456a 100644 --- a/flexiapi/app/Account.php +++ b/flexiapi/app/Account.php @@ -24,6 +24,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Auth; use Illuminate\Foundation\Auth\User as Authenticatable; +use App\Http\Controllers\Account\AuthenticateController as WebAuthenticateController; use Illuminate\Support\Str; use App\ApiKey; @@ -295,6 +296,12 @@ class Account extends Authenticatable return $authToken; } + public function provision(): string + { + $this->provisioning_token = Str::random(WebAuthenticateController::$emailCodeSize); + return $this->provisioning_token; + } + public function isAdmin() { return ($this->admin); diff --git a/flexiapi/app/Http/Controllers/Account/AuthenticateController.php b/flexiapi/app/Http/Controllers/Account/AuthenticateController.php index 96988bf..e74342a 100644 --- a/flexiapi/app/Http/Controllers/Account/AuthenticateController.php +++ b/flexiapi/app/Http/Controllers/Account/AuthenticateController.php @@ -93,21 +93,24 @@ class AuthenticateController extends Controller */ public function authenticateEmail(Request $request) { - $request->validate([ + $rules = [ 'email' => 'required|email|exists:accounts,email', - 'username' => [ - 'required' - ], 'g-recaptcha-response' => 'required|captcha', - ]); + ]; + + if (config('app.account_email_unique') == false) { + $rules['username'] = 'required'; + } + + $request->validate($rules); + + $account = Account::where('email', $request->get('email')); /** * Because several accounts can have the same email */ - $account = Account::where('username', $request->get('username')); - if (config('app.account_email_unique') == false) { - $account = $account->where('email', $request->get('email')); + $account = $account->where('username', $request->get('username')); } $account = $account->first(); @@ -126,6 +129,7 @@ class AuthenticateController extends Controller } $account->confirmation_key = Str::random(self::$emailCodeSize); + $account->provision(); $account->save(); Mail::to($account)->send(new PasswordAuthentication($account)); diff --git a/flexiapi/app/Http/Controllers/Admin/AccountController.php b/flexiapi/app/Http/Controllers/Admin/AccountController.php index bef8b1e..4040ce7 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountController.php @@ -206,7 +206,7 @@ class AccountController extends Controller public function provision(int $id) { $account = Account::findOrFail($id); - $account->provisioning_token = Str::random(WebAuthenticateController::$emailCodeSize); + $account->provision(); $account->save(); Log::channel('events')->info('Web Admin: Account provisioned', ['id' => $account->identifier]); diff --git a/flexiapi/app/Http/Controllers/Api/AccountController.php b/flexiapi/app/Http/Controllers/Api/AccountController.php index aa22179..a60c471 100644 --- a/flexiapi/app/Http/Controllers/Api/AccountController.php +++ b/flexiapi/app/Http/Controllers/Api/AccountController.php @@ -126,7 +126,7 @@ class AccountController extends Controller $account->ip_address = $request->ip(); $account->creation_time = Carbon::now(); $account->user_agent = config('app.name'); - $account->provisioning_token = Str::random(WebAuthenticateController::$emailCodeSize); + $account->provision(); $account->save(); $account->updatePassword($request->get('password'), $request->get('algorithm')); @@ -269,7 +269,7 @@ class AccountController extends Controller $account->creation_time = Carbon::now(); $account->user_agent = config('app.name'); $account->dtmf_protocol = $request->get('dtmf_protocol'); - $account->provisioning_token = Str::random(WebAuthenticateController::$emailCodeSize); + $account->provision(); $account->save(); $account->updatePassword($request->get('password'), $request->get('algorithm')); @@ -332,7 +332,7 @@ class AccountController extends Controller public function provision(Request $request) { $account = $request->user(); - $account->provisioning_token = Str::random(WebAuthenticateController::$emailCodeSize); + $account->provision(); $account->save(); Log::channel('events')->info('API: Account provisioned', ['id' => $account->identifier]); diff --git a/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php b/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php index 0ded191..75407e6 100644 --- a/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php +++ b/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php @@ -96,7 +96,7 @@ class AccountController extends Controller public function provision(int $id) { $account = Account::findOrFail($id); - $account->provisioning_token = Str::random(WebAuthenticateController::$emailCodeSize); + $account->provision(); $account->save(); Log::channel('events')->info('API Admin: Account provisioned', ['id' => $account->identifier]); @@ -149,7 +149,7 @@ class AccountController extends Controller if (!$request->has('activated') || !(bool)$request->get('activated')) { $account->confirmation_key = Str::random(WebAuthenticateController::$emailCodeSize); - $account->provisioning_token = Str::random(WebAuthenticateController::$emailCodeSize); + $account->provision(); } $account->save(); diff --git a/flexiapi/app/Mail/PasswordAuthentication.php b/flexiapi/app/Mail/PasswordAuthentication.php index 10881e5..667ca33 100644 --- a/flexiapi/app/Mail/PasswordAuthentication.php +++ b/flexiapi/app/Mail/PasswordAuthentication.php @@ -38,10 +38,22 @@ class PasswordAuthentication extends Mailable public function build() { - return $this->view('mails.authentication') - ->text('mails.authentication_text') - ->with([ - 'link' => route('account.authenticate.email_confirm', [$this->account->confirmation_key]) - ]); + return $this->view(view()->exists('mails.authentication_custom') + ? 'mails.authentication_custom' + : 'mails.authentication') + ->text(view()->exists('mails.authentication_text_custom') + ? 'mails.authentication_text_custom' + : 'mails.authentication_text') + ->with([ + 'link' => route('account.authenticate.email_confirm', [$this->account->confirmation_key]), + 'provisioning_link' => route('provisioning.show', [ + 'provisioning_token' => $this->account->provisioning_token, + 'reset_password' => true + ]), + 'provisioning_qrcode' => route('provisioning.qrcode', [ + 'provisioning_token' => $this->account->provisioning_token, + 'reset_password' => true + ]) + ]); } } diff --git a/flexiapi/resources/views/account/login/email.blade.php b/flexiapi/resources/views/account/login/email.blade.php index c917f23..ab3b0cc 100644 --- a/flexiapi/resources/views/account/login/email.blade.php +++ b/flexiapi/resources/views/account/login/email.blade.php @@ -7,21 +7,23 @@
{!! Form::open(['route' => 'account.authenticate.email']) !!} +
+ {!! Form::label('email', 'Email') !!} + {!! Form::email('email', old('email'), ['class' => 'form-control', 'placeholder' => 'bob@example.com', 'required']) !!} +
+ @if (config('app.account_email_unique') == false)
- {!! Form::label('email', 'Email') !!} - {!! Form::email('email', old('email'), ['class' => 'form-control', 'placeholder' => 'bob@example.com', 'required']) !!} -
- @endif -
- {!! Form::label('username', 'SIP Username') !!} -
- {!! Form::text('username', old('username'), ['class' => 'form-control', 'placeholder' => 'username', 'required']) !!} -
- {{ $domain }} + {!! Form::label('username', 'SIP Username') !!} +
+ {!! Form::text('username', old('username'), ['class' => 'form-control', 'placeholder' => 'username', 'required']) !!} +
+ {{ $domain }} +
-
+ @endif + @include('parts.captcha') {!! Form::submit('Send the authentication link', ['class' => 'btn btn-primary btn-centered']) !!} {!! Form::close() !!} diff --git a/flexiapi/resources/views/mails/authentication.blade.php b/flexiapi/resources/views/mails/authentication.blade.php index cffe046..785be7b 100644 --- a/flexiapi/resources/views/mails/authentication.blade.php +++ b/flexiapi/resources/views/mails/authentication.blade.php @@ -11,6 +11,12 @@

{{ $link }}

+

+ You can as well configure your new device using the following code or by directly flashing the QRCode:
+ +
+ Provisioning link +

Regards,
{{ config('mail.signature') }} diff --git a/flexiapi/resources/views/mails/authentication_custom.blade.php.example b/flexiapi/resources/views/mails/authentication_custom.blade.php.example new file mode 100644 index 0000000..785be7b --- /dev/null +++ b/flexiapi/resources/views/mails/authentication_custom.blade.php.example @@ -0,0 +1,25 @@ + + + Authenticate on {{ config('app.name') }} + + +

Hello,

+

+ You are trying to authenticate to {{ config('app.name') }} using your email account.
+ Please follow the unique link bellow to finish the authentication process. +

+

+ {{ $link }} +

+

+ You can as well configure your new device using the following code or by directly flashing the QRCode:
+ +
+ Provisioning link +

+

+ Regards,
+ {{ config('mail.signature') }} +

+ + \ No newline at end of file diff --git a/flexiapi/resources/views/mails/authentication_text.blade.php b/flexiapi/resources/views/mails/authentication_text.blade.php index 950d3de..10f1e2d 100644 --- a/flexiapi/resources/views/mails/authentication_text.blade.php +++ b/flexiapi/resources/views/mails/authentication_text.blade.php @@ -5,5 +5,9 @@ Please follow the unique link bellow to finish the authentication process. {{ $link }} +You can as well configure your new device using the following code or by directly flashing the QRCode in the following link: + +{{ $provisioning_qrcode}} + Regards, {{ config('mail.signature') }} \ No newline at end of file diff --git a/flexiapi/resources/views/mails/authentication_text_custom.blade.php.example b/flexiapi/resources/views/mails/authentication_text_custom.blade.php.example new file mode 100644 index 0000000..10f1e2d --- /dev/null +++ b/flexiapi/resources/views/mails/authentication_text_custom.blade.php.example @@ -0,0 +1,13 @@ +Hello, + +You are trying to authenticate to {{ config('app.name') }} using your email account. +Please follow the unique link bellow to finish the authentication process. + +{{ $link }} + +You can as well configure your new device using the following code or by directly flashing the QRCode in the following link: + +{{ $provisioning_qrcode}} + +Regards, +{{ config('mail.signature') }} \ No newline at end of file