| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/
-$autoload['libraries'] = array('form_validation');
+$autoload['libraries'] = array('form_validation', 'session');
/*
| MUST set an encryption key. See the user guide for info.
|
*/
-$config['encryption_key'] = '';
+$config['encryption_key'] = '328pgYhL6Fc87WC46UHIaaxHBYeutR5u';
/*
|--------------------------------------------------------------------------
| 'sess_time_to_update' = how many seconds between CI refreshing Session Information
|
*/
-$config['sess_cookie_name'] = 'ci_session';
+$config['sess_cookie_name'] = 'p2ptube_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
-$config['sess_table_name'] = 'ci_sessions';
-$config['sess_match_ip'] = FALSE;
+$config['sess_table_name'] = 'sessions';
+$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
|
*/
-
+$hook['pre_controller'][] = array(
+ 'class' => '',
+ 'function' => 'select_language',
+ 'filename' => 'hooks.php',
+ 'filepath' => 'hooks',
+ 'params' => array()
+);
/* End of file hooks.php */
/* Location: ./application/config/hooks.php */
\ No newline at end of file
// ** LOADING VIEWS
// **
$this->load->view('html_begin', $this->html_head_params);
- $this->load->view('header', array('selected_menu' => 'home'));
+ $this->load->view('header', array(
+ 'selected_menu'=> 'home',
+ 'username'=> $this->session->userdata('username')
+ ));
$main_params['content'] = $this->load->view('catalog/index_view', $data, TRUE);
$main_params['side'] = $this->load->view('side_default', NULL, TRUE);
public function test($page = 0)
{
- $params = array( 'title' => 'Test - '. $this->config->item('site_name'),
- //'css' => array(),
- //'js' => array(),
- //'metas' => array('description'=>'','keywords'=>'')
- );
- $this->load->library('html_head_params', $params);
-
- // **
- // ** LOADING VIEWS
- // **
- $this->load->view('html_begin', $this->html_head_params);
- $this->load->view('header', array('selected_menu' => 'home'));
-
- $this->load->view('echo', array('output'=>'Test Page', 'clear'=>TRUE));
-
- $this->load->view('footer');
- $this->load->view('html_end');
+ echo $this->uri->segment(1);
}
public function category($category_name, $ordering = 'hottest', $offset = 0)
* @author Călin-Andrei Burloiu
*/
class User extends CI_Controller {
-
+
+ private $username = NULL;
+ private $email = NULL;
+ private $user_id = NULL;
+
public function __construct()
{
parent::__construct();
-
+
$this->lang->load('user');
}
-
+
public function index()
{
}
-
+
public function login()
- {
+ {
$this->load->library('form_validation');
-
- if ($this->form_validation->run() == FALSE)
+ $this->load->model('users_model');
+
+ $username = $this->input->post('username');
+ $password = $this->input->post('password');
+
+ $form_validation_config = array(
+ array(
+ 'field'=>'username',
+ 'label'=>'lang:user_username_or_email',
+ 'rules'=>'trim|required|min_length[5]|max_length[32]'
+ . '|strtolower|callback__valid_username'
+ . '|callback__do_login[password]'
+ ),
+ array(
+ 'field'=>'password',
+ 'label'=>'lang:user_password',
+ 'rules'=>'required|min_length[5]|max_length[32]'
+ )
+ );
+ $this->form_validation->set_rules($form_validation_config);
+ $this->form_validation->set_error_delimiters('<span class="error">',
+ '</span>');
+
+ if ($this->form_validation->run() === FALSE)
{
$params = array( 'title' => $this->config->item('site_name'),
'css' => array(
'catalog.css'
- ),
- //'js' => array(),
- //'metas' => array('description'=>'')
+ ),
+ //'js' => array(),
+ //'metas' => array('description'=>'')
);
$this->load->library('html_head_params', $params);
-
+
// **
// ** LOADING VIEWS
// **
$this->load->view('html_begin', $this->html_head_params);
$this->load->view('header', array('selected_menu' => 'login'));
-
+
$this->load->view('user/login_view', array());
-
+
$this->load->view('footer');
$this->load->view('html_end');
}
else
{
- header('Location: ' . site_url());
+ if ($this->user_id !== NULL)
+ {
+ $this->session->set_userdata(array(
+ 'user_id'=> $this->user_id,
+ 'username'=> $this->username
+ ));
+ }
+
+ header('Location: '. site_url());
return;
}
}
-
- public function _check_login($username, $password)
+
+ public function _valid_username($username)
+ {
+ $this->load->helper('email');
+
+ if (valid_email($username))
+ return TRUE;
+ else
+ return (preg_match('/^[a-z0-9\._]+$/', $username) == 1);
+ }
+
+ public function _do_login($username, $field_password)
{
+ $password = $this->input->post('password');
+
+ $this->load->model('users_model');
+ $res_login = $this->users_model->login($username, $password);
+
+ // First authentication of a user with LDAP, i.e. the user does not
+ // have an user_id in `users` DB table yet.
+ if ($res_login === TRUE)
+ return TRUE;
+ // Authentication failed
+ else if ($res_login === FALSE)
+ return FALSE;
+
+ // Authentication when the user has an user_id in the DB.
+ $this->username = $res_login['username'];
+ $this->email = $res_login['email'];
+ $this->user_id = $res_login['id'];
+
return TRUE;
}
}
--- /dev/null
+<?php
+
+// TODO delete this if not used
+function select_language()
+{
+ $CI =& get_instance();
+
+ //$config->set_item('language', 'romanian');
+
+ $vars = get_defined_vars();
+ print_r($vars);
+}
+
+/* End of file catalog.php */
+/* Location: ./application/controllers/catalog.php */
--- /dev/null
+<?php
+
+include('system/language/english/form_validation_lang.php');
+
+$lang['_valid_username'] = "You must enter an e-mail address or a valid username.";
+$lang['_do_login'] = "Wrong %s, or wrong %s.";
+
+
+/* End of file form_validation_lang.php */
+/* Location: ./system/language/english/form_validation_lang.php */
\ No newline at end of file
--- /dev/null
+<?php
+
+/**
+ * Class Users_model models user information from DB
+ *
+ * @category Model
+ * @author calinburloiu
+ *
+ */
+class Users_model extends CI_Model {
+ public $db = NULL;
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ if ($this->db === NULL)
+ {
+ $this->load->library('singleton_db');
+ $this->db = $this->singleton_db->connect();
+ }
+ }
+
+ /**
+ * Check authentication credentials. $username can be username or e-mail.
+ *
+ * @param string $username
+ * @param string $password
+ */
+ public function login($username, $password)
+ {
+ $this->load->helper('email');
+
+ // User logs with e-mail address.
+ if (! valid_email($username))
+ $cond_user = "username = '$username'";
+ else
+ $cond_user = "email = '$username'";
+
+ $enc_password = sha1($password);
+
+ // TODO select only required fields.
+ $query = $this->db->query("SELECT * FROM `users`
+ WHERE $cond_user AND password = '$enc_password'");
+
+ if ($query->num_rows() !== 1)
+ return FALSE;
+
+ return $query->row_array();
+ }
+}
+
+/* End of file users_model.php */
+/* Location: ./application/models/users_model.php */
public function __construct()
{
+ parent::__construct();
+
if ($this->db === NULL)
{
$this->load->library('singleton_db');
<?php echo ($selected_menu == 'contact' ? 'class="selected"' : '') ?>><?php echo $this->lang->line('ui_nav_menu_contact') ?>
</a></li>
+ <?php if (isset($username) && $username): ?>
+ <li class="menu-right"><a href="<?php echo '#'//site_url('register') ?>"
+ <?php echo ($selected_menu == 'account' ? 'class="selected"' : '') ?>><?php echo $username ?></a></li>
+ <?php else: ?>
<li class="menu-right"><a href="<?php echo '#'//site_url('register') ?>"
<?php echo ($selected_menu == 'register' ? 'class="selected"' : '') ?>><?php echo $this->lang->line('ui_nav_menu_register') ?></a></li>
<li class="menu-right"><a href="<?php echo site_url('user/login') ?>"
<?php echo ($selected_menu == 'login' ? 'class="selected"' : '') ?>><?php echo $this->lang->line('ui_nav_menu_log_in') ?></a></li>
+ <?php endif; ?>
</ul>
<div id="header">
-<table>
+
+<?php echo form_open('user/login') ?>
+<table class="form">
<tr>
<th><?php echo $this->lang->line('user_username_or_email'). ': ' ?></th>
<td>
- <input type="text" name="username" size="32" />
+ <input type="text" name="username" size="16" value="<?php echo set_value('username') ?>" />
</td>
</tr>
+ <tr>
+ <td></td>
+ <td><?php echo form_error('username') ?></td>
+ </tr>
<tr>
<th><?php echo $this->lang->line('user_password'). ': ' ?></th>
<td>
- <input type="password" name="password" size="32" />
+ <input type="password" name="password" size="16" value="" />
</td>
</tr>
+ <tr>
+ <td></td>
+ <td><?php echo form_error('password') ?></td>
+ </tr>
<tr>
<td></td>
<td>
<input type="submit" value="<?php echo $this->lang->line('ui_nav_menu_log_in') ?>" />
</td>
</tr>
-</table>
\ No newline at end of file
+</table>
+</form>
\ No newline at end of file
margin-bottom: 8px;
}
+table.form th
+{
+ text-align: right;
+}
+
+.error
+{
+ color: red;
+ font-weight:bold;
+}
+
.inline
{
vertical-align: middle;