2016-01-08 09:02:15 -06:00
|
|
|
<?php
|
2018-05-11 03:08:34 -05:00
|
|
|
|
2016-05-20 05:27:31 -05:00
|
|
|
/**
|
|
|
|
* User.php
|
2020-02-16 07:00:57 -06:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-05-20 05:27:31 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-10-04 23:52:15 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 01:40:00 -05:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-01 23:37:26 -05:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-05-20 05:27:31 -05:00
|
|
|
*/
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2018-05-11 03:08:34 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-01-08 09:02:15 -06:00
|
|
|
namespace FireflyIII;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2019-08-17 03:46:32 -05:00
|
|
|
use Eloquent;
|
|
|
|
use Exception;
|
2016-11-22 14:21:11 -06:00
|
|
|
use FireflyIII\Events\RequestedNewPassword;
|
2023-01-29 00:00:26 -06:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2018-06-06 14:23:00 -05:00
|
|
|
use FireflyIII\Models\Account;
|
|
|
|
use FireflyIII\Models\Attachment;
|
|
|
|
use FireflyIII\Models\AvailableBudget;
|
|
|
|
use FireflyIII\Models\Bill;
|
|
|
|
use FireflyIII\Models\Budget;
|
|
|
|
use FireflyIII\Models\Category;
|
2017-04-13 13:47:59 -05:00
|
|
|
use FireflyIII\Models\CurrencyExchangeRate;
|
2021-08-28 08:47:33 -05:00
|
|
|
use FireflyIII\Models\GroupMembership;
|
2020-06-20 03:22:07 -05:00
|
|
|
use FireflyIII\Models\ObjectGroup;
|
2018-06-06 14:23:00 -05:00
|
|
|
use FireflyIII\Models\PiggyBank;
|
|
|
|
use FireflyIII\Models\Preference;
|
2018-06-10 09:59:03 -05:00
|
|
|
use FireflyIII\Models\Recurrence;
|
2018-06-06 14:23:00 -05:00
|
|
|
use FireflyIII\Models\Role;
|
|
|
|
use FireflyIII\Models\Rule;
|
|
|
|
use FireflyIII\Models\RuleGroup;
|
|
|
|
use FireflyIII\Models\Tag;
|
|
|
|
use FireflyIII\Models\Transaction;
|
2019-01-28 13:00:40 -06:00
|
|
|
use FireflyIII\Models\TransactionGroup;
|
2018-06-06 14:23:00 -05:00
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2021-08-29 23:37:55 -05:00
|
|
|
use FireflyIII\Models\UserGroup;
|
2020-11-29 11:35:49 -06:00
|
|
|
use FireflyIII\Models\Webhook;
|
2022-09-24 05:14:27 -05:00
|
|
|
use FireflyIII\Notifications\Admin\TestNotification;
|
2022-10-01 05:21:42 -05:00
|
|
|
use FireflyIII\Notifications\Admin\UserInvitation;
|
2022-09-24 05:14:27 -05:00
|
|
|
use FireflyIII\Notifications\Admin\UserRegistration;
|
|
|
|
use FireflyIII\Notifications\Admin\VersionCheckResult;
|
2019-08-17 03:46:32 -05:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2021-08-29 23:37:55 -05:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2016-02-11 22:49:53 -06:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2016-02-06 03:11:06 -06:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
2016-01-08 09:02:15 -06:00
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2019-08-17 03:46:32 -05:00
|
|
|
use Illuminate\Notifications\DatabaseNotification;
|
|
|
|
use Illuminate\Notifications\DatabaseNotificationCollection;
|
2016-09-15 23:19:40 -05:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
2022-09-18 08:48:28 -05:00
|
|
|
use Illuminate\Notifications\Notification;
|
2019-08-17 03:46:32 -05:00
|
|
|
use Illuminate\Support\Carbon;
|
2018-07-22 11:50:27 -05:00
|
|
|
use Illuminate\Support\Collection;
|
2022-09-18 08:48:28 -05:00
|
|
|
use Illuminate\Support\Str;
|
2019-08-17 03:46:32 -05:00
|
|
|
use Laravel\Passport\Client;
|
2018-02-04 01:14:03 -06:00
|
|
|
use Laravel\Passport\HasApiTokens;
|
2019-08-17 03:46:32 -05:00
|
|
|
use Laravel\Passport\Token;
|
2023-02-22 11:03:31 -06:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2016-11-22 14:21:11 -06:00
|
|
|
use Request;
|
2018-01-10 00:51:47 -06:00
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
2015-02-05 22:04:06 -06:00
|
|
|
|
2016-01-09 01:20:55 -06:00
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Class User.
|
2018-06-06 14:23:00 -05:00
|
|
|
*
|
2023-06-21 05:34:58 -05:00
|
|
|
* @property int $id
|
|
|
|
* @property string $email
|
|
|
|
* @property bool $isAdmin
|
|
|
|
* @property bool $has2FA
|
|
|
|
* @property array $prefs
|
|
|
|
* @property string $password
|
|
|
|
* @property string $mfa_secret
|
|
|
|
* @property Collection $roles
|
|
|
|
* @property string $blocked_code
|
|
|
|
* @property bool $blocked
|
|
|
|
* @property Carbon|null $created_at
|
|
|
|
* @property Carbon|null $updated_at
|
|
|
|
* @property string|null $remember_token
|
|
|
|
* @property string|null $reset
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Account[] $accounts
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Attachment[] $attachments
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|AvailableBudget[] $availableBudgets
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Bill[] $bills
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Budget[] $budgets
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Category[] $categories
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Client[] $clients
|
2020-11-29 11:35:49 -06:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|CurrencyExchangeRate[] $currencyExchangeRates
|
2023-06-21 05:34:58 -05:00
|
|
|
* @property-read DatabaseNotificationCollection|DatabaseNotification[] $notifications
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|PiggyBank[] $piggyBanks
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Preference[] $preferences
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Recurrence[] $recurrences
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|RuleGroup[] $ruleGroups
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Rule[] $rules
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Tag[] $tags
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Token[] $tokens
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|TransactionGroup[] $transactionGroups
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|TransactionJournal[] $transactionJournals
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Transaction[] $transactions
|
2019-08-17 03:46:32 -05:00
|
|
|
* @method static Builder|User newModelQuery()
|
|
|
|
* @method static Builder|User newQuery()
|
|
|
|
* @method static Builder|User query()
|
|
|
|
* @method static Builder|User whereBlocked($value)
|
|
|
|
* @method static Builder|User whereBlockedCode($value)
|
|
|
|
* @method static Builder|User whereCreatedAt($value)
|
|
|
|
* @method static Builder|User whereEmail($value)
|
|
|
|
* @method static Builder|User whereId($value)
|
|
|
|
* @method static Builder|User wherePassword($value)
|
|
|
|
* @method static Builder|User whereRememberToken($value)
|
|
|
|
* @method static Builder|User whereReset($value)
|
|
|
|
* @method static Builder|User whereUpdatedAt($value)
|
2023-06-21 05:34:58 -05:00
|
|
|
* @property string|null $objectguid
|
|
|
|
* @property-read int|null $accounts_count
|
|
|
|
* @property-read int|null $attachments_count
|
|
|
|
* @property-read int|null $available_budgets_count
|
|
|
|
* @property-read int|null $bills_count
|
|
|
|
* @property-read int|null $budgets_count
|
|
|
|
* @property-read int|null $categories_count
|
|
|
|
* @property-read int|null $clients_count
|
|
|
|
* @property-read int|null $currency_exchange_rates_count
|
|
|
|
* @property-read int|null $notifications_count
|
|
|
|
* @property-read int|null $piggy_banks_count
|
|
|
|
* @property-read int|null $preferences_count
|
|
|
|
* @property-read int|null $recurrences_count
|
|
|
|
* @property-read int|null $roles_count
|
|
|
|
* @property-read int|null $rule_groups_count
|
|
|
|
* @property-read int|null $rules_count
|
|
|
|
* @property-read int|null $tags_count
|
|
|
|
* @property-read int|null $tokens_count
|
|
|
|
* @property-read int|null $transaction_groups_count
|
|
|
|
* @property-read int|null $transaction_journals_count
|
|
|
|
* @property-read int|null $transactions_count
|
2021-05-24 01:22:41 -05:00
|
|
|
* @method static Builder|User whereMfaSecret($value)
|
|
|
|
* @method static Builder|User whereObjectguid($value)
|
2023-06-21 05:34:58 -05:00
|
|
|
* @property string|null $provider
|
2021-05-24 01:22:41 -05:00
|
|
|
* @method static Builder|User whereProvider($value)
|
2023-06-21 05:34:58 -05:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|ObjectGroup[] $objectGroups
|
|
|
|
* @property-read int|null $object_groups_count
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|Webhook[] $webhooks
|
|
|
|
* @property-read int|null $webhooks_count
|
|
|
|
* @property string|null $two_factor_secret
|
|
|
|
* @property string|null $two_factor_recovery_codes
|
|
|
|
* @property string|null $guid
|
|
|
|
* @property string|null $domain
|
2021-06-11 23:28:17 -05:00
|
|
|
* @method static Builder|User whereDomain($value)
|
|
|
|
* @method static Builder|User whereGuid($value)
|
|
|
|
* @method static Builder|User whereTwoFactorRecoveryCodes($value)
|
|
|
|
* @method static Builder|User whereTwoFactorSecret($value)
|
2023-06-21 05:34:58 -05:00
|
|
|
* @property int|null $user_group_id
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|GroupMembership[] $groupMemberships
|
|
|
|
* @property-read int|null $group_memberships_count
|
|
|
|
* @property-read UserGroup|null $userGroup
|
2021-09-18 03:08:10 -05:00
|
|
|
* @method static Builder|User whereUserGroupId($value)
|
2023-03-08 23:33:23 -06:00
|
|
|
* @mixin Eloquent
|
2016-01-09 01:20:55 -06:00
|
|
|
*/
|
2016-01-08 09:02:15 -06:00
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
2022-10-30 08:24:10 -05:00
|
|
|
use Notifiable;
|
|
|
|
use HasApiTokens;
|
2016-01-09 01:51:49 -06:00
|
|
|
|
2018-03-03 01:12:18 -06:00
|
|
|
/**
|
2022-02-27 03:04:08 -06:00
|
|
|
* The attributes that should be cast to native types.
|
2018-03-03 01:12:18 -06:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts
|
|
|
|
= [
|
|
|
|
'created_at' => 'datetime',
|
|
|
|
'updated_at' => 'datetime',
|
|
|
|
'blocked' => 'boolean',
|
|
|
|
];
|
2015-02-05 22:04:06 -06:00
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-07-26 08:51:07 -05:00
|
|
|
protected $fillable = ['email', 'password', 'blocked', 'blocked_code'];
|
2015-02-05 22:04:06 -06:00
|
|
|
/**
|
|
|
|
* The attributes excluded from the model's JSON form.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = ['password', 'remember_token'];
|
2015-02-05 22:14:27 -06:00
|
|
|
/**
|
|
|
|
* The database table used by the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'users';
|
2015-02-05 22:04:06 -06:00
|
|
|
|
2018-01-10 00:51:47 -06:00
|
|
|
/**
|
2023-06-21 05:34:58 -05:00
|
|
|
* @param string $value
|
2018-01-10 00:51:47 -06:00
|
|
|
*
|
|
|
|
* @return User
|
2018-04-02 07:17:11 -05:00
|
|
|
* @throws NotFoundHttpException
|
2018-01-10 00:51:47 -06:00
|
|
|
*/
|
2018-02-10 01:21:20 -06:00
|
|
|
public static function routeBinder(string $value): User
|
2018-01-10 00:51:47 -06:00
|
|
|
{
|
2018-02-10 01:21:20 -06:00
|
|
|
if (auth()->check()) {
|
2022-12-29 12:41:57 -06:00
|
|
|
$userId = (int)$value;
|
2018-01-10 00:51:47 -06:00
|
|
|
$user = self::find($userId);
|
2018-04-02 07:17:11 -05:00
|
|
|
if (null !== $user) {
|
2018-01-10 00:51:47 -06:00
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
}
|
2022-10-30 08:24:10 -05:00
|
|
|
throw new NotFoundHttpException();
|
2018-01-10 00:51:47 -06:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
* Link to accounts.
|
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasMany
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public function accounts(): HasMany
|
2015-02-05 22:04:06 -06:00
|
|
|
{
|
2018-04-27 23:23:13 -05:00
|
|
|
return $this->hasMany(Account::class);
|
2015-02-05 22:04:06 -06:00
|
|
|
}
|
2015-02-05 22:01:24 -06:00
|
|
|
|
2021-08-28 08:47:33 -05:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Link to attachments
|
2021-08-28 08:47:33 -05:00
|
|
|
*
|
|
|
|
* @return HasMany
|
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function attachments(): HasMany
|
2021-08-28 08:47:33 -05:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->hasMany(Attachment::class);
|
2021-08-28 08:47:33 -05:00
|
|
|
}
|
|
|
|
|
2015-07-18 02:49:19 -05:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Link to available budgets
|
2017-11-25 13:27:53 -06:00
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasMany
|
2015-07-18 02:49:19 -05:00
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function availableBudgets(): HasMany
|
2015-07-18 02:49:19 -05:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->hasMany(AvailableBudget::class);
|
2015-07-18 02:49:19 -05:00
|
|
|
}
|
|
|
|
|
2020-11-29 11:35:49 -06:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Link to bills.
|
2020-11-29 11:35:49 -06:00
|
|
|
*
|
|
|
|
* @return HasMany
|
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function bills(): HasMany
|
2020-11-29 11:35:49 -06:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->hasMany(Bill::class);
|
2020-11-29 11:35:49 -06:00
|
|
|
}
|
|
|
|
|
2020-05-06 23:44:01 -05:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Link to budgets.
|
2020-05-06 23:44:01 -05:00
|
|
|
*
|
2021-09-18 03:26:12 -05:00
|
|
|
* @return HasMany
|
2020-05-06 23:44:01 -05:00
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function budgets(): HasMany
|
2020-05-06 23:44:01 -05:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->hasMany(Budget::class);
|
2020-05-06 23:44:01 -05:00
|
|
|
}
|
|
|
|
|
2016-12-30 06:47:23 -06:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Link to categories
|
2017-11-25 13:27:53 -06:00
|
|
|
*
|
2016-12-30 06:47:23 -06:00
|
|
|
* @return HasMany
|
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function categories(): HasMany
|
2016-12-30 06:47:23 -06:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->hasMany(Category::class);
|
2016-12-30 06:47:23 -06:00
|
|
|
}
|
|
|
|
|
2015-04-28 01:58:01 -05:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Link to currency exchange rates
|
2017-11-25 13:27:53 -06:00
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasMany
|
2015-04-28 01:58:01 -05:00
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function currencyExchangeRates(): HasMany
|
2015-04-28 01:58:01 -05:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->hasMany(CurrencyExchangeRate::class);
|
2015-04-28 01:58:01 -05:00
|
|
|
}
|
|
|
|
|
2016-01-12 14:37:48 -06:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Generates access token.
|
2017-11-25 13:27:53 -06:00
|
|
|
*
|
2021-09-18 03:26:12 -05:00
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
2016-01-12 14:37:48 -06:00
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function generateAccessToken(): string
|
2016-01-12 14:37:48 -06:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
$bytes = random_bytes(16);
|
|
|
|
|
|
|
|
return bin2hex($bytes);
|
2016-01-12 14:37:48 -06:00
|
|
|
}
|
|
|
|
|
2023-02-22 11:14:14 -06:00
|
|
|
/**
|
|
|
|
* A safe method that returns the user's current administration ID (group ID).
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
* @throws FireflyException
|
|
|
|
*/
|
|
|
|
public function getAdministrationId(): int
|
|
|
|
{
|
|
|
|
$groupId = (int)$this->user_group_id;
|
|
|
|
if (0 === $groupId) {
|
|
|
|
throw new FireflyException('User has no administration ID.');
|
|
|
|
}
|
|
|
|
return $groupId;
|
|
|
|
}
|
|
|
|
|
2020-06-20 03:22:07 -05:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Get the models LDAP domain.
|
2023-06-21 05:34:58 -05:00
|
|
|
*
|
2022-03-29 08:01:12 -05:00
|
|
|
* @return string
|
2022-03-19 05:19:58 -05:00
|
|
|
* @deprecated
|
2020-06-20 03:22:07 -05:00
|
|
|
*
|
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function getLdapDomain()
|
2020-06-20 03:22:07 -05:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->{$this->getLdapDomainColumn()};
|
2020-06-20 03:22:07 -05:00
|
|
|
}
|
|
|
|
|
2016-01-12 14:37:48 -06:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Get the database column name of the domain.
|
2023-06-21 05:34:58 -05:00
|
|
|
*
|
2022-03-29 08:01:12 -05:00
|
|
|
* @return string
|
2022-03-19 05:19:58 -05:00
|
|
|
* @deprecated
|
2017-11-25 13:27:53 -06:00
|
|
|
*
|
2016-01-12 14:37:48 -06:00
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function getLdapDomainColumn()
|
2016-01-12 14:37:48 -06:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return 'domain';
|
2016-01-12 14:37:48 -06:00
|
|
|
}
|
|
|
|
|
2021-08-29 23:37:55 -05:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Get the models LDAP GUID.
|
2023-06-21 05:34:58 -05:00
|
|
|
*
|
2022-03-29 08:01:12 -05:00
|
|
|
* @return string
|
2022-03-19 05:19:58 -05:00
|
|
|
* @deprecated
|
2021-09-18 03:26:12 -05:00
|
|
|
*
|
2021-08-29 23:37:55 -05:00
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function getLdapGuid()
|
2021-08-29 23:37:55 -05:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->{$this->getLdapGuidColumn()};
|
2021-08-29 23:37:55 -05:00
|
|
|
}
|
2021-09-18 03:26:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the models LDAP GUID database column name.
|
2023-06-21 05:34:58 -05:00
|
|
|
*
|
2022-03-29 08:01:12 -05:00
|
|
|
* @return string
|
2022-03-19 05:19:58 -05:00
|
|
|
* @deprecated
|
2021-09-18 03:26:12 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function getLdapGuidColumn()
|
|
|
|
{
|
|
|
|
return 'objectguid';
|
|
|
|
}
|
|
|
|
|
2017-04-13 13:47:59 -05:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
*
|
2017-04-13 13:47:59 -05:00
|
|
|
* @return HasMany
|
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function groupMemberships(): HasMany
|
2017-04-13 13:47:59 -05:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->hasMany(GroupMembership::class)->with(['userGroup', 'userRole']);
|
|
|
|
}
|
|
|
|
|
2023-01-29 00:00:26 -06:00
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* Link to object groups.
|
|
|
|
*
|
|
|
|
* @return HasMany
|
|
|
|
*/
|
|
|
|
public function objectGroups(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(ObjectGroup::class);
|
2017-09-14 11:27:22 -05:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
* Link to piggy banks.
|
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasManyThrough
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public function piggyBanks(): HasManyThrough
|
2015-02-05 22:14:27 -06:00
|
|
|
{
|
2018-04-27 23:23:13 -05:00
|
|
|
return $this->hasManyThrough(PiggyBank::class, Account::class);
|
2015-02-05 22:14:27 -06:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
* Link to preferences.
|
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasMany
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public function preferences(): HasMany
|
2015-02-05 22:14:27 -06:00
|
|
|
{
|
2018-04-27 23:23:13 -05:00
|
|
|
return $this->hasMany(Preference::class);
|
2015-02-05 22:14:27 -06:00
|
|
|
}
|
|
|
|
|
2018-06-10 09:59:03 -05:00
|
|
|
/**
|
|
|
|
* Link to recurring transactions.
|
|
|
|
*
|
|
|
|
* @return HasMany
|
|
|
|
*/
|
|
|
|
public function recurrences(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(Recurrence::class);
|
|
|
|
}
|
|
|
|
|
2022-12-29 12:41:57 -06:00
|
|
|
/**
|
|
|
|
* Get the notification routing information for the given driver.
|
|
|
|
*
|
2023-06-21 05:34:58 -05:00
|
|
|
* @param string $driver
|
|
|
|
* @param Notification|null $notification
|
2022-12-29 12:41:57 -06:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function routeNotificationFor($driver, $notification = null)
|
|
|
|
{
|
2023-06-21 05:34:58 -05:00
|
|
|
if (method_exists($this, $method = 'routeNotificationFor' . Str::studly($driver))) {
|
2022-12-29 12:41:57 -06:00
|
|
|
return $this->{$method}($notification);
|
|
|
|
}
|
|
|
|
$email = $this->email;
|
|
|
|
// see if user has alternative email address:
|
|
|
|
$pref = app('preferences')->getForUser($this, 'remote_guard_alt_email');
|
|
|
|
if (null !== $pref) {
|
|
|
|
$email = $pref->data;
|
|
|
|
}
|
|
|
|
// if user is demo user, send to owner:
|
|
|
|
if ($this->hasRole('demo')) {
|
|
|
|
$email = config('firefly.site_owner');
|
|
|
|
}
|
|
|
|
|
|
|
|
return match ($driver) {
|
|
|
|
'database' => $this->notifications(),
|
|
|
|
'mail' => $email,
|
|
|
|
default => null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-06-21 05:34:58 -05:00
|
|
|
* @param string $role
|
2022-12-29 12:41:57 -06:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasRole(string $role): bool
|
|
|
|
{
|
|
|
|
return $this->roles()->where('name', $role)->count() === 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link to roles.
|
|
|
|
*
|
|
|
|
* @return BelongsToMany
|
|
|
|
*/
|
|
|
|
public function roles(): BelongsToMany
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Role::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Route notifications for the Slack channel.
|
|
|
|
*
|
2023-06-21 05:34:58 -05:00
|
|
|
* @param Notification $notification
|
2022-12-29 12:41:57 -06:00
|
|
|
* @return string
|
2023-02-22 11:03:31 -06:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
2022-12-29 12:41:57 -06:00
|
|
|
*/
|
|
|
|
public function routeNotificationForSlack(Notification $notification): string
|
|
|
|
{
|
|
|
|
// this check does not validate if the user is owner, Should be done by notification itself.
|
|
|
|
if ($notification instanceof TestNotification) {
|
|
|
|
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
|
|
|
|
}
|
|
|
|
if ($notification instanceof UserRegistration) {
|
|
|
|
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
|
|
|
|
}
|
|
|
|
if ($notification instanceof VersionCheckResult) {
|
|
|
|
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
|
|
|
|
}
|
|
|
|
if ($notification instanceof UserInvitation) {
|
|
|
|
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
|
|
|
|
}
|
|
|
|
return app('preferences')->getForUser($this, 'slack_webhook_url', '')->data;
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
* Link to rule groups.
|
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasMany
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public function ruleGroups(): HasMany
|
2015-02-05 22:14:27 -06:00
|
|
|
{
|
2018-04-27 23:23:13 -05:00
|
|
|
return $this->hasMany(RuleGroup::class);
|
2015-02-05 22:14:27 -06:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
* Link to rules.
|
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasMany
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public function rules(): HasMany
|
2015-02-05 22:14:27 -06:00
|
|
|
{
|
2018-04-27 23:23:13 -05:00
|
|
|
return $this->hasMany(Rule::class);
|
2015-02-05 22:14:27 -06:00
|
|
|
}
|
|
|
|
|
2016-12-14 11:59:12 -06:00
|
|
|
/**
|
|
|
|
* Send the password reset notification.
|
|
|
|
*
|
2023-06-21 05:34:58 -05:00
|
|
|
* @param string $token
|
2016-12-14 11:59:12 -06:00
|
|
|
*/
|
2018-08-04 10:30:06 -05:00
|
|
|
public function sendPasswordResetNotification($token): void
|
2016-12-14 11:59:12 -06:00
|
|
|
{
|
2017-06-07 04:13:04 -05:00
|
|
|
$ipAddress = Request::ip();
|
2016-12-14 11:59:12 -06:00
|
|
|
|
2017-06-07 04:13:04 -05:00
|
|
|
event(new RequestedNewPassword($this, $token, $ipAddress));
|
2016-12-14 11:59:12 -06:00
|
|
|
}
|
|
|
|
|
2022-12-29 12:41:57 -06:00
|
|
|
// start LDAP related code
|
|
|
|
|
2021-09-18 03:26:12 -05:00
|
|
|
/**
|
|
|
|
* Set the models LDAP domain.
|
2023-06-21 05:34:58 -05:00
|
|
|
*
|
|
|
|
* @param string $domain
|
2021-09-18 03:26:12 -05:00
|
|
|
*
|
|
|
|
* @return void
|
2022-03-29 08:01:12 -05:00
|
|
|
* @deprecated
|
|
|
|
*
|
2021-09-18 03:26:12 -05:00
|
|
|
*/
|
|
|
|
public function setLdapDomain($domain)
|
|
|
|
{
|
|
|
|
$this->{$this->getLdapDomainColumn()} = $domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the models LDAP GUID.
|
2023-06-21 05:34:58 -05:00
|
|
|
*
|
|
|
|
* @param string $guid
|
2021-09-18 03:26:12 -05:00
|
|
|
*
|
|
|
|
* @return void
|
2022-03-29 08:01:12 -05:00
|
|
|
* @deprecated
|
2021-09-18 03:26:12 -05:00
|
|
|
*/
|
|
|
|
public function setLdapGuid($guid)
|
|
|
|
{
|
|
|
|
$this->{$this->getLdapGuidColumn()} = $guid;
|
|
|
|
}
|
|
|
|
|
2015-03-29 11:28:49 -05:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
* Link to tags.
|
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasMany
|
2015-03-29 11:28:49 -05:00
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public function tags(): HasMany
|
2015-03-29 11:28:49 -05:00
|
|
|
{
|
2018-04-27 23:23:13 -05:00
|
|
|
return $this->hasMany(Tag::class);
|
2015-03-29 11:28:49 -05:00
|
|
|
}
|
|
|
|
|
2019-01-28 13:00:40 -06:00
|
|
|
/**
|
|
|
|
* Link to transaction groups.
|
|
|
|
*
|
|
|
|
* @return HasMany
|
|
|
|
*/
|
|
|
|
public function transactionGroups(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(TransactionGroup::class);
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
* Link to transaction journals.
|
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasMany
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2016-08-26 02:30:52 -05:00
|
|
|
public function transactionJournals(): HasMany
|
2015-02-05 22:14:27 -06:00
|
|
|
{
|
2018-04-27 23:23:13 -05:00
|
|
|
return $this->hasMany(TransactionJournal::class);
|
2015-02-05 22:14:27 -06:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2017-11-25 13:27:53 -06:00
|
|
|
* Link to transactions.
|
|
|
|
*
|
2016-02-06 03:11:06 -06:00
|
|
|
* @return HasManyThrough
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public function transactions(): HasManyThrough
|
2015-02-05 22:14:27 -06:00
|
|
|
{
|
2018-04-27 23:23:13 -05:00
|
|
|
return $this->hasManyThrough(Transaction::class, TransactionJournal::class);
|
2015-02-05 22:14:27 -06:00
|
|
|
}
|
2021-06-11 23:28:17 -05:00
|
|
|
|
|
|
|
/**
|
2021-09-18 03:26:12 -05:00
|
|
|
* @return BelongsTo
|
2021-06-11 23:28:17 -05:00
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function userGroup(): BelongsTo
|
2021-06-11 23:28:17 -05:00
|
|
|
{
|
2022-10-30 08:24:10 -05:00
|
|
|
return $this->belongsTo(UserGroup::class, );
|
2021-06-11 23:28:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2021-09-18 03:26:12 -05:00
|
|
|
* Link to webhooks
|
2021-06-11 23:28:17 -05:00
|
|
|
*
|
2021-09-18 03:26:12 -05:00
|
|
|
* @return HasMany
|
2021-06-11 23:28:17 -05:00
|
|
|
*/
|
2021-09-18 03:26:12 -05:00
|
|
|
public function webhooks(): HasMany
|
2021-06-11 23:28:17 -05:00
|
|
|
{
|
2021-09-18 03:26:12 -05:00
|
|
|
return $this->hasMany(Webhook::class);
|
2021-06-11 23:28:17 -05:00
|
|
|
}
|
2015-02-05 21:39:52 -06:00
|
|
|
}
|