fixed logiin redirect

This commit is contained in:
jostheta 2024-07-23 11:41:42 +05:30
parent 76104ff94e
commit ac5bc10376
3 changed files with 24 additions and 15 deletions

View File

@ -2,6 +2,8 @@
defined('BASEPATH') OR exit('No direct script access allowed'); defined('BASEPATH') OR exit('No direct script access allowed');
//Routes of the forms controller //Routes of the forms controller
$route['login_redirect/(:num)'] = 'Users/login_redirect/$1';
$route['create'] = 'Forms/create'; $route['create'] = 'Forms/create';
$route['my_forms'] = 'Forms/my_forms'; $route['my_forms'] = 'Forms/my_forms';
$route['my_drafts'] = 'Forms/my_drafts'; $route['my_drafts'] = 'Forms/my_drafts';
@ -15,6 +17,7 @@ $route['responses/index/(:num)'] = 'Responses/index/$1';
//Routes of the pages controller //Routes of the pages controller
$route['hero'] = 'Pages/hero'; $route['hero'] = 'Pages/hero';
$route['default_controller'] = 'Pages/view'; $route['default_controller'] = 'Pages/view';

View File

@ -28,18 +28,18 @@
} }
// Log in user // Log in user
public function login(){ public function login($form_id = null) {
$data['title'] = 'Sign In'; $data['title'] = 'Sign In';
$data['form_id'] = $form_id;
$this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run() === FALSE){ if ($this->form_validation->run() === FALSE) {
$this->load->view('templates/header'); $this->load->view('templates/header');
$this->load->view('users/login', $data); $this->load->view('users/login', $data);
$this->load->view('templates/footer'); $this->load->view('templates/footer');
} else { } else {
// Get username // Get username
$username = $this->input->post('username'); $username = $this->input->post('username');
// Get and encrypt the password // Get and encrypt the password
@ -48,7 +48,7 @@
// Login user // Login user
$user_id = $this->user_model->login($username, $password); $user_id = $this->user_model->login($username, $password);
if($user_id){ if ($user_id) {
// Create session // Create session
$user_data = array( $user_data = array(
'user_id' => $user_id, 'user_id' => $user_id,
@ -61,7 +61,12 @@
// Set message // Set message
$this->session->set_flashdata('user_loggedin', 'You are now logged in'); $this->session->set_flashdata('user_loggedin', 'You are now logged in');
// Redirect to the form response page if form ID is provided
if ($form_id) {
redirect('forms/respond/' . $form_id);
} else {
redirect('pages'); redirect('pages');
}
} else { } else {
// Set message // Set message
$this->session->set_flashdata('login_failed', 'Login is invalid'); $this->session->set_flashdata('login_failed', 'Login is invalid');
@ -108,6 +113,7 @@
// Log in user with redirection // Log in user with redirection
public function login_redirect($form_id = null) { public function login_redirect($form_id = null) {
$data['title'] = 'Sign In'; $data['title'] = 'Sign In';
$data['form_id'] = $form_id;
$this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('password', 'Password', 'required');

View File

@ -1,4 +1,4 @@
<?php echo form_open('users/login'); ?> <?php echo form_open('users/login_redirect/' . $form_id); ?>
<div class="row"> <div class="row">
<div class="col-md-4 col-md-offset-4"> <div class="col-md-4 col-md-offset-4">
<h1 class="text-center"><?php echo $title; ?></h1> <h1 class="text-center"><?php echo $title; ?></h1>