/** * Render View * * @param int $userId * @param int $planId * @param null|string $inviteCode */ public function subscribe($userId, $planId, $inviteCode = null) { $user = new User($userId); $plan = new Plan($planId); if ($plan->special) { $specialInvite = new Special_invite(); if (!$specialInvite->check($planId, $inviteCode)) { redirect('subscript/plans'); } } //set any errors and display the form $message = strip_tags($this->template->message()); if ($message) { $this->addFlash($message); } $periods = $plan->getPeriods(); $systems = Payment_gateways::findAllActive()->all_to_single_array('name'); $this->template->set('user', $user); $this->template->set('plan', $plan); $this->template->set('periods', $periods); $this->template->set('systems', $systems); $this->template->set('options', $this->config->config['period_qualifier']); $this->template->render(); }
public function register($planId = null, $inviteCode = null) { $password_min = $this->config->item('min_password_length', 'ion_auth'); $password_max = $this->config->item('max_password_length', 'ion_auth'); if ($this->isPaymentEnabled()) { if ($planId == null) { redirect('auth/plans'); } if ($this->isTrialEnabled()) { $plan = new Plan((int) $planId); $specialInvite = new Special_invite(); if ($plan->id == null || $plan->special && !$specialInvite->check($planId, $inviteCode)) { $this->addFlash('Plan id incorrect'); redirect('auth/plans'); } } } //validate form input $this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean'); $this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); $this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $password_min . ']|max_length[' . $password_max . ']|matches[confirm]'); $this->form_validation->set_rules('confirm', 'Confirm Password', 'required'); $this->form_validation->set_rules('terms', 'Terms and Conditions', 'required'); if ($this->form_validation->run() === TRUE) { $first_name = $this->input->post('first_name'); $last_name = $this->input->post('last_name'); $email = $this->input->post('email'); $password = $this->input->post('password'); $username = strtolower($first_name) . ' ' . strtolower($last_name); $additional_data = array('first_name' => $first_name, 'last_name' => $last_name); $registered = $this->ion_auth->register($username, $password, $email, $additional_data); if ($registered) { /* @var Core\Service\Mail\MailSender $sender */ $sender = $this->get('core.mail.sender'); $sender->sendRegistrationMail(array('user' => new User($registered))); if ($this->isPaymentEnabled()) { $user = User::findByEmail($email); if ($this->isTrialEnabled()) { /* @var Core\Service\Subscriber\Subscriber $subscriber */ $subscriber = $this->get('core.subscriber'); $subscriber->setUser($user); $period = $plan->getTrialPeriod(); $interval = new DateInterval('P' . $period->period . ucwords($period->qualifier)); $subscriber->addTrialSubscription($plan, $interval); $this->addFlash('Registered', 'success'); $logged = $this->ion_auth->login($email, $password, true); if ($logged) { redirect('/settings'); } redirect('auth'); } else { redirect('subscript/subscribe/' . $user->id . '/' . $planId . '/' . $inviteCode); } } else { $this->addFlash('Registered', 'success'); $remember = TRUE; $logged = $this->ion_auth->login($email, $password, $remember); if ($logged) { redirect('/dashboard'); } redirect('auth'); } } else { $this->addFlash($this->ion_auth->errors()); } } else { if (validation_errors()) { $this->addFlash(validation_errors()); } } CssJs::getInst()->c_js(); $this->template->set('first_name', $this->form_validation->set_value('first_name')); $this->template->set('last_name', $this->form_validation->set_value('last_name')); $this->template->set('email', $this->form_validation->set_value('email')); $this->template->set('terms', $this->form_validation->set_value('terms')); $this->template->set('planId', $planId); $this->template->set('inviteCode', $inviteCode); $this->template->render(); }