Allow phone numbers to be set on the admin account creation API endpoint

This commit is contained in:
Timothée Jaussoin 2021-04-22 17:46:42 +02:00
parent 13d5a2410a
commit 9cf86e1b6a
3 changed files with 18 additions and 2 deletions

View file

@ -28,8 +28,9 @@ use Carbon\Carbon;
use App\Account; use App\Account;
use App\ActivationExpiration; use App\ActivationExpiration;
use App\Admin; use App\Admin;
use App\Rules\WithoutSpaces; use App\Alias;
use App\Http\Controllers\Account\AuthenticateController as WebAuthenticateController; use App\Http\Controllers\Account\AuthenticateController as WebAuthenticateController;
use App\Rules\WithoutSpaces;
class AccountController extends Controller class AccountController extends Controller
{ {
@ -80,11 +81,17 @@ class AccountController extends Controller
'algorithm' => 'required|in:SHA-256,MD5', 'algorithm' => 'required|in:SHA-256,MD5',
'password' => 'required|filled', 'password' => 'required|filled',
'domain' => 'min:3', 'domain' => 'min:3',
'email' => 'email',
'admin' => 'boolean|nullable', 'admin' => 'boolean|nullable',
'activated' => 'boolean|nullable', 'activated' => 'boolean|nullable',
'confirmation_key_expires' => [ 'confirmation_key_expires' => [
'date_format:Y-m-d H:i:s', 'date_format:Y-m-d H:i:s',
'nullable', 'nullable',
],
'phone' => [
'unique:external.aliases,alias',
'unique:external.accounts,username',
new WithoutSpaces, 'starts_with:+', 'phone:AUTO'
] ]
]); ]);
@ -123,6 +130,14 @@ class AccountController extends Controller
$admin->save(); $admin->save();
} }
if ($request->has('phone')) {
$alias = new Alias;
$alias->alias = $request->get('phone');
$alias->domain = config('app.sip_domain');
$alias->account_id = $account->id;
$alias->save();
}
// Full reload // Full reload
$account = Account::withoutGlobalScopes()->find($account->id); $account = Account::withoutGlobalScopes()->find($account->id);

View file

@ -167,6 +167,7 @@ For the moment only DIGEST-MD5 and DIGEST-SHA-256 are supported through the auth
<li><code>domain</code> optional, the value is set to the default registration domain if not set</li> <li><code>domain</code> optional, the value is set to the default registration domain if not set</li>
<li><code>activated</code> optional, a boolean, set to <code>false</code> by default</li> <li><code>activated</code> optional, a boolean, set to <code>false</code> by default</li>
<li><code>admin</code> optional, a boolean, set to <code>false</code> by default, create an admin account</li> <li><code>admin</code> optional, a boolean, set to <code>false</code> by default, create an admin account</li>
<li><code>phone</code> optional, a phone number, set a phone number to the account</li>
<li><code>confirmation_key_expires</code> optional, a datetime of this format: Y-m-d H:i:s. Only used when <code>activated</code> is not used or <code>false</code>. Enforces an expiration date on the returned <code>confirmation_key</code>. After that datetime public email or phone activation endpoints will return <code>403</code>.</li> <li><code>confirmation_key_expires</code> optional, a datetime of this format: Y-m-d H:i:s. Only used when <code>activated</code> is not used or <code>false</code>. Enforces an expiration date on the returned <code>confirmation_key</code>. After that datetime public email or phone activation endpoints will return <code>403</code>.</li>
</ul> </ul>

View file

@ -8,7 +8,7 @@
#%define _datadir %{_datarootdir} #%define _datadir %{_datarootdir}
#%define _docdir %{_datadir}/doc #%define _docdir %{_datadir}/doc
%define build_number 60 %define build_number 61
%define var_dir /var/opt/belledonne-communications %define var_dir /var/opt/belledonne-communications
%define opt_dir /opt/belledonne-communications/share/flexisip-account-manager %define opt_dir /opt/belledonne-communications/share/flexisip-account-manager
%define env_file "$RPM_BUILD_ROOT/etc/flexisip-account-manager/flexiapi.env" %define env_file "$RPM_BUILD_ROOT/etc/flexisip-account-manager/flexiapi.env"