mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 10:08:05 +00:00
Fix #80 Inject provisioning link and QRCode in the default email with a password_reset parameter
This commit is contained in:
parent
d0f5bf24f5
commit
f68c0957da
12 changed files with 109 additions and 30 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
])
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,21 +7,23 @@
|
|||
<div class="card mt-3">
|
||||
<div class="card-body">
|
||||
{!! Form::open(['route' => 'account.authenticate.email']) !!}
|
||||
<div class="form-group">
|
||||
{!! Form::label('email', 'Email') !!}
|
||||
{!! Form::email('email', old('email'), ['class' => 'form-control', 'placeholder' => 'bob@example.com', 'required']) !!}
|
||||
</div>
|
||||
|
||||
@if (config('app.account_email_unique') == false)
|
||||
<div class="form-group">
|
||||
{!! Form::label('email', 'Email') !!}
|
||||
{!! Form::email('email', old('email'), ['class' => 'form-control', 'placeholder' => 'bob@example.com', 'required']) !!}
|
||||
</div>
|
||||
@endif
|
||||
<div class="form-group">
|
||||
{!! Form::label('username', 'SIP Username') !!}
|
||||
<div class=" input-group mb-3">
|
||||
{!! Form::text('username', old('username'), ['class' => 'form-control', 'placeholder' => 'username', 'required']) !!}
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text" id="basic-addon2">{{ $domain }}</span>
|
||||
{!! Form::label('username', 'SIP Username') !!}
|
||||
<div class=" input-group mb-3">
|
||||
{!! Form::text('username', old('username'), ['class' => 'form-control', 'placeholder' => 'username', 'required']) !!}
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text" id="basic-addon2">{{ $domain }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@include('parts.captcha')
|
||||
{!! Form::submit('Send the authentication link', ['class' => 'btn btn-primary btn-centered']) !!}
|
||||
{!! Form::close() !!}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@
|
|||
<p>
|
||||
<a href="{{ $link }}">{{ $link }}</a>
|
||||
</p>
|
||||
<p>
|
||||
You can as well configure your new device using the following code or by directly flashing the QRCode:<br />
|
||||
|
||||
<img src="{{ $provisioning_qrcode}}"><br />
|
||||
<a href="{{ $provisioning_link }}">Provisioning link</a>
|
||||
</p>
|
||||
<p>
|
||||
Regards,<br />
|
||||
{{ config('mail.signature') }}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Authenticate on {{ config('app.name') }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello,</p>
|
||||
<p>
|
||||
You are trying to authenticate to {{ config('app.name') }} using your email account.<br />
|
||||
Please follow the unique link bellow to finish the authentication process.
|
||||
</p>
|
||||
<p>
|
||||
<a href="{{ $link }}">{{ $link }}</a>
|
||||
</p>
|
||||
<p>
|
||||
You can as well configure your new device using the following code or by directly flashing the QRCode:<br />
|
||||
|
||||
<img src="{{ $provisioning_qrcode}}"><br />
|
||||
<a href="{{ $provisioning_link }}">Provisioning link</a>
|
||||
</p>
|
||||
<p>
|
||||
Regards,<br />
|
||||
{{ config('mail.signature') }}
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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') }}
|
||||
|
|
@ -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') }}
|
||||
Loading…
Add table
Reference in a new issue