/** * Complete registration with invite */ public function invite($code = null) { $this->load->config('manage_users'); $timelimit = time() - $this->config->config['invite_timelimit']; $user = new User(); if ($post = $this->input->post()) { $password_min = $this->config->item('min_password_length', 'ion_auth'); $password_max = $this->config->item('max_password_length', 'ion_auth'); $this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $password_min . ']|max_length[' . $password_max . ']|matches[confirm]'); if ($this->form_validation->run() === TRUE) { $user->getInviteUser($post['code'], $timelimit); if (!$user->exists()) { $this->addFlash('Params of your invitation are not valid'); redirect('auth'); } $ion_auth = new Ion_auth_model(); $result = $ion_auth->registerByInvite(array('id' => $user->id, 'password' => $post['password'])); if ($result) { $email = $user->email; $sender = $this->get('core.mail.sender'); $sender->sendRegistrationMail(array('user' => $user)); $this->addFlash('Registered', 'success'); $remember = TRUE; $logged = $this->ion_auth->login($email, $post['password'], $remember); if ($logged) { redirect('/dashboard'); } redirect('auth'); } else { redirect('auth'); } } else { if (validation_errors()) { $this->addFlash(validation_errors()); } $this->template->set('code', $post['code']); $this->template->render(); } } else { if ($code) { $user->getInviteUser($code, $timelimit); if (!$user->exists()) { $this->addFlash('Your inviting link is not valid'); redirect('auth'); } $newCode = $this->ion_auth->createInviteCode(); $user->invite_code = md5($newCode); if ($user->save()) { $this->template->set('code', $newCode); } $this->template->render(); } else { redirect('auth'); } } }