mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-09 06:55:43 -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 FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Role;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
||||
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
||||
@ -94,13 +94,14 @@ class AuthController extends Controller
|
||||
/**
|
||||
* Handle a registration request for the application.
|
||||
*
|
||||
* @param UserRepositoryInterface $repository
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @throws FireflyException
|
||||
* @throws \Illuminate\Foundation\Validation\ValidationException
|
||||
*/
|
||||
public function register(Request $request)
|
||||
public function register(UserRepositoryInterface $repository, Request $request)
|
||||
{
|
||||
$validator = $this->validator($request->all());
|
||||
|
||||
@ -146,12 +147,10 @@ class AuthController extends Controller
|
||||
Session::flash('gaEventAction', 'new-registration');
|
||||
|
||||
// first user ever?
|
||||
if (User::count() == 1) {
|
||||
$admin = Role::where('name', 'owner')->first();
|
||||
Auth::user()->attachRole($admin);
|
||||
if ($repository->count() == 1) {
|
||||
$repository->attachRole(Auth::user(), 'owner');
|
||||
}
|
||||
|
||||
|
||||
return redirect($this->redirectPath());
|
||||
}
|
||||
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\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
||||
$this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search');
|
||||
$this->app->bind('FireflyIII\Repositories\User\UserRepositoryInterface', 'FireflyIII\Repositories\User\UserRepository');
|
||||
|
||||
// CSV import
|
||||
$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