1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Http/Controllers/AccountController.php

158 lines
5.1 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
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
2018-10-24 05:50:15 +02:00
namespace App\Http\Controllers;
use App\Http\Requests\Account\CreateAccountRequest;
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;
use App\Transformers\CompanyUserTransformer;
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();
2019-04-03 02:09:22 +02:00
//$this->middleware('guest');
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
*
* @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-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(
* name="token_name",
2020-07-30 05:27:00 +02:00
* in="query",
* 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-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",
* @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(
* 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)
{
2019-04-18 13:57:22 +02:00
$account = CreateAccount::dispatchNow($request->all());
if (! ($account instanceof Account)) {
return $account;
}
2019-09-16 23:42:08 +02:00
$ct = CompanyUser::whereUserId(auth()->user()->id);
config(['ninja.company_id' => $ct->first()->company->id]);
2019-09-16 23:42:08 +02:00
return $this->listResponse($ct);
2018-10-24 05:50:15 +02:00
}
}