Пример #1
0
 public function getStarted()
 {
     if (Auth::check()) {
         return Redirect::to('invoices/create');
     }
     if (!Utils::isNinja() && !Utils::allowNewAccounts() && Account::count() > 0) {
         return Redirect::to('/login');
     }
     $user = false;
     $guestKey = Input::get('guest_key');
     if ($guestKey) {
         $user = User::where('password', '=', $guestKey)->first();
         if ($user && $user->registered) {
             return Redirect::to('/');
         }
     }
     if (!$user) {
         $account = $this->accountRepo->create();
         $user = $account->users()->first();
         Session::forget(RECENTLY_VIEWED);
     }
     Auth::login($user, true);
     Event::fire(new UserLoggedIn());
     return Redirect::to('invoices/create')->with('sign_up', Input::get('sign_up'));
 }
Пример #2
0
 public function getStarted()
 {
     $user = false;
     $guestKey = Input::get('guest_key');
     // local storage key to login until registered
     $prevUserId = Session::pull(PREV_USER_ID);
     // last user id used to link to new account
     if (Auth::check()) {
         return Redirect::to('invoices/create');
     }
     if (!Utils::isNinja() && (Account::count() > 0 && !$prevUserId)) {
         return Redirect::to('/login');
     }
     if ($guestKey && !$prevUserId) {
         $user = User::where('password', '=', $guestKey)->first();
         if ($user && $user->registered) {
             return Redirect::to('/');
         }
     }
     if (!$user) {
         $account = $this->accountRepo->create();
         $user = $account->users()->first();
         Session::forget(RECENTLY_VIEWED);
         if ($prevUserId) {
             $users = $this->accountRepo->associateAccounts($user->id, $prevUserId);
             Session::put(SESSION_USER_ACCOUNTS, $users);
         }
     }
     Auth::login($user, true);
     event(new UserLoggedIn());
     $redirectTo = Input::get('redirect_to') ?: 'invoices/create';
     return Redirect::to($redirectTo)->with('sign_up', Input::get('sign_up'));
 }
Пример #3
0
 public function showSetup()
 {
     if (Utils::isNinja() || Utils::isDatabaseSetup() && Account::count() > 0) {
         return Redirect::to('/');
     }
     $view = View::make('setup');
     return Response::make($view);
 }
 public function showIndex()
 {
     Session::reflash();
     if (!Utils::isNinja() && (!Utils::isDatabaseSetup() || Account::count() == 0)) {
         return Redirect::to('/setup');
     } elseif (Auth::check()) {
         return Redirect::to('/dashboard');
     } else {
         return Redirect::to('/login');
     }
 }
Пример #5
0
 public function showIndex()
 {
     Artisan::call('cache:clear', array());
     // Artisan::call('Cache:clear',array());
     Session::reflash();
     if (!Utils::isNinja() && (!Utils::isDatabaseSetup() || Account::count() == 0)) {
         return Redirect::to('/setup');
     } elseif (Auth::check()) {
         return Redirect::to('/dashboard');
     } else {
         return Redirect::to('/login');
     }
 }
