1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/UserController.php

166 lines
3.9 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers;
2019-04-27 11:20:03 +02:00
use App\Factory\UserFactory;
2019-04-25 13:33:03 +02:00
use App\Filters\UserFilters;
use App\Http\Controllers\Traits\VerifiesUserEmail;
2019-04-27 11:20:03 +02:00
use App\Http\Requests\User\CreateUserRequest;
use App\Http\Requests\User\DestroyUserRequest;
use App\Http\Requests\User\EditUserRequest;
use App\Http\Requests\User\ShowUserRequest;
use App\Http\Requests\User\StoreUserRequest;
use App\Http\Requests\User\UpdateUserRequest;
2019-04-25 13:33:03 +02:00
use App\Models\User;
2019-06-06 06:51:28 +02:00
use App\Repositories\UserRepository;
2019-04-25 13:33:03 +02:00
use App\Transformers\UserTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
2019-01-27 00:22:57 +01:00
/**
* Class UserController
* @package App\Http\Controllers
*/
2019-03-28 22:34:58 +01:00
class UserController extends BaseController
{
use VerifiesUserEmail;
2019-04-25 13:33:03 +02:00
use MakesHash;
protected $entity_type = User::class;
protected $entity_transformer = UserTransformer::class;
2019-06-06 06:51:28 +02:00
protected $user_repo;
2019-06-11 07:28:24 +02:00
/**
* Constructor
*
* @param \App\Repositories\UserRepository $user_repo The user repo
*/
public function __construct(UserRepository $user_repo)
2019-03-28 22:34:58 +01:00
{
parent::__construct();
2019-06-06 06:51:28 +02:00
$this->user_repo = $user_repo;
2019-06-11 07:28:24 +02:00
2019-03-28 22:34:58 +01:00
}
2019-04-25 13:33:03 +02:00
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(UserFilters $filters)
2019-04-25 13:33:03 +02:00
{
$users = User::filter($filters);
return $this->listResponse($users);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
2019-04-27 11:20:03 +02:00
public function create(CreateUserRequest $request)
2019-04-25 13:33:03 +02:00
{
2019-04-27 11:20:03 +02:00
$user = UserFactory::create();
return $this->itemResponse($user);
2019-04-25 13:33:03 +02:00
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
2019-04-27 11:20:03 +02:00
public function store(StoreUserRequest $request)
2019-04-25 13:33:03 +02:00
{
2019-06-06 06:51:28 +02:00
$company = auth()->user()->company();
2019-04-28 12:25:18 +02:00
//save user
2019-06-06 06:51:28 +02:00
$user = $this->user_repo->save($request->all(), UserFactory::create($company->id, auth()->user()->id));
$user->companies()->attach($company->id, [
'account_id' => $company->account->id,
'is_owner' => 0,
'is_admin' => $request->input('is_admin'),
'is_locked' => 0,
'permissions' => $request->input('permissions'),
'settings' => $request->input('settings'),
]);
$user->load('companies');
2019-06-06 06:51:28 +02:00
return $this->itemResponse($user);
2019-04-28 12:25:18 +02:00
2019-04-25 13:33:03 +02:00
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
2019-06-05 11:50:37 +02:00
public function show(ShowUserRequest $request, User $user)
2019-04-25 13:33:03 +02:00
{
2019-06-05 11:50:37 +02:00
return $this->itemResponse($user);
2019-04-25 13:33:03 +02:00
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
2019-06-05 11:50:37 +02:00
public function edit(EditUserRequest $request, User $user)
2019-04-25 13:33:03 +02:00
{
2019-06-05 11:50:37 +02:00
return $this->itemResponse($user);
2019-04-25 13:33:03 +02:00
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
2019-06-05 02:43:23 +02:00
public function update(UpdateUserRequest $request, User $user)
2019-04-25 13:33:03 +02:00
{
2019-06-06 06:51:28 +02:00
$user = $this->user_repo->save($request->all(), $user);
return $this->itemResponse($user);
2019-04-25 13:33:03 +02:00
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
2019-06-06 06:51:28 +02:00
public function destroy(DestroyUserRequest $request, User $user)
2019-04-25 13:33:03 +02:00
{
2019-06-06 06:51:28 +02:00
$user->delete();
$user->tokens->delete();
2019-06-06 06:51:28 +02:00
return response()->json([], 200);
2019-04-25 13:33:03 +02:00
}
}