diff --git a/app/Constants.php b/app/Constants.php index be4f6bc450..bf89dd6066 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -288,7 +288,6 @@ if (! defined('APP_NAME')) { define('REQUESTED_PRO_PLAN', 'REQUESTED_PRO_PLAN'); define('DEMO_ACCOUNT_ID', 'DEMO_ACCOUNT_ID'); - define('PREV_USER_ID', 'PREV_USER_ID'); define('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h'); define('NINJA_LICENSE_ACCOUNT_KEY', 'AsFmBAeLXF0IKf7tmi0eiyZfmWW9hxMT'); define('NINJA_GATEWAY_ID', GATEWAY_STRIPE); diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 68bb58b4c3..2d32918243 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -123,17 +123,16 @@ class AccountController extends BaseController { $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)) { + if (! Utils::isNinja() && Account::count() > 0) { return Redirect::to('/login'); } - if ($guestKey && ! $prevUserId) { + if ($guestKey) { $user = User::where('password', '=', $guestKey)->first(); if ($user && $user->registered) { @@ -144,11 +143,6 @@ class AccountController extends BaseController if (! $user) { $account = $this->accountRepo->create(); $user = $account->users()->first(); - - if ($prevUserId) { - $users = $this->accountRepo->associateAccounts($user->id, $prevUserId); - Session::put(SESSION_USER_ACCOUNTS, $users); - } } Auth::login($user, true); @@ -1234,7 +1228,7 @@ class AccountController extends BaseController public function checkEmail() { $email = User::withTrashed()->where('email', '=', Input::get('email')) - ->where('id', '<>', Auth::user()->id) + ->where('id', '<>', Auth::user()->registered ? 0 : Auth::user()->id) ->first(); if ($email) { @@ -1249,36 +1243,58 @@ class AccountController extends BaseController */ public function submitSignup() { + $user = Auth::user(); + $account = $user->account; + $rules = [ 'new_first_name' => 'required', 'new_last_name' => 'required', 'new_password' => 'required|min:6', - 'new_email' => 'email|required|unique:users,email,'.Auth::user()->id.',id', + 'new_email' => 'email|required|unique:users,email', ]; + if (! $user->registered) { + $rules['new_email'] .= ',' . Auth::user()->id . ',id'; + } + $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return ''; } - /** @var \App\Models\User $user */ - $user = Auth::user(); - $user->first_name = trim(Input::get('new_first_name')); - $user->last_name = trim(Input::get('new_last_name')); - $user->email = trim(strtolower(Input::get('new_email'))); - $user->username = $user->email; - $user->password = bcrypt(trim(Input::get('new_password'))); - $user->registered = true; - $user->save(); + $firstName = trim(Input::get('new_first_name')); + $lastName = trim(Input::get('new_last_name')); + $email = trim(strtolower(Input::get('new_email'))); + $password = trim(Input::get('new_password')); - $user->account->startTrial(PLAN_PRO); + if ($user->registered) { + $newAccount = $this->accountRepo->create($firstName, $lastName, $email, $password, $account->company); + $newUser = $newAccount->users()->first(); + $users = $this->accountRepo->associateAccounts($user->id, $newUser->id); - if (Input::get('go_pro') == 'true') { - Session::set(REQUESTED_PRO_PLAN, true); + Session::flash('message', trans('texts.created_new_company')); + Session::put(SESSION_USER_ACCOUNTS, $users); + Auth::loginUsingId($newUser->id); + + return RESULT_SUCCESS; + } else { + $user->first_name = $firstName; + $user->last_name = $lastName; + $user->email = $email; + $user->username = $user->email; + $user->password = bcrypt($password); + $user->registered = true; + $user->save(); + + $user->account->startTrial(PLAN_PRO); + + if (Input::get('go_pro') == 'true') { + Session::set(REQUESTED_PRO_PLAN, true); + } + + return "{$user->first_name} {$user->last_name}"; } - - return "{$user->first_name} {$user->last_name}"; } /** diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 7f26529fe0..7948d210e2 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -65,12 +65,6 @@ class HomeController extends BaseController */ public function invoiceNow() { - if (Auth::check() && Input::get('new_company')) { - Session::put(PREV_USER_ID, Auth::user()->id); - Auth::user()->clearSession(); - Auth::logout(); - } - // Track the referral/campaign code if (Input::has('rc')) { Session::set(SESSION_REFERRAL_CODE, Input::get('rc')); diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index 43f2de1f82..8129f034f0 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -27,15 +27,17 @@ use Validator; class AccountRepository { - public function create($firstName = '', $lastName = '', $email = '', $password = '') + public function create($firstName = '', $lastName = '', $email = '', $password = '', $company = false) { - $company = new Company(); - $company->utm_source = Input::get('utm_source'); - $company->utm_medium = Input::get('utm_medium'); - $company->utm_campaign = Input::get('utm_campaign'); - $company->utm_term = Input::get('utm_term'); - $company->utm_content = Input::get('utm_content'); - $company->save(); + if (! $company) { + $company = new Company(); + $company->utm_source = Input::get('utm_source'); + $company->utm_medium = Input::get('utm_medium'); + $company->utm_campaign = Input::get('utm_campaign'); + $company->utm_term = Input::get('utm_term'); + $company->utm_content = Input::get('utm_content'); + $company->save(); + } $account = new Account(); $account->ip = Request::getClientIp(); @@ -617,61 +619,7 @@ class AccountRepository $record->save(); - $users = $this->getUserAccounts($record); - - // Pick the primary user - foreach ($users as $user) { - if (! $user->public_id) { - $useAsPrimary = false; - if (empty($primaryUser)) { - $useAsPrimary = true; - } - - $planDetails = $user->account->getPlanDetails(false, false); - $planLevel = 0; - - if ($planDetails) { - $planLevel = 1; - if ($planDetails['plan'] == PLAN_ENTERPRISE) { - $planLevel = 2; - } - - if (! $useAsPrimary && ( - $planLevel > $primaryUserPlanLevel - || ($planLevel == $primaryUserPlanLevel && $planDetails['expires'] > $primaryUserPlanExpires) - )) { - $useAsPrimary = true; - } - } - - if ($useAsPrimary) { - $primaryUser = $user; - $primaryUserPlanLevel = $planLevel; - if ($planDetails) { - $primaryUserPlanExpires = $planDetails['expires']; - } - } - } - } - - // Merge other companies into the primary user's company - if (! empty($primaryUser)) { - foreach ($users as $user) { - if ($user == $primaryUser || $user->public_id) { - continue; - } - - if ($user->account->company_id != $primaryUser->account->company_id) { - foreach ($user->account->company->accounts as $account) { - $account->company_id = $primaryUser->account->company_id; - $account->save(); - } - $user->account->company->forceDelete(); - } - } - } - - return $users; + return $this->loadAccounts($userId1); } public function unlinkAccount($account) diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index f94a4563ed..cd54179087 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2368,7 +2368,7 @@ $LANG = array( // New Client Portal styling 'invoice_from' => 'Invoices From:', - 'email_alias_message' => 'Note: we require each user to have a unique email address.
Consider using an alias. ie, email+label@example.com', + 'email_alias_message' => 'We require each company to have a unique email address.
Consider using an alias. ie, email+label@example.com', 'full_name' => 'Full Name', 'month_year' => 'MONTH/YEAR', 'valid_thru' => 'Valid\nthru', @@ -2435,6 +2435,7 @@ $LANG = array( 'reset_counter_help' => 'Automatically reset the invoice and quote counters.', 'auto_bill_failed' => 'Auto-billing for invoice :invoice_number failed', 'online_payment_discount' => 'Online Payment Discount', + 'created_new_company' => 'Successfully created new company', ); diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index 604ec38b29..959fe1968a 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -4,115 +4,9 @@ @section('head') - + +