Пример #6
0
 public function doSetup()
 {
     if (Utils::isNinjaProd() || Utils::isDatabaseSetup() && Account::count() > 0) {
         return Redirect::to('/');
     }
     $valid = false;
     $test = Input::get('test');
     $app = Input::get('app');
     $app['key'] = str_random(RANDOM_KEY_LENGTH);
     $database = Input::get('database');
     $dbType = $database['default'];
     $database['connections'] = [$dbType => $database['type']];
     $mail = Input::get('mail');
     $email = $mail['username'];
     $mail['from']['address'] = $email;
     if ($test == 'mail') {
         return self::testMail($mail);
     }
     $valid = self::testDatabase($database);
     if ($test == 'db') {
         return $valid === true ? 'Success' : $valid;
     } elseif (!$valid) {
         return Redirect::to('/setup')->withInput();
     }
     $config = "APP_ENV=production\n" . "APP_DEBUG=false\n" . "APP_URL={$app['url']}\n" . "APP_KEY={$app['key']}\n\n" . "DB_TYPE={$dbType}\n" . "DB_HOST={$database['type']['host']}\n" . "DB_DATABASE={$database['type']['database']}\n" . "DB_USERNAME={$database['type']['username']}\n" . "DB_PASSWORD={$database['type']['password']}\n\n" . "MAIL_DRIVER={$mail['driver']}\n" . "MAIL_PORT={$mail['port']}\n" . "MAIL_ENCRYPTION={$mail['encryption']}\n" . "MAIL_HOST={$mail['host']}\n" . "MAIL_USERNAME={$mail['username']}\n" . "MAIL_FROM_NAME={$mail['from']['name']}\n" . "MAIL_PASSWORD={$mail['password']}\n\n" . "#PHANTOMJS_CLOUD_KEY='a-demo-key-with-low-quota-per-ip-address'";
     // Write Config Settings
     $fp = fopen(base_path() . "/.env", 'w');
     fwrite($fp, $config);
     fclose($fp);
     // == DB Migrate & Seed == //
     // Artisan::call('migrate:rollback', array('--force' => true)); // Debug Purposes
     Artisan::call('migrate', array('--force' => true));
     if (Industry::count() == 0) {
         Artisan::call('db:seed', array('--force' => true));
     }
     Cache::flush();
     Artisan::call('optimize', array('--force' => true));
     $firstName = trim(Input::get('first_name'));
     $lastName = trim(Input::get('last_name'));
     $email = trim(strtolower(Input::get('email')));
     $password = trim(Input::get('password'));
     $account = $this->accountRepo->create($firstName, $lastName, $email, $password);
     $user = $account->users()->first();
     return Redirect::to('/login');
 }
Пример #7
0
 public function updateSetup()
 {
     if (Utils::isNinjaProd()) {
         return Redirect::to('/');
     }
     if (!Auth::check() && Utils::isDatabaseSetup() && Account::count() > 0) {
         return Redirect::to('/');
     }
     if (!($canUpdateEnv = @fopen(base_path() . "/.env", 'w'))) {
         Session::flash('error', 'Warning: Permission denied to write to .env config file, try running <code>sudo chown www-data:www-data /path/to/ninja/.env</code>');
         return Redirect::to('/settings/system_settings');
     }
     $app = Input::get('app');
     $db = Input::get('database');
     $mail = Input::get('mail');
     $_ENV['APP_URL'] = $app['url'];
     $_ENV['APP_DEBUG'] = Input::get('debug') ? 'true' : 'false';
     $_ENV['DB_TYPE'] = 'mysql';
     // $db['default'];
     $_ENV['DB_HOST'] = $db['type']['host'];
     $_ENV['DB_DATABASE'] = $db['type']['database'];
     $_ENV['DB_USERNAME'] = $db['type']['username'];
     $_ENV['DB_PASSWORD'] = $db['type']['password'];
     if ($mail) {
         $_ENV['MAIL_DRIVER'] = $mail['driver'];
         $_ENV['MAIL_PORT'] = $mail['port'];
         $_ENV['MAIL_ENCRYPTION'] = $mail['encryption'];
         $_ENV['MAIL_HOST'] = $mail['host'];
         $_ENV['MAIL_USERNAME'] = $mail['username'];
         $_ENV['MAIL_FROM_NAME'] = $mail['from']['name'];
         $_ENV['MAIL_PASSWORD'] = $mail['password'];
         $_ENV['MAIL_FROM_ADDRESS'] = $mail['username'];
     }
     $config = '';
     foreach ($_ENV as $key => $val) {
         $config .= "{$key}={$val}\n";
     }
     $fp = fopen(base_path() . "/.env", 'w');
     fwrite($fp, $config);
     fclose($fp);
     Session::flash('message', trans('texts.updated_settings'));
     return Redirect::to('/settings/system_settings');
 }