mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 10:08:05 +00:00
Resolve the accounts inside the controllers, the automatic Laravel object resolve doesn't fit with the authenticated scope declared in the Account booted() method
This commit is contained in:
parent
5d508d96d8
commit
c81fdc6b10
5 changed files with 59 additions and 25 deletions
|
|
@ -28,8 +28,10 @@ use App\AccountType;
|
|||
|
||||
class AccountAccountTypeController extends Controller
|
||||
{
|
||||
public function create(Account $account)
|
||||
public function create(int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
return view('admin.account.account_type.create', [
|
||||
'account' => $account,
|
||||
'account_types' => AccountType::whereNotIn('id', function($query) use ($account) {
|
||||
|
|
@ -40,8 +42,10 @@ class AccountAccountTypeController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request, Account $account)
|
||||
public function store(Request $request, int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
$request->validate([
|
||||
'account_type_id' => ['required', 'exists:account_types,id'],
|
||||
]);
|
||||
|
|
@ -55,8 +59,10 @@ class AccountAccountTypeController extends Controller
|
|||
return redirect()->route('admin.account.show', $account);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Account $account, int $typeId)
|
||||
public function destroy(Request $request, int $id, int $typeId)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
$account->types()->detach($typeId);
|
||||
|
||||
$request->session()->flash('success', 'Type successfully removed');
|
||||
|
|
|
|||
|
|
@ -29,8 +29,10 @@ use App\Rules\NoUppercase;
|
|||
|
||||
class AccountActionController extends Controller
|
||||
{
|
||||
public function create(Account $account)
|
||||
public function create(int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
return view('admin.account.action.create_edit', [
|
||||
'action' => new AccountAction,
|
||||
'account' => $account,
|
||||
|
|
@ -38,8 +40,10 @@ class AccountActionController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request, Account $account)
|
||||
public function store(Request $request, int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
$request->validate([
|
||||
'key' => ['required', 'alpha_dash', new NoUppercase],
|
||||
'code' => ['required', 'alpha_num', new NoUppercase],
|
||||
|
|
@ -59,8 +63,10 @@ class AccountActionController extends Controller
|
|||
return redirect()->route('admin.account.show', $accountAction->account);
|
||||
}
|
||||
|
||||
public function edit(Account $account, int $actionId)
|
||||
public function edit(int $id, int $actionId)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
$accountAction = $account->actions()
|
||||
->where('id', $actionId)
|
||||
->firstOrFail();
|
||||
|
|
@ -72,8 +78,10 @@ class AccountActionController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Account $account, int $actionId)
|
||||
public function update(Request $request, int $id, int $actionId)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
$request->validate([
|
||||
'key' => ['alpha_dash', new NoUppercase],
|
||||
'code' => ['alpha_num', new NoUppercase],
|
||||
|
|
@ -94,8 +102,10 @@ class AccountActionController extends Controller
|
|||
return redirect()->route('admin.account.show', $account);
|
||||
}
|
||||
|
||||
public function delete(Account $account, int $actionId)
|
||||
public function delete(int $id, int $actionId)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
return view('admin.account.action.delete', [
|
||||
'action' => $account->actions()
|
||||
->where('id', $actionId)
|
||||
|
|
@ -103,8 +113,10 @@ class AccountActionController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Account $account, int $actionId)
|
||||
public function destroy(Request $request, int $id, int $actionId)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
$accountAction = $account->actions()
|
||||
->where('id', $actionId)
|
||||
->firstOrFail();
|
||||
|
|
|
|||
|
|
@ -27,15 +27,18 @@ use App\Account;
|
|||
|
||||
class AccountContactController extends Controller
|
||||
{
|
||||
public function create(Account $account)
|
||||
public function create(int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
return view('admin.account.contact.create', [
|
||||
'account' => $account
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request, Account $account)
|
||||
public function store(Request $request, int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
$contact = Account::sip($request->get('sip'))->first();
|
||||
|
||||
if (!$contact) {
|
||||
|
|
@ -54,8 +57,9 @@ class AccountContactController extends Controller
|
|||
return redirect()->route('admin.account.show', $account);
|
||||
}
|
||||
|
||||
public function delete(Account $account, int $contactId)
|
||||
public function delete(int $id, int $contactId)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
$contact = $account->contacts()->where('id', $contactId)->firstOrFail();
|
||||
|
||||
return view('admin.account.contact.delete', [
|
||||
|
|
@ -64,8 +68,9 @@ class AccountContactController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Account $account)
|
||||
public function destroy(Request $request, int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
$contact = $account->contacts()->where('id', $request->get('contact_id'))->firstOrFail();
|
||||
|
||||
$account->contacts()->detach($contact->id);
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@ class AccountController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function show(Account $account)
|
||||
public function show(int $id)
|
||||
{
|
||||
return view('admin.account.show', [
|
||||
'account' => $account
|
||||
'account' => Account::findOrFail($id)
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -84,10 +84,10 @@ class AccountController extends Controller
|
|||
return redirect()->route('admin.account.show', $account->id);
|
||||
}
|
||||
|
||||
public function edit(Account $account)
|
||||
public function edit(int $id)
|
||||
{
|
||||
return view('admin.account.create_edit', [
|
||||
'account' => $account
|
||||
'account' => Account::findOrFail($id)
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -112,8 +112,9 @@ class AccountController extends Controller
|
|||
return redirect()->route('admin.account.index', $request->get('search'));
|
||||
}
|
||||
|
||||
public function activate(Account $account)
|
||||
public function activate(int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
$account->activated = true;
|
||||
$account->save();
|
||||
|
||||
|
|
@ -122,8 +123,9 @@ class AccountController extends Controller
|
|||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function deactivate(Account $account)
|
||||
public function deactivate(int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
$account->activated = false;
|
||||
$account->save();
|
||||
|
||||
|
|
@ -132,8 +134,9 @@ class AccountController extends Controller
|
|||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function provision(Account $account)
|
||||
public function provision(int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
$account->confirmation_key = Str::random(WebAuthenticateController::$emailCodeSize);
|
||||
$account->save();
|
||||
|
||||
|
|
@ -142,8 +145,10 @@ class AccountController extends Controller
|
|||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function admin(Account $account)
|
||||
public function admin(int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
$admin = new Admin;
|
||||
$admin->account_id = $account->id;
|
||||
$admin->save();
|
||||
|
|
@ -167,8 +172,10 @@ class AccountController extends Controller
|
|||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function delete(Account $account)
|
||||
public function delete(int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
return view('admin.account.delete', [
|
||||
'account' => $account
|
||||
]);
|
||||
|
|
@ -194,16 +201,20 @@ class AccountController extends Controller
|
|||
return redirect()->back();
|
||||
}
|
||||
|
||||
private function fillPassword(Request $request, Account $account)
|
||||
private function fillPassword(Request $request, int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
if ($request->filled('password')) {
|
||||
$algorithm = $request->has('password_sha256') ? 'SHA-256' : 'MD5';
|
||||
$account->updatePassword($request->get('password'), $algorithm);
|
||||
}
|
||||
}
|
||||
|
||||
private function fillPhone(Request $request, Account $account)
|
||||
private function fillPhone(Request $request, int $id)
|
||||
{
|
||||
$account = Account::findOrFail($id);
|
||||
|
||||
if ($request->filled('phone')) {
|
||||
$account->alias()->delete();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#%define _datadir %{_datarootdir}
|
||||
#%define _docdir %{_datadir}/doc
|
||||
|
||||
%define build_number 121
|
||||
%define build_number 122
|
||||
%define var_dir /var/opt/belledonne-communications
|
||||
%define opt_dir /opt/belledonne-communications/share/flexisip-account-manager
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue