<?php
$config = array(
- 'signin'=> array(
+ 'login'=> array(
array(
'field'=>'username',
'label'=>'lang:user_username_or_email',
'label'=>'lang:user_email',
'rules'=>'trim|required|xss_clean|valid_email|callback__do_resend_activation'
)
+ ),
+ 'recover_password'=> array(
+ array(
+ 'field'=>'username',
+ 'label'=>'lang:user_username',
+ 'rules'=>'trim|required|min_length[5]|max_length[32]'
+ . '|strtolower|callback__valid_username|callback__username_exists|callback__internal_account'
+ . '|callback__do_recover_password'
+ ),
+ array(
+ 'field'=>'email',
+ 'label'=>'lang:user_email',
+ 'rules'=>'trim|required|xss_clean|valid_email'
+ )
)
);
$config['available_languages_list'] = array(
'en'=>'english',
'ro'=>'romanian'
-);
\ No newline at end of file
+);
+
+/*
+|--------------------------------------------------------------------------
+| No-Reply E-mail address
+|--------------------------------------------------------------------------
+|
+| The e-mail address from which the users receive e-mail notifications
+| like account activation e-mail or password recovery.
+|
+*/
+$config['noreply_email'] = 'no-reply@p2p-next.cs.pub.ro';
\ No newline at end of file
--- /dev/null
+<?php
+
+/**
+ * Class Message displays messages (info, error).
+ *
+ * Messages are captured from 'msg' flash session variable.
+ *
+ * @category Controller
+ * @author Călin-Andrei Burloiu
+ */
+class Message extends CI_Controller {
+
+ private $msg;
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->msg = $this->session->flashdata('msg');
+ }
+
+ public function _remap($method, $params = array())
+ {
+ if (! $this->msg)
+ header('Location: '. site_url());
+
+ $params = array(
+ 'title'=> $this->lang->line("message_title_{$method}")
+ .' – '
+ . $this->config->item('site_name'),
+ //'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());
+
+ $main_params['content'] =
+ $this->load->view("message/{$method}_view",
+ array('msg'=> $this->msg), TRUE);
+
+ $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
+ $this->load->view('main', $main_params);
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+}
+
+/* End of file message.php */
+/* Location: ./application/controllers/message.php */
public function index()
{
}
+
+ public function test($user_id = 1)
+ {
+ echo sha1('hQwCUEPQZcN8c4Es');
+ }
/**
* Login a user and then redirect it to the last page which must be encoded
$this->form_validation->set_error_delimiters('<span class="error">',
'</span>');
- if ($this->form_validation->run('signin') === FALSE)
+ if ($this->form_validation->run('login') === FALSE)
{
$params = array( 'title' =>
$this->lang->line('ui_nav_menu_login')
public function activate($user_id, $method='', $activation_code='')
{
- $user_id = intval($user_id);
+ $user_id = intval($user_id);
+ $res_form_validation = FALSE;
+
+ if ($method == 'code')
+ {
+ if (! $activation_code)
+ $res_form_validation = $this->form_validation->run('activate');
+ // Activation code is provided in URL.
+ else
+ {
+ if ($this->_valid_activation_code($activation_code)
+ && $this->users_model->activate_account($user_id,
+ $activation_code))
+ {
+ $this->session->set_flashdata('msg', sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));
+ header('Location: '. site_url('message/info'));
+ return;
+ }
+ else
+ {
+ $this->session->set_flashdata('msg',
+ $this->lang->line('user_msg_wrong_activation_code'));
+ header('Location: '. site_url('message/error'));
+ return;
+ }
+ }
+ }
+ else if ($method == 'resend')
+ {
+ $res_form_validation =
+ $this->form_validation->run('resend_activation');
+ }
+
$userdata = $this->users_model->get_userdata($user_id,
'email, a.activation_code');
$email = $userdata['email'];
- //print_r($userdata['activation_code']);
$activated_account = ($userdata['activation_code'] == NULL);
+ if ($activated_account)
+ {
+ $this->session->set_flashdata('msg', sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));
+ header('Location: '. site_url('message/info'));
+ return;
+ }
+
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<span class="error">',
'</span>');
- $res_form_validation = FALSE;
- if ($method == 'code')
- {
- $res_form_validation = $this->form_validation->run('activate');
- }
- else if ($method == 'resend')
- {
- $res_form_validation =
- $this->form_validation->run('resend_activation');
- }
-
if ($res_form_validation === FALSE)
{
$params = array(
$this->load->view('html_begin', $this->html_head_params);
$this->load->view('header', array());
- if (! $activated_account)
- {
- $main_params['content'] =
- $this->load->view('user/activate_view',
- array('user_id'=> $user_id, 'email'=> $userdata['email']),
- TRUE);
- }
- else
- {
- $main_params['content'] =
- $this->load->view('user/activated_account_view',
- NULL, TRUE);
- }
+ // Show form
+ $main_params['content'] =
+ $this->load->view('user/activate_view',
+ array( 'user_id'=> $user_id,
+ 'email'=> $userdata['email']),
+ TRUE);
$main_params['side'] = $this->load->view('side_default', NULL, TRUE);
$this->load->view('main', $main_params);
{
// Redirect to a message which tells the user that the
// activation was successful.
- header('Location: '. site_url("user/activate/$user_id"));
+ $this->session->set_flashdata('msg', sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));
+ header('Location: '. site_url('message/info'));
+ return;
}
else if ($method == 'resend')
{
- // Redirect to home page
- header('Location: '. site_url());
+ // Redirect to resent message
+ $this->session->set_flashdata('msg', sprintf(
+ $this->lang->line('user_msg_activation_resent'),
+ $this->input->post('email')));
+ header('Location: '. site_url('message/info'));
+ return;
}
}
}
+ public function recover_password()
+ {
+ $this->load->library('form_validation');
+
+ $this->form_validation->set_error_delimiters('<span class="error">',
+ '</span>');
+
+ if ($this->form_validation->run('recover_password') === FALSE)
+ {
+ $params = array( 'title' =>
+ $this->lang->line(
+ 'user_title_password_recovery')
+ .' – '
+ . $this->config->item('site_name'),
+ //'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' =>
+ 'recover_password'));
+
+ $main_params['content'] = $this->load->view(
+ 'user/recover_password_view', array(),
+ TRUE);
+
+ $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
+ $this->load->view('main', $main_params);
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+ else
+ {
+ // Redirect to resent message
+ $this->session->set_flashdata('msg', sprintf(
+ $this->lang->line('user_msg_password_recovery_email_sent'),
+ $this->input->post('username'),
+ $this->input->post('email')));
+ header('Location: '. site_url('message/info'));
+ return;
+ }
+ }
+
public function _update_session_userdata($data)
{
foreach ($data as $key=> $val)
public function _do_resend_activation($email)
{
- return FALSE;
+ $user_id = $this->input->post('user-id');
+ if ($user_id === FALSE)
+ return FALSE;
+ $user_id = intval($user_id);
+
+ $this->users_model->set_userdata($user_id,
+ array('email'=> $email));
+
+ return $this->users_model->send_activation_email($user_id, $email);
+ }
+
+ public function _username_exists($username)
+ {
+ $userdata = $this->users_model->get_userdata($username);
+
+ if (! $userdata)
+ return FALSE;
+
+ return TRUE;
+ }
+
+ public function _internal_account($username)
+ {
+ $userdata = $this->users_model->get_userdata($username, 'auth_src');
+ if (! $userdata)
+ return FALSE;
+
+ if ($userdata['auth_src'] != 'internal')
+ return FALSE;
+
+ return TRUE;
+ }
+
+ public function _do_recover_password($username)
+ {
+ $email = $this->input->post('email');
+ if (! $email)
+ return FALSE;
+
+ return $this->users_model->recover_password($username, $email);
}
}
--- /dev/null
+<?php
+
+class Send_email_exception extends Exception
+{
+
+}
\ No newline at end of file
$lang['_do_activate'] = 'Wrong activation code.';
$lang['_do_resend_activation'] = 'An error occurred while resending your activation e-mail. This is not a permanent error. Please try again later.';
+// Password Recovery
+$lang['_username_exists'] = 'There is no account registered with this username.';
+$lang['_internal_account'] = 'You cannot change the password for this account because authentication is provided by a third-party.';
+$lang['_do_recover_password'] = 'Username and e-mail address are not associated with the same account.';
+
+
/* End of file form_validation_lang.php */
/* Location: ./system/language/english/form_validation_lang.php */
\ No newline at end of file
$lang['user_date_format_hint'] = 'use format YEAR-MONTH-DAY';
$lang['user_country'] = 'Country';
$lang['user_locality'] = 'City / Town';
+$lang['user_picture'] = 'Profile Picture';
$lang['user_ui_lang'] = 'Site Interface Language';
$lang['user_time_zone'] = 'Time Zone';
$lang['user_roles'] = 'Roles';
// Account Activation
$lang['user_title_activation'] = 'Account Activation';
+$lang['user_title_password_recovery'] = 'Password Recovery';
$lang['user_legend_activation'] = 'Activate your account';
$lang['user_instruction_activation'] = 'Shortly after the registration you made you will receive an <em>activation e-mail</em> on your e-mail address you provided. In order to confirm that you are the owner of that e-mail address, follow the link there or enter the <em>activation code</em> also provided in that e-mail in the field below.';
$lang['user_activation_code'] = 'Activation Code';
$lang['user_submit_activate'] = 'Activate Account';
+$lang['user_submit_password_recovery'] = 'Recover Password';
$lang['user_legend_resend_activation'] = 'Resend the activation code';
$lang['user_instruction_resend_activation'] = 'The <em>activation e-mail</em> can take up to a few minutes until it arrives in your inbox, so please be patient. If you entered a wrong e-mail address, you can change it by entering another one in the field below. Pressing <em>Resend</em> will cause us to retransmit you the <em>activation e-mail</em> on the address entered in this field.';
+$lang['user_instruction_password_recovery'] = 'Enter you username and the e-mail address associated with your account and we will send you a new auto-generated password.';
$lang['user_submit_resend_activation'] = 'Resend Activation E-mail';
$lang['user_msg_activated_account'] = 'Your account is active so you can <a href="%s">login</a>. You successfully validated your e-mail address through the <em>activation e-mail</em>.';
+$lang['user_msg_wrong_activation_code'] = 'Wrong account activation code!';
+$lang['user_msg_activation_resent'] = 'Activation e-mail has been resent to %s!';
+$lang['user_msg_password_recovery_email_sent'] = 'An e-mail with a new password for user %s has been sent to %s.';
+$lang['user_link_password_recovery'] = 'Did you forget your password?';
+$lang['user_activation_email_content'] =
+"Hello %s,
+
+Please confirm that you registered a new account on %s (%s) by following the link below:
+
+%s
+
+If the link does not work try to copy it and then paste it into your address bar.
+
+Alternatively you can use the following Activation Code: %s
+
+Thank for registering!
+";
+$lang['user_password_recovery_email_content'] =
+"Hello %s,
+
+You requested a password recovery on %s (%s). Here is your new auto-generated password:
+
+%s
+
+It is recommended to change this password after you log in.
+
+Best regards!
+";
$lang['user_no_videos_uploaded'] = 'The user uploaded no videos.';
--- /dev/null
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+
+/**
+ * An image processing library initially intended for creating thumbnails.
+ *
+ * @category Library
+ * @author Simon Jarvis, Călin-Andrei Burloiu
+ * @copyright 2006 Simon Jarvis, 2011 Călin-Andrei Burloiu
+ */
+
+class Image {
+
+ var $image;
+ var $image_type;
+
+ function load($filename) {
+ $image_info = getimagesize($filename);
+ $this->image_type = $image_info[2];
+ if( $this->image_type == IMAGETYPE_JPEG ) {
+ $this->image = imagecreatefromjpeg($filename);
+ } elseif( $this->image_type == IMAGETYPE_GIF ) {
+ $this->image = imagecreatefromgif($filename);
+ } elseif( $this->image_type == IMAGETYPE_PNG ) {
+ $this->image = imagecreatefrompng($filename);
+ }
+ }
+ function save($filename, $image_type=IMAGETYPE_JPEG, $compression=60, $permissions=null) {
+ if( $image_type == IMAGETYPE_JPEG ) {
+ imagejpeg($this->image,$filename,$compression);
+ } elseif( $image_type == IMAGETYPE_GIF ) {
+ imagegif($this->image,$filename);
+ } elseif( $image_type == IMAGETYPE_PNG ) {
+ imagepng($this->image,$filename);
+ }
+ if( $permissions != null) {
+ chmod($filename,$permissions);
+ }
+ }
+ function output($image_type=IMAGETYPE_JPEG) {
+ if( $image_type == IMAGETYPE_JPEG ) {
+ imagejpeg($this->image);
+ } elseif( $image_type == IMAGETYPE_GIF ) {
+ imagegif($this->image);
+ } elseif( $image_type == IMAGETYPE_PNG ) {
+ imagepng($this->image);
+ }
+ }
+ function saveThumbnail($filename, $width, $height)
+ {
+ $ratio = $this->getWidth() / $this->getHeight();
+ $thumbRatio = $width / $height;
+
+ if($ratio < $thumbRatio)
+ $this->resizeToHeight($height);
+ else
+ $this->resizeToWidth($width);
+
+ $this->save($filename);
+ }
+ function getWidth() {
+ return imagesx($this->image);
+ }
+ function getHeight() {
+ return imagesy($this->image);
+ }
+ function resizeToHeight($height) {
+ $ratio = $height / $this->getHeight();
+ $width = $this->getWidth() * $ratio;
+ $this->resize($width,$height);
+ }
+ function resizeToWidth($width) {
+ $ratio = $width / $this->getWidth();
+ $height = $this->getheight() * $ratio;
+ $this->resize($width,$height);
+ }
+ function scale($scale) {
+ $width = $this->getWidth() * $scale/100;
+ $height = $this->getheight() * $scale/100;
+ $this->resize($width,$height);
+ }
+ function resize($width,$height) {
+ $new_image = imagecreatetruecolor($width, $height);
+ imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
+ $this->image = $new_image;
+ }
+}
+
+
+/* End of file Singleton_db.php */
+/* Location: ./application/libraries/Singleton_db.php */
if ($query === FALSE)
return FALSE;
- // If the registered with internal authentication it needs to activate
+ // If registered with internal authentication it needs to activate
// the account.
- $activation_code = Users_model::gen_activation_code();
+ $activation_code = Users_model::gen_activation_code($data['username']);
$user_id = $this->get_user_id($data['username']);
$query = $this->db->query("INSERT INTO `users_unactivated`
(user_id, activation_code)
VALUES ($user_id, '$activation_code')");
+ $this->send_activation_email($user_id, $data['email'],
+ $activation_code, $data['username']);
// TODO exception on failure
return $query;
return TRUE;
}
+ public function send_activation_email($user_id, $email = NULL,
+ $activation_code = NULL, $username = NULL)
+ {
+ if (!$activation_code || !$email || !$username)
+ {
+ if (!$email)
+ $cols = 'email, ';
+ else
+ $cols = '';
+
+ $userdata = $this->get_userdata($user_id,
+ $cols. "a.activation_code, username");
+ $activation_code =& $userdata['activation_code'];
+
+ if (!$email)
+ $email =& $userdata['email'];
+ $username =& $userdata['username'];
+ }
+
+ if ($activation_code === NULL)
+ return TRUE;
+
+ $subject = '['. $this->config->item('site_name')
+ . '] Account Activation';
+ $activation_url =
+ site_url("user/activate/$user_id/code/$activation_code");
+ $msg = sprintf($this->lang->line('user_activation_email_content'),
+ $username, $this->config->item('site_name'), site_url(),
+ $activation_url, $activation_code);
+ $headers = "From: ". $this->config->item('noreply_email');
+
+ return mail($email, $subject, $msg, $headers);
+ }
+
+ public function recover_password($username, $email)
+ {
+ $userdata = $this->get_userdata($username, 'email, username, id');
+
+ if (strcmp($userdata['email'], $email) !== 0)
+ return FALSE;
+
+ $recovered_password = Users_model::gen_password();
+
+ $this->set_userdata(intval($userdata['id']), array('password'=>
+ $recovered_password));
+
+ $subject = '['. $this->config->item('site_name')
+ . '] Password Recovery';
+ $msg = sprintf($this->lang->line('user_password_recovery_email_content'),
+ $username, $this->config->item('site_name'), site_url(),
+ $recovered_password);
+ $headers = "From: ". $this->config->item('noreply_email');
+
+ mail($email, $subject, $msg, $headers);
+
+ return TRUE;
+ }
+
/**
* Returns data from `users` table. If $user is int it is used as an
* id, if it is string it is used as an username.
* @param int $user_id
* @param array $data key-value pairs with columns and new values to be
* modified
+ * @return boolean returns TRUE on success and FALSE otherwise
*/
public function set_userdata($user_id, $data)
{
return $activation_code;
}
+ public static function gen_password()
+ {
+ $ci =& get_instance();
+ $length = 16;
+ $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.?!_-';
+ $len_chars = strlen($chars);
+ $enc_key = $ci->config->item('encryption_key');
+ $len_enc_key = strlen($enc_key);
+ $password = '';
+
+ for ($p = 0; $p < $length; $p++)
+ {
+ $i = (mt_rand(1, 100) * ord($enc_key[ mt_rand(0, $len_enc_key-1) ]))
+ % $len_chars;
+ $password .= $chars[$i];
+ }
+
+ return $password;
+ }
+
public static function roles_to_string($roles)
{
$ci =& get_instance();
--- /dev/null
+<div class="ui-widget">
+ <div style="padding: 0 .7em;" class="ui-state-error ui-corner-all">
+ <p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span>
+ <?php echo $msg ?></p>
+ </div>
+</div>
\ No newline at end of file
--- /dev/null
+<div class="ui-widget">
+ <div style="padding: 0 .7em;" class="ui-state-highlight ui-corner-all">
+ <p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-info"></span>
+ <?php echo $msg ?></p>
+ </div>
+</div>
\ No newline at end of file
<input type="submit" value="<?php echo $this->lang->line('ui_nav_menu_log_in') ?>" />
</td>
</tr>
+ <tr>
+ <td></td>
+ <td>
+ <p><a href="<?php echo site_url('user/recover_password') ?>"><?php echo $this->lang->line('user_link_password_recovery') ?></a></p>
+ </td>
+ </tr>
</table>
</form>
\ No newline at end of file
--- /dev/null
+<?php echo form_open("user/recover_password") ?>
+<table class="form">
+ <tr>
+ <td></td>
+ <td>
+ <p><?php echo $this->lang->line('user_instruction_password_recovery'); ?></p>
+ </td>
+ </tr>
+ <tr>
+ <th><?php echo $this->lang->line('user_username'). ': ' ?></th>
+ <td>
+ <input type="text" name="username" size="24" 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_email'). ': ' ?></th>
+ <td>
+ <input type="text" name="email" size="24" value="<? echo set_value('email') ?>" />
+ </td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><?php echo form_error('email') ?></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td>
+ <input type="submit" value="<?php echo $this->lang->line('user_submit_password_recovery') ?>" />
+ </td>
+ </tr>
+</table>
+</form>
\ No newline at end of file
<input type="text" name="username" size="16" value="<?php echo _set_value($userdata, 'username') ?>" />
</td>
<?php else: ?>
- <th><?php echo $this->lang->line('user_username'). ': ' ?></th>
+ <th><?php echo $this->lang->line('user_username'). ' : ' ?></th>
<td>
<em><?php echo $userdata['username'] ?></em>
</td>`
</tr>
<tr><td></td><td><?php echo form_error('locality') ?></td></tr>
+ <tr>
+ <th><?php echo $this->lang->line('user_picture'). ' : ' ?></th>
+ <td>
+ <input type="file" name="picture" size="16" />
+ </td>
+ </tr>
+ <tr><td></td><td><?php echo form_error('locality') ?></td></tr>
+
<tr><td></td><td> </td></tr>
<tr>
text-decoration: underline;
}
+.ui-state-highlight a
+{
+ color: rgb(0,90,192) !important;
+}
+
h1
{
margin-top: 8px;