1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Controllers/AccountController.php

106 lines
2.8 KiB
PHP
Raw Normal View History

2018-10-24 05:50:15 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
2018-10-24 05:50:15 +02:00
namespace App\Http\Controllers;
2023-10-26 04:57:44 +02:00
use App\Http\Requests\Account\CreateAccountRequest;
use App\Http\Requests\Account\UpdateAccountRequest;
use App\Jobs\Account\CreateAccount;
2023-04-02 07:57:27 +02:00
use App\Libraries\MultiDB;
2023-10-26 04:57:44 +02:00
use App\Models\Account;
2019-09-16 23:42:08 +02:00
use App\Models\CompanyUser;
use App\Transformers\AccountTransformer;
2019-09-16 23:42:08 +02:00
use App\Transformers\CompanyUserTransformer;
2023-10-26 04:57:44 +02:00
use App\Utils\TruthSource;
use Illuminate\Foundation\Bus\DispatchesJobs;
2023-10-26 04:57:44 +02:00
use Illuminate\Http\Response;
2018-10-24 05:50:15 +02:00
2019-03-28 22:34:58 +01:00
class AccountController extends BaseController
2018-10-24 05:50:15 +02:00
{
use DispatchesJobs;
2019-09-16 23:42:08 +02:00
protected $entity_type = CompanyUser::class;
2019-04-18 13:57:22 +02:00
2019-09-16 23:42:08 +02:00
protected $entity_transformer = CompanyUserTransformer::class;
2019-04-18 13:57:22 +02:00
2018-10-24 05:50:15 +02:00
public function __construct()
{
2019-03-28 22:34:58 +01:00
parent::__construct();
2018-10-24 05:50:15 +02:00
}
/**
* Display a listing of the resource.
*
2020-10-28 11:10:49 +01:00
* @return void
2018-10-24 05:50:15 +02:00
*/
public function index()
{
// return view('signup.index');
2018-10-24 05:50:15 +02:00
}
/**
* Show the form for creating a new resource.
*
2020-10-28 11:10:49 +01:00
* @return void
2018-10-24 05:50:15 +02:00
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param CreateAccountRequest $request
* @return Response
2019-10-06 14:24:15 +02:00
*
2018-10-24 05:50:15 +02:00
*/
public function store(CreateAccountRequest $request)
{
$account = (new CreateAccount($request->all(), $request->getClientIp()))->handle();
if (! ($account instanceof Account)) {
return $account;
}
2023-04-02 07:57:27 +02:00
MultiDB::findAndSetDbByAccountKey($account->key);
2023-08-27 00:41:27 +02:00
$cu = CompanyUser::query()->where('user_id', $account->users()->first()->id);
2023-03-24 01:22:21 +01:00
$company_user = $cu->first();
$truth = app()->make(TruthSource::class);
2023-03-24 01:22:21 +01:00
$truth->setCompanyUser($company_user);
$truth->setUser($company_user->user);
$truth->setCompany($company_user->company);
$truth->setCompanyToken($company_user->tokens()->where('user_id', $company_user->user_id)->where('company_id', $company_user->company_id)->first());
2023-03-24 01:22:21 +01:00
return $this->listResponse($cu);
2018-10-24 05:50:15 +02:00
}
public function update(UpdateAccountRequest $request, Account $account)
{
$fi = new \FilesystemIterator(public_path('react'), \FilesystemIterator::SKIP_DOTS);
if (iterator_count($fi) < 30) {
return response()->json(['message' => 'React App Not Installed, Please install the React app before attempting to switch.'], 400);
}
$account->fill($request->all());
$account->save();
$this->entity_type = Account::class;
$this->entity_transformer = AccountTransformer::class;
return $this->itemResponse($account);
}
2018-10-24 05:50:15 +02:00
}