1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
invoiceninja/app/Models/LookupUser.php

70 lines
1.7 KiB
PHP
Raw Normal View History

2017-04-30 19:08:49 +02:00
<?php
namespace App\Models;
use Eloquent;
2017-04-30 22:07:58 +02:00
use App\Models\User;
2017-04-30 19:08:49 +02:00
/**
* Class ExpenseCategory.
*/
2017-04-30 21:18:17 +02:00
class LookupUser extends LookupModel
2017-04-30 19:08:49 +02:00
{
/**
* @var array
*/
protected $fillable = [
'lookup_account_id',
'email',
2017-04-30 21:29:15 +02:00
'user_id',
2017-05-10 12:02:20 +02:00
'confirmation_code',
2017-04-30 19:08:49 +02:00
];
2017-05-01 16:29:31 +02:00
public static function updateUser($accountKey, $userId, $email, $confirmationCode)
2017-05-01 09:19:27 +02:00
{
if (! env('MULTI_DB_ENABLED')) {
return;
}
$current = config('database.default');
config(['database.default' => DB_NINJA_LOOKUP]);
$lookupAccount = LookupAccount::whereAccountKey($accountKey)
->firstOrFail();
$lookupUser = LookupUser::whereLookupAccountId($lookupAccount->id)
->whereUserId($userId)
->firstOrFail();
$lookupUser->email = $email;
2017-05-01 16:29:31 +02:00
$lookupUser->confirmation_code = $confirmationCode;
2017-05-01 09:19:27 +02:00
$lookupUser->save();
config(['database.default' => $current]);
}
public static function validateEmail($email, $user = false)
{
if (! env('MULTI_DB_ENABLED')) {
return true;
}
$current = config('database.default');
config(['database.default' => DB_NINJA_LOOKUP]);
$lookupUser = LookupUser::whereEmail($email)->first();
if ($user) {
$lookupAccount = LookupAccount::whereAccountKey($user->account->account_key)->firstOrFail();
$isValid = ! $lookupUser || ($lookupUser->lookup_account_id == $lookupAccount->id && $lookupUser->user_id == $user->id);
} else {
$isValid = ! $lookupUser;
}
config(['database.default' => $current]);
return $isValid;
}
2017-04-30 19:08:49 +02:00
}