diff --git a/app/Events/Account/AccountCreated.php b/app/Events/Account/AccountCreated.php new file mode 100644 index 000000000000..0b8d9d9c8323 --- /dev/null +++ b/app/Events/Account/AccountCreated.php @@ -0,0 +1,38 @@ +user = $user; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Events/UserSignedUp.php b/app/Events/User/UserCreated.php similarity index 94% rename from app/Events/UserSignedUp.php rename to app/Events/User/UserCreated.php index 6ded1d818b3b..ca95be8ce5a0 100644 --- a/app/Events/UserSignedUp.php +++ b/app/Events/User/UserCreated.php @@ -1,6 +1,6 @@ middleware('guest'); + } + + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + return view('signup.index'); + + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\SignupRequest $request + * @return \Illuminate\Http\Response + */ + public function store(CreateAccountRequest $request) + { + + CreateAccount::dispatchNow($request); + + //todo redirect to localization setup workflow + return redirect()->route('user.dashboard'); + + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function show($id) + { + // + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + // + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + // + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + // + } +} diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index d543c6dc2b22..b70d7c49e347 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -2,7 +2,9 @@ namespace App\Http\Controllers; +use App\Http\Requests\Company\CreateCompanyRequest; use App\Http\Requests\SignupRequest; +use App\Jobs\Company\CreateCompany; use App\Jobs\RegisterNewAccount; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Http\Request; @@ -45,13 +47,10 @@ class CompanyController extends Controller * @param \App\Http\Requests\SignupRequest $request * @return \Illuminate\Http\Response */ - public function store(SignupRequest $request) + public function store(CreateCompanyRequest $request) { - $user = RegisterNewAccount::dispatchNow($request); - - //log user in - Auth::guard('user')->login($user, true); + CreateCompany::dispatchNow($request); //todo redirect to localization setup workflow return redirect()->route('user.dashboard'); diff --git a/app/Http/Requests/SignupRequest.php b/app/Http/Requests/Account/CreateAccountRequest.php similarity index 90% rename from app/Http/Requests/SignupRequest.php rename to app/Http/Requests/Account/CreateAccountRequest.php index 8f31e4af4fa5..2789bd38f352 100644 --- a/app/Http/Requests/SignupRequest.php +++ b/app/Http/Requests/Account/CreateAccountRequest.php @@ -1,12 +1,13 @@ request = $request; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + + $account = Account::create($this->request->toArray()); + + $user = CreateUser::dispatchNow($this->request, $account); + + $company = CreateCompany::dispatchNow($this->request, $account); + + UserCompany::create([ + 'user_id' => $user->id, + 'account_id' => $account->id, + 'company_id' => $company->id, + 'is_admin' => true, + 'is_owner' => true, + 'permissions' => '', + + ]); + + Auth::loginUsingId($user->id, true); + + event(new AccountCreated()); + + return $user; + } +} diff --git a/app/Jobs/Company/CreateCompany.php b/app/Jobs/Company/CreateCompany.php new file mode 100644 index 000000000000..88cc75d9df92 --- /dev/null +++ b/app/Jobs/Company/CreateCompany.php @@ -0,0 +1,55 @@ +request = $request; + $this->account = $account; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + + $company = new Company(); + $company->name = $this->request->first_name . ' ' . $this->request->last_name; + $company->account_id = $this->account->id; + $company->company_key = strtolower(str_random(RANDOM_KEY_LENGTH)); + $company->ip = $this->request->ip(); + $company->save(); + + + return $company; + } +} diff --git a/app/Jobs/RegisterNewAccount.php b/app/Jobs/RegisterNewAccount.php deleted file mode 100644 index 19c75dfc0ccb..000000000000 --- a/app/Jobs/RegisterNewAccount.php +++ /dev/null @@ -1,81 +0,0 @@ -request = $request; - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - - $ac = new Account(); - $ac->utm_source = $this->request->input('utm_source'); - $ac->utm_medium = $this->request->input('utm_medium'); - $ac->utm_campaign = $this->request->input('utm_campaign'); - $ac->utm_term = $this->request->input('utm_term'); - $ac->utm_content = $this->request->input('utm_content'); - $ac->save(); - - $company = new Company(); - $company->account_id = $ac->id; - $company->name = $this->request->first_name . ' ' . $this->request->last_name; - $company->company_key = strtolower(str_random(RANDOM_KEY_LENGTH)); - $company->ip = $this->request->ip(); - $company->save(); - - $user = new User(); - $user->account_id = $ac->id; - $user->password = Hash::make($this->request->input('password')); - $user->accepted_terms_version = config('ninja.terms_version'); - $user->confirmation_code = strtolower(str_random(RANDOM_KEY_LENGTH)); - $user->db = config('database.default'); - $user->fill($this->request->all()); - $user->save(); - - $user_account = new UserCompany(); - $user_account->user_id = $user->id; - $user_account->account_id = $ac->id; - $user_account->company_id = $company->id; - $user_account->is_owner = TRUE; - $user_account->is_admin = TRUE; - $user_account->permissions = ''; - $user_account->save(); - - $ac->default_company_id = $ac->id; - $ac->save(); - - //fire account created job - event(new UserSignedUp($user)); - - return $user; - } -} diff --git a/app/Jobs/User/CreateUser.php b/app/Jobs/User/CreateUser.php new file mode 100644 index 000000000000..9044e0dfd383 --- /dev/null +++ b/app/Jobs/User/CreateUser.php @@ -0,0 +1,50 @@ +request = $request; + $this->account = $account; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + + $user = new User(); + $user->account_id = $this->account->id; + $user->password = Hash::make($this->request->input('password')); + $user->accepted_terms_version = config('ninja.terms_version'); + $user->confirmation_code = strtolower(str_random(RANDOM_KEY_LENGTH)); + $user->db = config('database.default'); + $user->fill($this->request->all()); + $user->save(); + + + return $user; + } +} diff --git a/app/Listeners/SendConfirmationNotification.php b/app/Listeners/SendVerificationNotification.php similarity index 81% rename from app/Listeners/SendConfirmationNotification.php rename to app/Listeners/SendVerificationNotification.php index e6f4ba528422..e3f0cfbfefa8 100644 --- a/app/Listeners/SendConfirmationNotification.php +++ b/app/Listeners/SendVerificationNotification.php @@ -2,10 +2,11 @@ namespace App\Listeners; +use App\Libraries\MultiDB; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -class SendConfirmationNotification +class SendVerificationNotification { /** * Create the event listener. @@ -26,5 +27,7 @@ class SendConfirmationNotification public function handle($event) { //send confirmation email using $event->user + MultiDB::setDB($event->user->db); + } } diff --git a/app/Models/Account.php b/app/Models/Account.php index 1d6bf97f83db..6a6c6dd2c158 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -26,6 +26,11 @@ class Account extends Model 'plan_paid', 'plan_started', 'plan_expires', + 'utm_source', + 'utm_medium', + 'utm_campaign', + 'utm_term', + 'utm_content', ]; /** diff --git a/app/Models/User.php b/app/Models/User.php index 9e8c2c4f9bfe..384a873f230d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -9,7 +9,7 @@ use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; use Laracasts\Presenter\PresentableTrait; -class User extends Authenticatable +class User extends Authenticatable implements MustVerifyEmail { use Notifiable; use SoftDeletes; diff --git a/app/Models/UserCompany.php b/app/Models/UserCompany.php index 5946ee351e36..544110f250e6 100644 --- a/app/Models/UserCompany.php +++ b/app/Models/UserCompany.php @@ -6,5 +6,6 @@ use Illuminate\Database\Eloquent\Model; class UserCompany extends Model { - // + protected $guarded = ['id']; + } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 4783e4898517..77fc926514eb 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,11 +2,11 @@ namespace App\Providers; -use App\Listeners\SendConfirmationNotification; +use App\Events\User\UserCreated; +use App\Listeners\SendVerificationNotification; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -use App\Events\UserSignedUp; class EventServiceProvider extends ServiceProvider { @@ -17,10 +17,10 @@ class EventServiceProvider extends ServiceProvider */ protected $listen = [ Registered::class => [ - SendEmailVerificationNotification::class, + SendVerificationNotification::class, ], - UserSignedUp::class => [ - SendConfirmationNotification::class, + UserCreated::class => [ + SendVerificationNotification::class, ] ]; diff --git a/app/Providers/TelescopeServiceProvider.php b/app/Providers/TelescopeServiceProvider.php new file mode 100644 index 000000000000..bf7ef56242db --- /dev/null +++ b/app/Providers/TelescopeServiceProvider.php @@ -0,0 +1,51 @@ +app->environment() == 'local') { + return true; + } + + return $entry->isReportableException() || + $entry->isFailedJob() || + $entry->isScheduledTask() || + $entry->hasMonitoredTag(); + }); + } + + /** + * Register the Telescope gate. + * + * This gate determines who can access Telescope in non-local environments. + * + * @return void + */ + protected function gate() + { + Gate::define('viewTelescope', function ($user) { + return in_array($user->email, [ + config('ninja.contact.email'), + 'turbo124@gmail.com' + ]); + }); + } +} diff --git a/app/Repositories/AccountRepository.php b/app/Repositories/AccountRepository.php new file mode 100644 index 000000000000..94e21fb8edb8 --- /dev/null +++ b/app/Repositories/AccountRepository.php @@ -0,0 +1,8 @@ +=5.3.3" + }, + "require-dev": { + "jakub-onderka/php-parallel-lint": "^0.9.0", + "phpunit/phpunit": "^4.7|>=5.0 <5.4", + "satooshi/php-coveralls": "^0.6.1", + "squizlabs/php_codesniffer": "^2.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Moontoast\\Math\\": "src/Moontoast/Math/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Ben Ramsey", + "email": "ben@benramsey.com", + "homepage": "https://benramsey.com" + } + ], + "description": "A mathematics library, providing functionality for large numbers", + "homepage": "https://github.com/ramsey/moontoast-math", + "keywords": [ + "bcmath", + "math" + ], + "time": "2017-02-16T16:54:46+00:00" + }, { "name": "nesbot/carbon", "version": "1.34.0", @@ -3270,16 +3378,16 @@ }, { "name": "filp/whoops", - "version": "2.3.0", + "version": "2.3.1", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "a9f129b99df316f847584d482c89c14a9f796e2b" + "reference": "bc0fd11bc455cc20ee4b5edabc63ebbf859324c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/a9f129b99df316f847584d482c89c14a9f796e2b", - "reference": "a9f129b99df316f847584d482c89c14a9f796e2b", + "url": "https://api.github.com/repos/filp/whoops/zipball/bc0fd11bc455cc20ee4b5edabc63ebbf859324c7", + "reference": "bc0fd11bc455cc20ee4b5edabc63ebbf859324c7", "shasum": "" }, "require": { @@ -3327,7 +3435,7 @@ "throwable", "whoops" ], - "time": "2018-10-20T09:00:00+00:00" + "time": "2018-10-23T09:00:00+00:00" }, { "name": "fzaninotto/faker", @@ -3922,16 +4030,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "6.1.1", + "version": "6.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "b097681a19a48e52706f57e47a09594bac4f7cab" + "reference": "4d3ae9b21a7d7e440bd0cf65565533117976859f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b097681a19a48e52706f57e47a09594bac4f7cab", - "reference": "b097681a19a48e52706f57e47a09594bac4f7cab", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4d3ae9b21a7d7e440bd0cf65565533117976859f", + "reference": "4d3ae9b21a7d7e440bd0cf65565533117976859f", "shasum": "" }, "require": { @@ -3981,7 +4089,7 @@ "testing", "xunit" ], - "time": "2018-10-18T09:01:38+00:00" + "time": "2018-10-23T05:59:32+00:00" }, { "name": "phpunit/php-file-iterator", @@ -4174,16 +4282,16 @@ }, { "name": "phpunit/phpunit", - "version": "7.4.1", + "version": "7.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c5a120ade60992bd671a912188ee9ee9f8083bbd" + "reference": "c151651fb6ed264038d486ea262e243af72e5e64" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c5a120ade60992bd671a912188ee9ee9f8083bbd", - "reference": "c5a120ade60992bd671a912188ee9ee9f8083bbd", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c151651fb6ed264038d486ea262e243af72e5e64", + "reference": "c151651fb6ed264038d486ea262e243af72e5e64", "shasum": "" }, "require": { @@ -4254,7 +4362,7 @@ "testing", "xunit" ], - "time": "2018-10-18T09:02:52+00:00" + "time": "2018-10-23T05:57:41+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", diff --git a/config/app.php b/config/app.php index d5d66c7021b2..264e368d5a73 100644 --- a/config/app.php +++ b/config/app.php @@ -177,6 +177,7 @@ return [ App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, + App\Providers\TelescopeServiceProvider::class, App\Providers\RouteServiceProvider::class, ], diff --git a/config/telescope.php b/config/telescope.php new file mode 100644 index 000000000000..14546f9987e1 --- /dev/null +++ b/config/telescope.php @@ -0,0 +1,92 @@ + 'telescope', + + /* + |-------------------------------------------------------------------------- + | Telescope Storage Driver + |-------------------------------------------------------------------------- + | + | This configuration options determines the storage driver that will + | be used to store Telescope's data. In addition, you may set any + | custom options as needed by the particular driver you choose. + | + */ + + 'driver' => env('TELESCOPE_DRIVER', 'database'), + + 'storage' => [ + 'database' => [ + 'connection' => env('DB_CONNECTION', 'mysql'), + ] + ], + + /* + |-------------------------------------------------------------------------- + | Record Pruning + |-------------------------------------------------------------------------- + | + | This configuration options determines how many Telescope records of + | a given type will be kept in storage. This allows you to control + | the amount of disk space claimed by Telescope's entry storage. + | + | When "null", records will not be pruned. + | + */ + + 'limit' => env('TELESCOPE_LIMIT', 100), + + /* + |-------------------------------------------------------------------------- + | Telescope Route Middleware + |-------------------------------------------------------------------------- + | + | These middleware will be assigned to every Telescope route, giving you + | the chance to add your own middleware to this list or change any of + | the existing middleware. Or, you can simply stick with this list. + | + */ + + 'middleware' => [ + 'web', + Authorize::class, + ], + + /* + |-------------------------------------------------------------------------- + | Telescope Watchers + |-------------------------------------------------------------------------- + | + | The following array lists the "watchers" that will be registered with + | Telescope. The watchers gather the application's profile data when + | a request or task is executed. Feel free to customize this list. + | + */ + + 'watchers' => [ + Watchers\CacheWatcher::class => env('TELESCOPE_CACHE_WATCHER', true), + Watchers\CommandWatcher::class => env('TELESCOPE_COMMAND_WATCHER', true), + Watchers\DumpWatcher::class => env('TELESCOPE_DUMP_WATCHER', true), + Watchers\EventWatcher::class => env('TELESCOPE_EVENT_WATCHER', true), + Watchers\ExceptionWatcher::class => env('TELESCOPE_EXCEPTION_WATCHER', true), + Watchers\JobWatcher::class => env('TELESCOPE_JOB_WATCHER', true), + Watchers\LogWatcher::class => env('TELESCOPE_LOG_WATCHER', true), + Watchers\MailWatcher::class => env('TELESCOPE_MAIL_WATCHER', true), + Watchers\ModelWatcher::class => env('TELESCOPE_MODEL_WATCHER', true), + Watchers\NotificationWatcher::class => env('TELESCOPE_NOTIFICATION_WATCHER', true), + + Watchers\QueryWatcher::class => [ + 'enabled' => env('TELESCOPE_QUERY_WATCHER', true), + 'slow' => 100, + ], + + Watchers\RedisWatcher::class => env('TELESCOPE_REDIS_WATCHER', true), + Watchers\RequestWatcher::class => env('TELESCOPE_REQUEST_WATCHER', true), + Watchers\ScheduleWatcher::class => env('TELESCOPE_SCHEDULE_WATCHER', true), + ], +]; diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 738cfb3f166f..15198e3ad0c7 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -158,7 +158,7 @@ class CreateUsersTable extends Migration $table->unsignedInteger('account_id'); $table->unsignedInteger('user_id')->index(); $table->text('permissions'); - $table->boolean('is_owner'); + $table->boolean('is_owner')->default(false); $table->boolean('is_admin'); $table->boolean('is_locked')->default(false); // locks user out of account $table->timestamps(); diff --git a/routes/web.php b/routes/web.php index e6c8d167e49f..4e62ec8fc337 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,8 +13,8 @@ Route::post('logout', 'Auth\LoginController@logout')->name('logout'); */ Route::redirect('/', '/login', 301); -Route::get('signup', 'CompanyController@index')->name('signup'); -Route::post('signup', 'CompanyController@store')->name('signup.submit'); +Route::get('signup', 'AccountController@index')->name('signup'); +Route::post('signup', 'AccountController@store')->name('signup.submit'); Route::get('contact/login', 'Auth\ContactLoginController@showLoginForm')->name('contact.login'); Route::post('contact/login', 'Auth\ContactLoginController@login')->name('contact.login.submit'); @@ -38,6 +38,9 @@ Route::get('auth/{provider}/callback', 'Auth\LoginController@handleProviderCallb * Authenticated User Routes */ +Auth::routes(['verify' => true]); + + Route::group(['middleware' => ['auth:user', 'db']], function () { Route::get('dashboard', 'HomeController@user')->name('user.dashboard');