Skip to content

Commit c60f3b2

Browse files
committed
implemented session management against imap and database PART1
* simply use imap from php, against a specific domain, you can filter the app by ip so it's safe, the levels of gmail-style security and yahoo are illogical in most controlled cases * the model checks in the DB and in the IMAP, if both are successful allows entry to the system, if the DB fails it should only allow to see the withholding vouchers, this is for now simpler and just check for both are valid * parent controller assigns all variables to respective objects after corroborating the credentials and user data
1 parent d34f656 commit c60f3b2

File tree

5 files changed

+1811
-14
lines changed

5 files changed

+1811
-14
lines changed

cweb/elcurrencyweb/controllers/Index.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class Index extends CP_Controller {
1818
function __construct()
1919
{
2020
parent::__construct();
21-
$this->load->helper(array('form', 'url','html'));
22-
$this->output->enable_profiler(ENVIRONMENT !== 'production');
23-
21+
$this->data = $data;
2422
}
2523

2624
/**
@@ -32,7 +30,7 @@ function __construct()
3230
*/
3331
public function index()
3432
{
35-
$data = array();
33+
$data = $this->data;
3634
$data['currentctr'] = $this->currentctr;
3735
$data['currentinx'] = $this->currentinx;
3836
$data['currenturl'] = $this->currenturl;
@@ -41,6 +39,45 @@ public function index()
4139
$this->load->view('footer',$data);
4240
}
4341

42+
/**
43+
* index que muestra vista con instrucciones, las instrucciones estan en la vista indexinput
44+
* esta vista revisa si es sesion activa y la muestra, sino redirige a login.
45+
*
46+
* @name: vistainicio
47+
* @param void
48+
* @return void
49+
*/
50+
public function vistainterna()
51+
{
52+
$this->checksession();
53+
$data = $this->data;
54+
$data['currentctr'] = $this->currentctr;
55+
$data['currentinx'] = $this->currentinx;
56+
$data['currenturl'] = $this->currenturl;
57+
$this->load->view('header',$data);
58+
$this->load->view('vista_home',$data);
59+
$this->load->view('footer',$data);
60+
}
61+
62+
/**
63+
* vistasalida que muestra vista con instrucciones, las instrucciones estan en la vista indexinput
64+
* esta vista es publica por defecto, y no necesita revisarse por sesion activa
65+
*
66+
* @name: vistasalida
67+
* @param void
68+
* @return void
69+
*/
70+
public function vistapublica()
71+
{
72+
$data = $this->data;
73+
$data['currentctr'] = $this->currentctr;
74+
$data['currentinx'] = $this->currentinx;
75+
$data['currenturl'] = $this->currenturl;
76+
$this->load->view('header',$data);
77+
$this->load->view('vista_publica',$data);
78+
$this->load->view('footer',$data);
79+
}
80+
4481
}
4582

4683
/* End of file Index.php */
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2+
3+
4+
class Indexauth extends YA_Controller {
5+
6+
function __construct()
7+
{
8+
parent::__construct();
9+
$data['menu'] = $this->genmenu();
10+
$data['menusub'] = '';
11+
$this->data = $data;
12+
}
13+
14+
/**
15+
* index que muestra login para autenticacion, y verifica esta contra el modelo de datos
16+
* este controlador no necesita verirficar la session ya que este solo muestra si entra o no
17+
*
18+
* @name: index
19+
* @param void
20+
* @return void
21+
*/
22+
public function index($data = NULL)
23+
{
24+
$message = 'Auth system prepared';
25+
26+
if(is_array($data))
27+
{
28+
array_merge($this->data,$data);
29+
}
30+
else
31+
{
32+
if($data == 'autherror')
33+
$message = 'Error login or invalid credentials';
34+
if($data == 'authcheck')
35+
$message = 'Invalid access or invalid credentials';
36+
if($data == 'logout')
37+
$message = 'Session closed';
38+
if($data == 'logauth')
39+
$message = 'Auth prepared to valid credentials';
40+
$data = $this->data;
41+
}
42+
43+
$this->config->load('imap');
44+
$data['sitename'] = $this->config->item('imap_host');
45+
46+
$data['message'] = $message;
47+
$this->load->view('header.php',$data);
48+
$this->load->view('inicion.php',$data);
49+
$this->load->view('footer.php',$data);
50+
}
51+
52+
public function auth($action = 'logout', $username = NULL, $userclave = NULL)
53+
{
54+
$typeerror = 'logout';
55+
56+
if($username == NULL)
57+
$username = $this->input->post('username');
58+
if($userclave == NULL)
59+
$userclave = $this->input->post('userclave');
60+
61+
if ( $action == 'login' )
62+
{
63+
$this->load->model('authmodel');
64+
$im_access = $this->authmodel->authimap($username, $userclave);
65+
$rs_access = $this->authmodel->authtable($username, $userclave);
66+
if($im_access == FALSE)
67+
$typeerror = 'autherror';
68+
if($rs_access == FALSE)
69+
$typeerror = 'authcheck';
70+
}
71+
72+
if ( $action == 'logauth' )
73+
$typeerror = 'logauth';
74+
75+
$data = array();
76+
if($rs_access AND $im_access)
77+
{
78+
$this->session->set_userdata('userdata', $rs_access);
79+
redirect('Index/vistainterna');
80+
}
81+
else
82+
{
83+
$this->session->sess_destroy(); sleep(3);
84+
header('location:'.site_url('/Indexauth/index/'.$typeerror));
85+
}
86+
}
87+
88+
}
89+
90+
/* End of file Indexauth.php */
91+
/* Location: ./application/controllers/Indexauth.php */

