2018-10-24 05:50:15 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. 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;
|
|
|
|
|
|
|
|
use App\Http\Requests\Account\CreateAccountRequest;
|
2022-06-16 07:58:11 +02:00
|
|
|
use App\Http\Requests\Account\UpdateAccountRequest;
|
2018-10-24 05:50:15 +02:00
|
|
|
use App\Jobs\Account\CreateAccount;
|
2019-04-18 13:57:22 +02:00
|
|
|
use App\Models\Account;
|
2019-09-16 23:42:08 +02:00
|
|
|
use App\Models\CompanyUser;
|
2022-06-16 07:58:11 +02:00
|
|
|
use App\Transformers\AccountTransformer;
|
2019-09-16 23:42:08 +02:00
|
|
|
use App\Transformers\CompanyUserTransformer;
|
2022-03-20 09:02:53 +01:00
|
|
|
use App\Utils\TruthSource;
|
2018-10-24 12:24:09 +02:00
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
2020-10-28 11:10:49 +01: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()
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
// 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
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/signup",
|
|
|
|
* operationId="postSignup",
|
|
|
|
* tags={"signup"},
|
|
|
|
* summary="Attempts a new account signup",
|
|
|
|
* description="Attempts a new account signup and returns a CompanyUser object on success",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
2019-11-26 09:14:01 +01:00
|
|
|
* @OA\Parameter(
|
|
|
|
* name="token_name",
|
2020-07-30 05:27:00 +02:00
|
|
|
* in="query",
|
2019-11-26 09:14:01 +01:00
|
|
|
* description="A custom name for the user company token",
|
|
|
|
* example="Daves iOS Device",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
2019-10-06 14:24:15 +02:00
|
|
|
* @OA\RequestBody(
|
|
|
|
* description="Signup credentials",
|
|
|
|
* required=true,
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="object",
|
|
|
|
* @OA\Property(
|
|
|
|
* property="email",
|
|
|
|
* description="The user email address",
|
|
|
|
* type="string",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="first_name",
|
|
|
|
* description="The signup users first name",
|
|
|
|
* type="string",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="last_name",
|
|
|
|
* description="The signup users last name",
|
|
|
|
* type="string",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="terms_of_service",
|
|
|
|
* description="The user accepted the terms of service",
|
|
|
|
* type="boolean",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="privacy_policy",
|
|
|
|
* description="The user accepted the privacy policy",
|
|
|
|
* type="boolean",
|
2019-12-30 22:59:12 +01:00
|
|
|
* ),
|
2019-10-06 14:24:15 +02:00
|
|
|
* @OA\Property(
|
|
|
|
* property="password",
|
|
|
|
* example="1234567",
|
|
|
|
* description="The user password must meet minimum criteria ~ >6 characters",
|
|
|
|
* type="string"
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="The Company User response",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-06 14:24:15 +02:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/CompanyUser"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-06 14:24:15 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2018-10-24 05:50:15 +02:00
|
|
|
*/
|
|
|
|
public function store(CreateAccountRequest $request)
|
|
|
|
{
|
2022-06-24 13:15:14 +02:00
|
|
|
$account = (new CreateAccount($request->all(), $request->getClientIp()))->handle();
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! ($account instanceof Account)) {
|
2020-03-07 13:46:45 +01:00
|
|
|
return $account;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-07 13:46:45 +01:00
|
|
|
|
2019-09-16 23:42:08 +02:00
|
|
|
$ct = CompanyUser::whereUserId(auth()->user()->id);
|
2020-03-11 12:05:05 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$truth = app()->make(TruthSource::class);
|
|
|
|
$truth->setCompanyUser($ct->first());
|
|
|
|
$truth->setUser(auth()->user());
|
|
|
|
$truth->setCompany($ct->first()->company);
|
2020-03-11 12:05:05 +01:00
|
|
|
|
2019-09-16 23:42:08 +02:00
|
|
|
return $this->listResponse($ct);
|
2018-10-24 05:50:15 +02:00
|
|
|
}
|
2022-06-16 07:58:11 +02:00
|
|
|
|
|
|
|
public function update(UpdateAccountRequest $request, Account $account)
|
|
|
|
{
|
2022-06-16 08:52:43 +02:00
|
|
|
$fi = new \FilesystemIterator(public_path('react'), \FilesystemIterator::SKIP_DOTS);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (iterator_count($fi) < 30) {
|
2022-06-16 08:52:43 +02:00
|
|
|
return response()->json(['message' => 'React App Not Installed, Please install the React app before attempting to switch.'], 400);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-06-16 08:52:43 +02:00
|
|
|
|
2022-06-16 07:58:11 +02:00
|
|
|
$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
|
|
|
}
|