fixed logiin redirect
This commit is contained in:
parent
76104ff94e
commit
ac5bc10376
|
@ -2,6 +2,8 @@
|
|||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
//Routes of the forms controller
|
||||
$route['login_redirect/(:num)'] = 'Users/login_redirect/$1';
|
||||
|
||||
$route['create'] = 'Forms/create';
|
||||
$route['my_forms'] = 'Forms/my_forms';
|
||||
$route['my_drafts'] = 'Forms/my_drafts';
|
||||
|
@ -15,6 +17,7 @@ $route['responses/index/(:num)'] = 'Responses/index/$1';
|
|||
|
||||
|
||||
|
||||
|
||||
//Routes of the pages controller
|
||||
$route['hero'] = 'Pages/hero';
|
||||
$route['default_controller'] = 'Pages/view';
|
||||
|
|
|
@ -28,46 +28,51 @@
|
|||
}
|
||||
|
||||
// Log in user
|
||||
public function login(){
|
||||
public function login($form_id = null) {
|
||||
$data['title'] = 'Sign In';
|
||||
|
||||
$data['form_id'] = $form_id;
|
||||
|
||||
$this->form_validation->set_rules('username', 'Username', '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('users/login', $data);
|
||||
$this->load->view('templates/footer');
|
||||
} else {
|
||||
|
||||
// Get username
|
||||
$username = $this->input->post('username');
|
||||
// Get and encrypt the password
|
||||
$password = md5($this->input->post('password'));
|
||||
|
||||
|
||||
// Login user
|
||||
$user_id = $this->user_model->login($username, $password);
|
||||
|
||||
if($user_id){
|
||||
|
||||
if ($user_id) {
|
||||
// Create session
|
||||
$user_data = array(
|
||||
'user_id' => $user_id,
|
||||
'username' => $username,
|
||||
'logged_in' => true
|
||||
);
|
||||
|
||||
|
||||
$this->session->set_userdata($user_data);
|
||||
|
||||
|
||||
// Set message
|
||||
$this->session->set_flashdata('user_loggedin', 'You are now logged in');
|
||||
|
||||
redirect('pages');
|
||||
|
||||
// Redirect to the form response page if form ID is provided
|
||||
if ($form_id) {
|
||||
redirect('forms/respond/' . $form_id);
|
||||
} else {
|
||||
redirect('pages');
|
||||
}
|
||||
} else {
|
||||
// Set message
|
||||
$this->session->set_flashdata('login_failed', 'Login is invalid');
|
||||
|
||||
|
||||
redirect('users/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,6 +113,7 @@
|
|||
// Log in user with redirection
|
||||
public function login_redirect($form_id = null) {
|
||||
$data['title'] = 'Sign In';
|
||||
$data['form_id'] = $form_id;
|
||||
|
||||
$this->form_validation->set_rules('username', 'Username', 'required');
|
||||
$this->form_validation->set_rules('password', 'Password', 'required');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php echo form_open('users/login'); ?>
|
||||
<?php echo form_open('users/login_redirect/' . $form_id); ?>
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1 class="text-center"><?php echo $title; ?></h1>
|
||||
|
|
Loading…
Reference in New Issue