cweb/elcurrencyweb/core/CP_Controller.php

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ class CP_Controller extends CI_Controller
2525
public $permite = FALSE;
2626
/** nombre de usuario tomado de la session activa */
2727
public $username = FALSE;
28+
/** correos de usuario tomado de la session activa */
29+
public $usermails = FALSE;
30+
/** estado de usuario tomado de la session activa */
31+
public $userstatus = 'INACTIVO';
2832
/** mecanismo barato para ver el controller que se denego desde la herencia*/
2933
public $modulo = NULL;
34+
/** objeto session del usuario */
35+
private $sessobj = NULL;
3036

3137
/**
3238
* establece librerias de sesion y permisos asi como modulo si se especifica
@@ -65,19 +71,39 @@ public function __construct($modulo = NULL)
6571
}
6672

6773
/** revision de session, si invalidad redirige a login */
68-
public function checku()
74+
public function checksession()
6975
{
7076
$this->userurl = $this->input->get_post('userurl');
7177
$this->currenturl = $this->uri->uri_string(); //$this->uri->segment(1).'/'.$this->uri->segment(2).'/'.$this->uri->segment(3).'/'.$this->uri->segment(4);
78+
$this->sessobj = $this->session->userdata('userdata');
7279

7380
$userurl = str_replace('/','',$this->userurl);
7481
$redirurl = $this->currenturl;
7582
if( $userurl != '')
7683
$redirurl = $this->userurl;
7784

78-
//$username = $_SESSION['username'];
85+
if($this->sessobj == NULL)
86+
{
87+
redirect('Indexauth/auth/login?userurl='.$redirurl,'location');
88+
return;
89+
}
90+
$this->datasession();
91+
}
7992

80-
//$this->username = $username;
93+
/** datos de session, si invalido genera invalidez */
94+
public function datasession()
95+
{
96+
$userdata = $this->sessobj;
97+
if( is_array($userdata) )
98+
{
99+
foreach($userdata as $variable => $varvalue)
100+
{
101+
if( $variable == 'userkey' )
102+
continue;
103+
if( array_key_exists($variable, $userdata) )
104+
$this->$variable = $userdata[$variable];
105+
}
106+
}
81107
}
82108

83109
/*
@@ -95,9 +121,16 @@ public function genmenu($modulename = NULL, $menuclasscss = NULL)
95121
$arraymodules = $this->arraymurls;
96122
$arraycontrls = $this->getcontrollers($modulename);
97123

98-
$user_loged = $this->session->userdata('username');
99-
$user_email = $this->session->userdata('useraddress');
124+
$user_loged = FALSE;
125+
$userdata = $this->sessobj;
126+
127+
log_message('info','entrando objeto session '.print_r($userdata,TRUE));
100128

129+
if( is_array($userdata) )
130+
{
131+
if( array_key_exists('username', $userdata) )
132+
$user_loged = $userdata['username'] OR FALSE;
133+
}
101134
$menumainstring = '';
102135

103136
if(($modulename == NULL OR $modulename == FALSE) AND $currentinx !== '')
@@ -106,14 +139,14 @@ public function genmenu($modulename = NULL, $menuclasscss = NULL)
106139
$menuclasssubdi = '';
107140
$menumainstring = '';
108141

109-
/* if( $user_email == NULL OR $user_loged == FALSE )
142+
if( $user_loged == FALSE )
110143
{
111144
$menumainstring .= '</div>';
112145
return $menumainstring;
113146
}
114147
else
115-
*/ {
116-
// $menumainstring .= ' '.anchor('/',ucfirst(SYSDIR),'class="active" ');
148+
{
149+
$menumainstring .= ' '.anchor('/',ucfirst(SYSDIR),'class="active" ');
117150
$menumainstring .= anchor('',' ');
118151
$modulename = $arraymodules[0];
119152
foreach($arraycontrls as $menuidex=>$menulink)
@@ -137,8 +170,11 @@ public function genmenu($modulename = NULL, $menuclasscss = NULL)
137170
$menumainstring .= ' '.anchor($menulink,ucfirst($menuname),'class=" '.$menuitemactive.' " ');
138171
}
139172
}
140-
// $menumainstring .= ' '.anchor('indexlogin/salirlogin','Salir','class="" ');
141-
}
173+
if( $user_loged == FALSE )
174+
$menumainstring .= ' '.anchor('/Indexauth/auth/logauth','Inicio','class="active" ');
175+
else
176+
$menumainstring .= ' '.anchor('/Indexauth/auth/logout','Logout','class="active" ');
177+
}
142178
}
143179
else
144180
{

0 commit comments

Comments
 (0)