1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Fixes for random subdomain generator

This commit is contained in:
David Bomba 2021-05-24 19:39:21 +10:00
parent 2f5cc5ac95
commit 0e61a6f491
12 changed files with 83 additions and 56 deletions

View File

@ -476,4 +476,62 @@ class LoginController extends BaseController
->header('X-App-Version', config('ninja.app_version'))
->header('X-Api-Version', config('ninja.minimum_client_version'));
}
public function redirectToProvider(string $provider)
{
//'https://www.googleapis.com/auth/gmail.send','email','profile','openid'
$scopes = [];
if($provider == 'google'){
$scopes = ['https://www.googleapis.com/auth/gmail.send','email','profile','openid'];
}
if (request()->has('code')) {
return $this->handleProviderCallback($provider);
} else {
return Socialite::driver($provider)->scopes($scopes)->redirect();
}
}
public function handleProviderCallback(string $provider)
{
$socialite_user = Socialite::driver($provider)
->stateless()
->user();
// if($user = OAuth::handleAuth($socialite_user, $provider))
// {
// Auth::login($user, true);
// return redirect($this->redirectTo);
// }
// else if(MultiDB::checkUserEmailExists($socialite_user->getEmail()))
// {
// Session::flash('error', 'User exists in system, but not with this authentication method'); //todo add translations
// return view('auth.login');
// }
// else {
// //todo
// $name = OAuth::splitName($socialite_user->getName());
// $new_account = [
// 'first_name' => $name[0],
// 'last_name' => $name[1],
// 'password' => '',
// 'email' => $socialite_user->getEmail(),
// 'oauth_user_id' => $socialite_user->getId(),
// 'oauth_provider_id' => $provider
// ];
// $account = CreateAccount::dispatchNow($new_account);
// Auth::login($account->default_company->owner(), true);
// $cookie = cookie('db', $account->default_company->db);
// return redirect($this->redirectTo)->withCookie($cookie);
// }
}
}

View File

@ -164,7 +164,7 @@ class BaseController extends Controller
*/
public function notFoundClient()
{
return abort(404);
abort(404, 'Page not found in client portal.');
}
/**

View File

@ -68,7 +68,7 @@ class DocumentController extends Controller
$documents->map(function ($document) {
if (auth()->user('contact')->client->id != $document->documentable->id) {
abort(401);
abort(401, 'Permission denied');
}
});

View File

@ -31,7 +31,7 @@ class EntityViewController extends Controller
public function index(string $entity_type, string $invitation_key)
{
if (! in_array($entity_type, $this->entity_types)) {
abort(404);
abort(404, 'Entity not found');
}
$invitation_entity = sprintf('App\\Models\\%sInvitation', ucfirst($entity_type));
@ -91,7 +91,7 @@ class EntityViewController extends Controller
public function handlePassword(string $entity_type, string $invitation_key)
{
if (! in_array($entity_type, $this->entity_types)) {
abort(404);
abort(404, 'Entity not found');
}
$invitation_entity = sprintf('App\\Models\\%sInvitation', ucfirst($entity_type));

View File

@ -149,6 +149,6 @@ class PaymentMethodController extends Controller
return $gateway = auth()->user()->client->getBankTransferGateway();
}
return abort(404);
abort(404, 'Gateway not found.');
}
}

View File

@ -93,11 +93,16 @@ class LoginController extends BaseController
public function redirectToProvider(string $provider)
{
//'https://www.googleapis.com/auth/gmail.send','email','profile','openid'
//
$scopes = [];
if($provider == 'google'){
$scopes = ['https://www.googleapis.com/auth/gmail.send','email','profile','openid'];
}
if (request()->has('code')) {
return $this->handleProviderCallback($provider);
} else {
return Socialite::driver($provider)->scopes()->redirect();
return Socialite::driver($provider)->scopes($scopes)->redirect();
}
}
@ -231,43 +236,5 @@ class LoginController extends BaseController
}
}
/*
* Received the returning object from the provider
* which we will use to resolve the user, we return the response in JSON format
*
* @return json
public function handleProviderCallbackApiUser(string $provider)
{
$socialite_user = Socialite::driver($provider)->stateless()->user();
if($user = OAuth::handleAuth($socialite_user, $provider))
{
return $this->itemResponse($user);
}
else if(MultiDB::checkUserEmailExists($socialite_user->getEmail()))
{
return $this->errorResponse(['message'=>'User exists in system, but not with this authentication method'], 400);
}
else {
//todo
$name = OAuth::splitName($socialite_user->getName());
$new_account = [
'first_name' => $name[0],
'last_name' => $name[1],
'password' => '',
'email' => $socialite_user->getEmail(),
];
$account = CreateAccount::dispatchNow($new_account);
return $this->itemResponse($account->default_company->owner());
}
}
*/
}

View File

@ -643,18 +643,12 @@ class TaskController extends BaseController
$sort_status_id = $this->decodePrimaryKey($key);
// nlog($task_list);
foreach ($task_list as $key => $task)
{
// nlog($task);
$task_record = Task::where('id', $this->decodePrimaryKey($task))
->where('company_id', auth()->user()->company()->id)
->first();
// nlog($task_record->id);
$task_record->status_order = $key;
$task_record->status_id = $sort_status_id;
@ -663,6 +657,6 @@ class TaskController extends BaseController
}
return response()->json(['message' => 'Ok'],200);
return response()->json(['message' => 'Ok'], 200);
}
}

View File

@ -52,6 +52,6 @@ class ContactRegister
return $next($request);
}
return abort(404);
abort(404, 'ContactRegister Middlware');
}
}

View File

@ -53,6 +53,6 @@ class RegisterRequest extends FormRequest
return $company;
}
abort(404);
abort(404, 'Register request not found.');
}
}

View File

@ -12,7 +12,9 @@
namespace App\Jobs\Company;
use App\DataMapper\CompanySettings;
use App\Libraries\MultiDB;
use App\Models\Company;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
@ -60,6 +62,12 @@ class CreateCompany
$company->subdomain = isset($this->request['subdomain']) ? $this->request['subdomain'] : '';
$company->custom_fields = new \stdClass;
$company->default_password_timeout = 1800000;
if(Ninja::isHosted())
$company->subdomain = MultiDB::randomSubdomainGenerator();
else
$company->subdomain = '';
$company->save();
return $company;

View File

@ -45,7 +45,7 @@ class VendorUpdatedActivity implements ShouldQueue
$fields = new stdClass;
$user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->vendor->user_id;
$user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->vendor->user_id;
$fields->vendor_id = $vendor->id;
$fields->user_id = $user_id;

View File

@ -24,7 +24,7 @@ Route::post('password/reset', 'Auth\ResetPasswordController@reset')->middleware(
* Social authentication
*/
// Route::get('auth/{provider}', 'Auth\LoginController@redirectToProvider');
Route::get('auth/{provider}', 'Auth\LoginController@redirectToProvider');
// Route::get('auth/{provider}/create', 'Auth\LoginController@redirectToProviderAndCreate');
/*