private function _licenses() { for ($i = 0; $i < 20; $i++) { $faker = \Faker\Factory::create(); $license = new License(); $license->license = uniqid(); $license->description = $faker->sentence(); $license->save(); } }
/** * @return mixed */ public function doRegister() { $affiliate = Affiliate::where('affiliate_key', '=', SELF_HOST_AFFILIATE_KEY)->first(); $email = trim(Input::get('email')); if (!$email || $email == TEST_USERNAME) { return RESULT_FAILURE; } $license = new License(); $license->first_name = Input::get('first_name'); $license->last_name = Input::get('last_name'); $license->email = $email; $license->transaction_reference = Request::getClientIp(); $license->license_key = Utils::generateLicense(); $license->affiliate_id = $affiliate->id; $license->product_id = PRODUCT_SELF_HOST; $license->is_claimed = 1; $license->save(); return RESULT_SUCCESS; }
public function do_license_payment() { $testMode = Session::get('test_mode') === 'true'; $rules = array('first_name' => 'required', 'last_name' => 'required', 'card_number' => 'required', 'expiration_month' => 'required', 'expiration_year' => 'required', 'cvv' => 'required', 'address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal_code' => 'required', 'country_id' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('license')->withErrors($validator); } $account = $this->accountRepo->getNinjaAccount(); $account->load('account_gateways.gateway'); $accountGateway = $account->getGatewayByType(PAYMENT_TYPE_CREDIT_CARD); try { $affiliate = Affiliate::find(Session::get('affiliate_id')); if ($testMode) { $ref = 'TEST_MODE'; } else { $gateway = self::createGateway($accountGateway); $details = self::getLicensePaymentDetails(Input::all(), $affiliate); $response = $gateway->purchase($details)->send(); $ref = $response->getTransactionReference(); if (!$ref) { Session::flash('error', $response->getMessage()); return Redirect::to('license')->withInput(); } if (!$response->isSuccessful()) { Session::flash('error', $response->getMessage()); Utils::logError($response->getMessage()); return Redirect::to('license')->withInput(); } } $licenseKey = Utils::generateLicense(); $license = new License(); $license->first_name = Input::get('first_name'); $license->last_name = Input::get('last_name'); $license->email = Input::get('email'); $license->transaction_reference = $ref; $license->license_key = $licenseKey; $license->affiliate_id = Session::get('affiliate_id'); $license->product_id = Session::get('product_id'); $license->save(); $data = ['message' => $affiliate->payment_subtitle, 'license' => $licenseKey, 'hideHeader' => true]; $name = "{$license->first_name} {$license->last_name}"; $this->contactMailer->sendLicensePaymentConfirmation($name, $license->email, $affiliate->price, $license->license_key, $license->product_id); if (Session::has('return_url')) { return Redirect::away(Session::get('return_url') . "?license_key={$license->license_key}&product_id=" . Session::get('product_id')); } else { return View::make('public.license', $data); } } catch (\Exception $e) { $errorMessage = trans('texts.payment_error'); Session::flash('error', $errorMessage); Utils::logError(Utils::getErrorString($e)); return Redirect::to('license')->withInput(); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); if (!$this->option('testrun') == 'true') { $this->comment('======= Importing Licenses from ' . $filename . ' ========='); } else { $this->comment('====== TEST ONLY License Import for ' . $filename . ' ===='); $this->comment('============== NO DATA WILL BE WRITTEN =============='); } if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } $csv = Reader::createFromPath($this->argument('filename')); $csv->setNewline("\r\n"); $csv->setOffset(1); $duplicates = ''; // Loop through the records $nbInsert = $csv->each(function ($row) use($duplicates) { $status_id = 1; // Let's just map some of these entries to more user friendly words if (array_key_exists('0', $row)) { $user_name = trim($row[0]); } else { $user_name = ''; } if (array_key_exists('1', $row)) { $user_email = trim($row[1]); } else { $user_email = ''; } if (array_key_exists('2', $row)) { $user_username = trim($row[2]); } else { $user_username = ''; } if (array_key_exists('3', $row)) { $user_license_name = trim($row[3]); } else { $user_license_name = ''; } if (array_key_exists('4', $row)) { $user_license_serial = trim($row[4]); } else { $user_license_serial = ''; } if (array_key_exists('5', $row)) { $user_licensed_to_name = trim($row[5]); } else { $user_licensed_to_name = ''; } if (array_key_exists('6', $row)) { $user_licensed_to_email = trim($row[6]); } else { $user_licensed_to_email = ''; } if (array_key_exists('7', $row)) { $user_license_seats = trim($row[7]); } else { $user_license_seats = ''; } if (array_key_exists('8', $row)) { $user_license_reassignable = trim($row[8]); if ($user_license_reassignable != '') { if (strtolower($user_license_reassignable) == 'yes' || strtolower($user_license_reassignable) == 'true' || $user_license_reassignable == '1') { $user_license_reassignable = 1; } } else { $user_license_reassignable = 0; } } else { $user_license_reassignable = 0; } if (array_key_exists('9', $row)) { $user_license_supplier = trim($row[9]); } else { $user_license_supplier = ''; } if (array_key_exists('10', $row)) { $user_license_maintained = trim($row[10]); if ($user_license_maintained != '') { if (strtolower($user_license_maintained) == 'yes' || strtolower($user_license_maintained) == 'true' || $user_license_maintained == '1') { $user_license_maintained = 1; } } else { $user_license_maintained = 0; } } else { $user_license_maintained = ''; } if (array_key_exists('11', $row)) { $user_license_notes = trim($row[11]); } else { $user_license_notes = ''; } if (array_key_exists('12', $row)) { if ($row[12] != '') { $user_license_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12])); } else { $user_license_purchase_date = ''; } } else { $user_license_purchase_date = 0; } // A number was given instead of a name if (is_numeric($user_name)) { $this->comment('User ' . $user_name . ' is not a name - assume this user already exists'); $user_username = ''; // No name was given } elseif ($user_name == '') { $this->comment('No user data provided - skipping user creation, just adding license'); $first_name = ''; $last_name = ''; $user_username = ''; } else { $name = explode(" ", $user_name); $first_name = $name[0]; $email_last_name = ''; $email_prefix = $first_name; if (!array_key_exists(1, $name)) { $last_name = ''; $email_last_name = $last_name; $email_prefix = $first_name; } else { $last_name = str_replace($first_name, '', $user_name); if ($this->option('email_format') == 'filastname') { $email_last_name .= str_replace(' ', '', $last_name); $email_prefix = $first_name[0] . $email_last_name; } elseif ($this->option('email_format') == 'firstname.lastname') { $email_last_name .= str_replace(' ', '', $last_name); $email_prefix = $first_name . '.' . $email_last_name; } elseif ($this->option('email_format') == 'firstname') { $email_last_name .= str_replace(' ', '', $last_name); $email_prefix = $first_name; } } $user_username = $email_prefix; // Generate an email based on their name if no email address is given if ($user_email == '') { if ($first_name == 'Unknown') { $status_id = 7; } $email = strtolower($email_prefix) . '@' . $this->option('domain'); $user_email = str_replace("'", '', $email); } } $this->comment('Full Name: ' . $user_name); $this->comment('First Name: ' . $first_name); $this->comment('Last Name: ' . $last_name); $this->comment('Username: '******'Email: ' . $user_email); $this->comment('License Name: ' . $user_license_name); $this->comment('Serial No: ' . $user_license_serial); $this->comment('Licensed To Name: ' . $user_licensed_to_name); $this->comment('Licensed To Email: ' . $user_licensed_to_email); $this->comment('Seats: ' . $user_license_seats); $this->comment('Reassignable: ' . $user_license_reassignable); $this->comment('Supplier: ' . $user_license_supplier); $this->comment('Maintained: ' . $user_license_maintained); $this->comment('Notes: ' . $user_license_notes); $this->comment('Purchase Date: ' . $user_license_purchase_date); $this->comment('------------- Action Summary ----------------'); if ($user_username != '') { if ($user = User::where('username', $user_username)->whereNotNull('username')->first()) { $this->comment('User ' . $user_username . ' already exists'); } else { $user = new \App\Models\User(); $password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); $user->first_name = $first_name; $user->last_name = $last_name; $user->username = $user_username; $user->email = $user_email; $user->permissions = '{user":1}'; $user->password = bcrypt($password); $user->activated = 1; if ($user->save()) { $this->comment('User ' . $first_name . ' created'); } else { $this->error('ERROR CREATING User ' . $first_name . ' ' . $last_name); $this->error($user->getErrors()); } $this->comment('User ' . $first_name . ' created'); } } else { $user = new User(); $user->user_id = null; } // Check for the supplier match and create it if it doesn't exist if ($supplier = Supplier::where('name', $user_license_supplier)->first()) { $this->comment('Supplier ' . $user_license_supplier . ' already exists'); } else { $supplier = new Supplier(); $supplier->name = e($user_license_supplier); $supplier->user_id = 1; if ($supplier->save()) { $this->comment('Supplier ' . $user_license_supplier . ' was created'); } else { $this->comment('Something went wrong! Supplier ' . $user_license_supplier . ' was NOT created'); } } // Add the license $license = new License(); $license->name = e($user_license_name); if ($user_license_purchase_date != '') { $license->purchase_date = $user_license_purchase_date; } else { $license->purchase_date = null; } $license->serial = e($user_license_serial); $license->seats = e($user_license_seats); $license->supplier_id = $supplier->id; $license->user_id = 1; if ($user_license_purchase_date != '') { $license->purchase_date = $user_license_purchase_date; } else { $license->purchase_date = null; } $license->license_name = $user_licensed_to_name; $license->license_email = $user_licensed_to_email; $license->notes = e($user_license_notes); if ($license->save()) { $this->comment('License ' . $user_license_name . ' with serial number ' . $user_license_serial . ' was created'); $license_seat_created = 0; for ($x = 0; $x < $user_license_seats; $x++) { // Create the license seat entries $license_seat = new LicenseSeat(); $license_seat->license_id = $license->id; // Only assign the first seat to the user if ($x == 0) { $license_seat->assigned_to = $user->id; } else { $license_seat->assigned_to = null; } if ($license_seat->save()) { $license_seat_created++; } } if ($license_seat_created > 0) { $this->comment($license_seat_created . ' seats were created'); } else { $this->comment('Something went wrong! NO seats for ' . $user_license_name . ' were created'); } } else { $this->comment('Something went wrong! License ' . $user_license_name . ' was NOT created'); } $this->comment('====================================='); return true; }); }
public function doRegister() { $affiliate = Affiliate::where('affiliate_key', '=', SELF_HOST_AFFILIATE_KEY)->first(); $license = new License(); $license->first_name = Input::get('first_name'); $license->last_name = Input::get('last_name'); $license->email = Input::get('email'); $license->transaction_reference = Request::getClientIp(); $license->license_key = Utils::generateLicense(); $license->affiliate_id = $affiliate->id; $license->product_id = PRODUCT_SELF_HOST; $license->is_claimed = 1; $license->save(); return ''; }
/** * Validates and stores the license form data submitted from the new * license form. * * @author [A. Gianotto] [<*****@*****.**>] * @see LicensesController::getCreate() method that provides the form view * @since [v1.0] * @return Redirect */ public function postCreate() { // get the POST data $new = Input::all(); // create a new model instance $license = new License(); if (e(Input::get('purchase_cost')) == '') { $license->purchase_cost = null; } else { $license->purchase_cost = e(Input::get('purchase_cost')); } if (e(Input::get('supplier_id')) == '') { $license->supplier_id = null; } else { $license->supplier_id = e(Input::get('supplier_id')); } if (e(Input::get('maintained')) == '') { $license->maintained = 0; } else { $license->maintained = e(Input::get('maintained')); } if (e(Input::get('reassignable')) == '') { $license->reassignable = 0; } else { $license->reassignable = e(Input::get('reassignable')); } if (e(Input::get('purchase_order')) == '') { $license->purchase_order = ''; } else { $license->purchase_order = e(Input::get('purchase_order')); } // Save the license data $license->name = e(Input::get('name')); $license->serial = e(Input::get('serial')); $license->license_email = e(Input::get('license_email')); $license->license_name = e(Input::get('license_name')); $license->notes = e(Input::get('notes')); $license->order_number = e(Input::get('order_number')); $license->seats = e(Input::get('seats')); $license->purchase_date = e(Input::get('purchase_date')); $license->purchase_order = e(Input::get('purchase_order')); $license->depreciation_id = e(Input::get('depreciation_id')); $license->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $license->expiration_date = e(Input::get('expiration_date')); $license->user_id = Auth::user()->id; if ($license->purchase_date == "" || $license->purchase_date == "0000-00-00") { $license->purchase_date = null; } if ($license->expiration_date == "" || $license->expiration_date == "0000-00-00") { $license->expiration_date = null; } if ($license->purchase_cost == "" || $license->purchase_cost == "0.00") { $license->purchase_cost = null; } // Was the license created? if ($license->save()) { $insertedId = $license->id; // Save the license seat data DB::transaction(function () use(&$insertedId, &$license) { for ($x = 0; $x < $license->seats; $x++) { $license_seat = new LicenseSeat(); $license_seat->license_id = $insertedId; $license_seat->user_id = Auth::user()->id; $license_seat->assigned_to = null; $license_seat->notes = null; $license_seat->save(); } }); // Redirect to the new license page return redirect()->to("admin/licenses")->with('success', trans('admin/licenses/message.create.success')); } return redirect()->back()->withInput()->withErrors($license->getErrors()); }
/** * @return \Illuminate\Contracts\View\View */ public function do_license_payment() { $testMode = Session::get('test_mode') === 'true'; $rules = ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'card_number' => 'required', 'expiration_month' => 'required', 'expiration_year' => 'required', 'cvv' => 'required', 'address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal_code' => 'required', 'country_id' => 'required']; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return redirect()->to('license')->withErrors($validator)->withInput(); } $account = $this->accountRepo->getNinjaAccount(); $account->load('account_gateways.gateway'); $accountGateway = $account->getGatewayByType(GATEWAY_TYPE_CREDIT_CARD); try { $affiliate = Affiliate::find(Session::get('affiliate_id')); if ($testMode) { $ref = 'TEST_MODE'; } else { $details = self::getLicensePaymentDetails(Input::all(), $affiliate); $gateway = Omnipay::create($accountGateway->gateway->provider); $gateway->initialize((array) $accountGateway->getConfig()); $response = $gateway->purchase($details)->send(); $ref = $response->getTransactionReference(); if (!$response->isSuccessful() || !$ref) { $this->error('License', $response->getMessage(), $accountGateway); return redirect()->to('license')->withInput(); } } $licenseKey = Utils::generateLicense(); $license = new License(); $license->first_name = Input::get('first_name'); $license->last_name = Input::get('last_name'); $license->email = Input::get('email'); $license->transaction_reference = $ref; $license->license_key = $licenseKey; $license->affiliate_id = Session::get('affiliate_id'); $license->product_id = Session::get('product_id'); $license->save(); $data = ['message' => $affiliate->payment_subtitle, 'license' => $licenseKey, 'hideHeader' => true, 'productId' => $license->product_id, 'price' => $affiliate->price]; $name = "{$license->first_name} {$license->last_name}"; $this->contactMailer->sendLicensePaymentConfirmation($name, $license->email, $affiliate->price, $license->license_key, $license->product_id); if (Session::has('return_url')) { $data['redirectTo'] = Session::get('return_url') . "?license_key={$license->license_key}&product_id=" . Session::get('product_id'); $data['message'] = 'Redirecting to ' . Session::get('return_url'); } return View::make('public.license', $data); } catch (\Exception $e) { $this->error('License-Uncaught', false, $accountGateway, $e); return redirect()->to('license')->withInput(); } }