mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix for #185
This commit is contained in:
parent
a0fd4b505a
commit
2f19ff314b
@ -6,7 +6,7 @@ namespace FireflyIII\Http\Controllers\Auth;
|
|||||||
use Auth;
|
use Auth;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Role;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
||||||
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
||||||
@ -94,13 +94,14 @@ class AuthController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Handle a registration request for the application.
|
* Handle a registration request for the application.
|
||||||
*
|
*
|
||||||
|
* @param UserRepositoryInterface $repository
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
* @throws \Illuminate\Foundation\Validation\ValidationException
|
* @throws \Illuminate\Foundation\Validation\ValidationException
|
||||||
*/
|
*/
|
||||||
public function register(Request $request)
|
public function register(UserRepositoryInterface $repository, Request $request)
|
||||||
{
|
{
|
||||||
$validator = $this->validator($request->all());
|
$validator = $this->validator($request->all());
|
||||||
|
|
||||||
@ -146,12 +147,10 @@ class AuthController extends Controller
|
|||||||
Session::flash('gaEventAction', 'new-registration');
|
Session::flash('gaEventAction', 'new-registration');
|
||||||
|
|
||||||
// first user ever?
|
// first user ever?
|
||||||
if (User::count() == 1) {
|
if ($repository->count() == 1) {
|
||||||
$admin = Role::where('name', 'owner')->first();
|
$repository->attachRole(Auth::user(), 'owner');
|
||||||
Auth::user()->attachRole($admin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return redirect($this->redirectPath());
|
return redirect($this->redirectPath());
|
||||||
}
|
}
|
||||||
throw new FireflyException('The authenticated user object is invalid.');
|
throw new FireflyException('The authenticated user object is invalid.');
|
||||||
|
@ -86,6 +86,7 @@ class FireflyServiceProvider extends ServiceProvider
|
|||||||
$this->app->bind('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface', 'FireflyIII\Repositories\Category\SingleCategoryRepository');
|
$this->app->bind('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface', 'FireflyIII\Repositories\Category\SingleCategoryRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
||||||
$this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search');
|
$this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search');
|
||||||
|
$this->app->bind('FireflyIII\Repositories\User\UserRepositoryInterface', 'FireflyIII\Repositories\User\UserRepository');
|
||||||
|
|
||||||
// CSV import
|
// CSV import
|
||||||
$this->app->bind('FireflyIII\Helpers\Csv\WizardInterface', 'FireflyIII\Helpers\Csv\Wizard');
|
$this->app->bind('FireflyIII\Helpers\Csv\WizardInterface', 'FireflyIII\Helpers\Csv\Wizard');
|
||||||
|
45
app/Repositories/User/UserRepository.php
Normal file
45
app/Repositories/User/UserRepository.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* UserRepository.php
|
||||||
|
* Copyright (C) 2016 Sander Dorigo
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FireflyIII\Repositories\User;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Models\Role;
|
||||||
|
use FireflyIII\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class UserRepository
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Repositories\User
|
||||||
|
*/
|
||||||
|
class UserRepository implements UserRepositoryInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User $user
|
||||||
|
* @param string $role
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function attachRole(User $user, string $role): bool
|
||||||
|
{
|
||||||
|
$admin = Role::where('name', 'owner')->first();
|
||||||
|
$user->attachRole($admin);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function count(): int
|
||||||
|
{
|
||||||
|
return User::count();
|
||||||
|
}
|
||||||
|
}
|
34
app/Repositories/User/UserRepositoryInterface.php
Normal file
34
app/Repositories/User/UserRepositoryInterface.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* UserRepositoryInterface.php
|
||||||
|
* Copyright (C) 2016 Sander Dorigo
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FireflyIII\Repositories\User;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface UserRepositoryInterface
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Repositories\User
|
||||||
|
*/
|
||||||
|
interface UserRepositoryInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param User $user
|
||||||
|
* @param string $role
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function attachRole(User $user, string $role): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function count(): int;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user