/** * check if post is cross-site (like login, register, password retrieval) * * @return void */ public function check_post() { $this->load->helper('form'); $this->load->library('form_validation'); if ($this->is_post()) { $this->form_validation->set_error_delimiters('', ''); switch ($this->input->post('form_name')) { case 'login': $this->form_validation->set_rules('login_email', lang('app_email'), 'required|valid_email'); $this->form_validation->set_rules('login_password', lang('app_password'), 'required'); $current_user = false; if ($this->form_validation->run() !== false) { $email = $this->input->post('login_email'); $password = $this->input->post('login_password'); if ($current_user = $this->login($email, $password)) { if (isset($_GET['from']) && ($redirect = $_GET['from'])) { redirect($redirect); } } } if (!$current_user) { $this->set_data('open_modal', 'login'); } break; case 'register': $this->form_validation->set_rules('register_email', lang('app_email'), 'required|valid_email'); $this->form_validation->set_rules('register_password', lang('app_password'), 'required|min_length[5]|max_length[15]'); $this->form_validation->set_rules('confirm_password', lang('app_confirm_password'), 'required|matches[register_password]'); if ($this->form_validation->run() !== false) { $email = $this->input->post('register_email'); $password = $this->input->post('register_password'); // check if email already exists $this->load->model('User_model'); if ($this->User_model->email_exists($email)) { $this->errors[] = sprintf(lang('app_register_email_exists_error'), $email); $this->set_data('open_modal', 'register'); } else { $current_user = $this->register($email, $password); if ($current_user) { $this->load->helper('email'); email_user_confirmation($current_user); admin_report("New user: {$email}", "Check his profil: " . $current_user->get_url()); redirect(site_url('user/settings')); } else { $this->errors[] = sprintf(lang('app_register_error'), $email); $this->set_data('open_modal', 'register'); } } } else { $this->set_data('open_modal', 'register'); } break; case 'password': $this->form_validation->set_rules('password_email', lang('app_email'), 'required|valid_email'); if ($this->form_validation->run() !== false) { $email = $this->input->post('password_email'); if ($this->retrieve_password($email)) { $this->messages[] = sprintf(lang('app_retrieve_password_success'), $email); } else { $this->errors[] = sprintf(lang('app_retrieve_password_error'), $email); } } else { $this->set_data('open_modal', 'password'); } break; case 'new_activity': if (!$this->save_activity()) { $this->set_data('open_modal', 'newActivity'); } break; case 'apply': $this->form_validation->set_rules('comment', lang('app_apply_comment'), 'max_length[1000]'); if ($this->form_validation->run() !== false) { $this->apply(); } else { $this->set_data('open_modal', 'apply'); } break; } } }
/** * check if post is cross-site (like login, register, password retrieval) * * @return void */ public function check_post() { $this->load->helper('form'); $this->load->library('form_validation'); if ($this->is_post()) { $this->form_validation->set_error_delimiters('', ''); switch ($this->input->post('form_name')) { case 'login': $this->form_validation->set_rules('login_email', lang('app_email'), 'required|valid_email'); $this->form_validation->set_rules('login_password', lang('app_password'), 'required'); $current_user = false; if ($this->form_validation->run() == false) { return $this->set_data('open_modal', 'login'); } $email = $this->input->post('login_email'); $password = $this->input->post('login_password'); if (!($current_user = $this->get_user($email, $password))) { return $this->set_data('open_modal', 'login'); } if (!$current_user->is_active()) { $this->errors[] = 'Seu usuário ainda não foi confirmado. Por favor acesse o link enviado ao seu e-mail para continuar o cadastro.'; return; } $this->set_currentuser($current_user); //user ok if (isset($_GET['from']) && ($redirect = $_GET['from'])) { return redirect($redirect); } break; case 'register': $this->form_validation->set_rules('register_email', lang('app_email'), 'required|valid_email'); $this->form_validation->set_rules('register_password', lang('app_password'), 'required|min_length[5]|max_length[15]'); $this->form_validation->set_rules('confirm_password', lang('app_confirm_password'), 'required|matches[register_password]'); if ($this->form_validation->run() !== false) { $email = $this->input->post('register_email'); $password = $this->input->post('register_password'); // check if email already exists $this->load->model('User_model'); if ($this->User_model->email_exists($email)) { $this->errors[] = sprintf(lang('app_register_email_exists_error'), $email); $this->set_data('open_modal', 'register'); } else { $current_user = $this->register($email, $password); if ($current_user) { $this->load->helper('email'); email_user_confirmation($current_user); admin_report("New user: {$email}", "Check his profil: " . $current_user->get_url()); $this->session->set_flashdata('messages', ['Favor verifique seu e-mail para continuar o cadastro']); redirect(site_url('/')); } else { $this->errors[] = sprintf(lang('app_register_error'), $email); $this->set_data('open_modal', 'register'); } } } else { $this->set_data('open_modal', 'register'); } break; case 'password': $this->form_validation->set_rules('password_email', lang('app_email'), 'required|valid_email'); if ($this->form_validation->run() !== false) { $email = $this->input->post('password_email'); if ($this->retrieve_password($email)) { $this->messages[] = sprintf(lang('app_retrieve_password_success'), $email); } else { $this->errors[] = sprintf(lang('app_retrieve_password_error'), $email); } } else { $this->set_data('open_modal', 'password'); } break; case 'new_activity': if (!$this->save_activity()) { $this->set_data('open_modal', 'newActivity'); } break; case 'apply': $this->form_validation->set_rules('comment', lang('app_apply_comment'), 'max_length[1000]'); if ($this->form_validation->run() !== false) { $this->apply(); } else { $this->set_data('open_modal', 'apply'); } break; } } }