Skip to content
This repository has been archived by the owner on Nov 27, 2017. It is now read-only.

Commit

Permalink
username is now the identity and sme bugfixes with activating the acc…
Browse files Browse the repository at this point in the history
…ount and ion_aut model
  • Loading branch information
emad-elsaid committed Apr 16, 2011
1 parent ca22f6a commit 23e1d6c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 87 deletions.
12 changes: 6 additions & 6 deletions application/config/ion_auth.php
Expand Up @@ -54,13 +54,13 @@
* Columns in your meta table,
* id not required.
**/
$config['columns'] = array('first_name', 'last_name', 'company', 'phone');
$config['columns'] = array('first_name', 'last_name');

/**
* A database column which is used to
* login with.
**/
$config['identity'] = 'email';
$config['identity'] = 'username';

/**
* Minimum Required Length of Password
Expand Down Expand Up @@ -138,22 +138,22 @@
/**
* Message Start Delimiter
**/
$config['message_start_delimiter'] = '<p>';
$config['message_start_delimiter'] = '<div class="info">';

/**
* Message End Delimiter
**/
$config['message_end_delimiter'] = '</p>';
$config['message_end_delimiter'] = '</div>';

/**
* Error Start Delimiter
**/
$config['error_start_delimiter'] = '<p>';
$config['error_start_delimiter'] = '<div class="error">';

/**
* Error End Delimiter
**/
$config['error_end_delimiter'] = '</p>';
$config['error_end_delimiter'] = '</div>';

/* End of file ion_auth.php */
/* Location: ./system/application/config/ion_auth.php */
30 changes: 17 additions & 13 deletions application/controllers/auth.php
Expand Up @@ -24,17 +24,15 @@ public function index(){
//log the user in
public function login(){

$this->data['title'] = lang('system_login');

//validate form input
$this->form_validation->set_rules('email', lang('system_email'), 'required|valid_email');
$this->form_validation->set_rules('username', lang('system_email'), 'required');
$this->form_validation->set_rules('password', lang('system_password'), 'required');

if ($this->form_validation->run() == true){ //check to see if the user is logging in
//check for "remember me"
$remember = (bool) $this->input->post('remember');

if ($this->ion_auth->login($this->input->post('email'), $this->input->post('password'), $remember)){ //if the login is successful
if ($this->ion_auth->login($this->input->post('username'), $this->input->post('password'), $remember)){ //if the login is successful
//redirect them back to the home page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect($this->config->item('base_url'), 'refresh');
Expand All @@ -47,10 +45,10 @@ public function login(){
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

$this->data['email'] = array('name' => 'email',
'id' => 'email',
$this->data['username'] = array('name' => 'username',
'id' => 'username',
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
'value' => $this->form_validation->set_value('username'),
);
$this->data['password'] = array('name' => 'password',
'id' => 'password',
Expand All @@ -64,11 +62,10 @@ public function login(){
//log the user out
public function logout(){

$this->data['title'] = lang('system_logout');
//log the user out
$logout = $this->ion_auth->logout();
//redirect them back to the page they came from
redirect('auth', 'refresh');
redirect('auth/login', 'refresh');

}

Expand Down Expand Up @@ -172,7 +169,7 @@ public function activate($id, $code=false){
if ($activation){
//redirect them to the auth page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth", 'refresh');
redirect("auth/login", 'refresh');
}else{
//redirect them to the forgot password page
$this->session->set_flashdata('message', $this->ion_auth->errors());
Expand All @@ -188,12 +185,13 @@ public function create_user(){
//validate form input
$this->form_validation->set_rules('first_name', lang('system_first_name'), 'required|xss_clean');
$this->form_validation->set_rules('last_name', lang('system_last_name'), 'required|xss_clean');
$this->form_validation->set_rules('username', lang('system_username'), 'trim|required|min_length[5]|max_length[15]|xss_clean');
$this->form_validation->set_rules('email', lang('system_email'), 'required|valid_email');
$this->form_validation->set_rules('password', lang('system_password'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', lang('system_password_conf'), 'required');

if ($this->form_validation->run() == true){
$username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name'));
$username = $this->input->post('username');
$email = $this->input->post('email');
$password = $this->input->post('password');

Expand All @@ -203,10 +201,11 @@ public function create_user(){
);
}

if ($this->form_validation->run() == true && $this->ion_auth->register($username, $password, $email, $additional_data)){ //check to see if we are creating the user
if ($this->form_validation->run() == true
&& $this->ion_auth->register($username, $password, $email, $additional_data)){
//redirect them back to the admin page
$this->session->set_flashdata('message', "User Created");
redirect("auth", 'refresh');
redirect("auth/login", 'refresh');
}else{ //display the create user form
//set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
Expand All @@ -226,6 +225,11 @@ public function create_user(){
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
);
$this->data['username'] = array('name' => 'username',
'id' => 'username',
'type' => 'text',
'value' => $this->form_validation->set_value('username'),
);
$this->data['password'] = array('name' => 'password',
'id' => 'password',
'type' => 'password',
Expand Down
62 changes: 3 additions & 59 deletions application/controllers/users_editor.php
Expand Up @@ -24,8 +24,7 @@ public function __construct(){
$this->pages = array(
'index'=>lang('system_active_users'),
'inactive'=>lang('system_inactive_users'),
'newGroup'=>lang('system_new_group'),
'newUser'=>lang('system_new_user')
'newGroup'=>lang('system_new_group')
);

$this->load->library('gui');
Expand Down Expand Up @@ -220,61 +219,6 @@ public function deleteGroup($id){

}

/**
* create new user page, and it has one form
* with needed data
* and it has already the action itself,
* that is copied from ion-auth Auth controller
*/
public function newUser(){

$this->load->library('form_validation');
//validate form input
$this->form_validation->set_rules('first_name', lang('system_first_name'), 'required|xss_clean');
$this->form_validation->set_rules('last_name', lang('system_last_name'), 'required|xss_clean');
$this->form_validation->set_rules('email', lang('system_email'), 'required|valid_email');
$this->form_validation->set_rules('password', lang('system_password'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', lang('system_password_conf'), 'required');

if ($this->form_validation->run() == true)
{
$username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name'));
$email = $this->input->post('email');
$password = $this->input->post('password');

$additional_data = array('first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name')
);
}
if ($this->form_validation->run() == true
&& $this->ion_auth->register($username, $password, $email, $additional_data,$this->input->post('group')))
{ //check to see if we are creating the user
//redirect them back to the admin page
$this->session->set_flashdata('message', lang('system_user_created'));
redirect("users_editor");
}else{ //display the create user form
//set the flash data error message if there is one
$groups = new Group();
$groups->get();
$groups_array = array();
foreach( $groups as $group )
$groups_array[$group->name] = $group->name;

$this->print_text(
$this->gui->form('users_editor/newUser',
array(
' ' => (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message'))),
lang('system_group_label') => $this->gui->dropdown('group','',$groups_array),
lang('system_first_name').'*' => $this->gui->textbox('first_name',$this->form_validation->set_value('first_name')),
lang('system_last_name').'*' => $this->gui->textbox('last_name',$this->form_validation->set_value('last_name')),
lang('system_email').'*' => $this->gui->textbox( 'email', $this->form_validation->set_value('email')),
lang('system_password').'*' => $this->gui->password( 'password', $this->form_validation->set_value('password')),
lang('system_password_conf').'*' => $this->gui->password( 'password_confirm', $this->form_validation->set_value('password_confirm')),
'' => $this->gui->button('submit',lang('system_create_user'), array('type'=>'submit'))
)));
}
}

/**
* edit user information
*
Expand All @@ -289,7 +233,7 @@ public function editUser($id){
$groups_array[$group->id] = $group->name;

$user = $this->ion_auth->get_user($id);
$this->print_text(
$this->print_text( '<p>'.
$this->gui->form('users_editor/editUserAction',
array(
lang('system_group_label') => $this->gui->dropdown('group',$user->group_id,$groups_array),
Expand All @@ -311,7 +255,7 @@ public function editUser($id){
anchor('users_editor/deleteUser/'.$id,lang('system_delete_user'))
),'',
array('id'=>$user->id)
)
) .'</p>'
);

}
Expand Down
2 changes: 1 addition & 1 deletion application/models/ion_auth_model.php
Expand Up @@ -458,7 +458,7 @@ public function profile($identity = '', $is_code = false)
**/
public function register($username, $password, $email, $additional_data = false, $group_name = false)
{
if ($this->identity_column == 'email' && $this->email_check($email))
if ( $this->email_check($email) )
{
$this->ion_auth->set_error('account_creation_duplicate_email');
return FALSE;
Expand Down
4 changes: 4 additions & 0 deletions application/views/auth/create_user.php
Expand Up @@ -68,6 +68,10 @@
<p><?=lang('system_email')?><br />
<?php echo form_input($email);?>
</p>

<p><?=lang('system_username')?><br />
<?php echo form_input($username);?>
</p>

<p><?=lang('system_password')?><br />
<?php echo form_input($password);?>
Expand Down
13 changes: 6 additions & 7 deletions application/views/auth/login.php
Expand Up @@ -9,7 +9,7 @@
<html>
<head>
<?=theme_head()?>
<style>
<style type="text/css" >
body{
font-size: 12px;
}
Expand All @@ -32,16 +32,15 @@
padding:3px;
width:97%;
border-color:#DFDFDF;
font-family: \"Lucida Grande\",Verdana,Arial,\"Bitstream Vera Sans\",sans-serif;
font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;

font-size-adjust:none;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:normal
}
</style>
<script language="javascript" >
<script type="text/javascript">
dojo.addOnLoad( null, function(){
dijit.byId( 'loginD' ).show();
});
Expand All @@ -54,15 +53,15 @@
<div class='mainInfo'>

<div class="pageTitleBorder"></div>
<center><img src="<?= base_url() ?>assets/admin/logo.png" align="center" ></center>
<center><img alt="" src="<?= base_url() ?>assets/admin/logo.png" align="center" ></center>
<p><?=lang('system_please_login')?></p>

<div id="infoMessage"><?php echo $message;?></div>

<?php echo form_open("auth/login");?>
<p>
<label for="email"><?=lang('system_email')?></label>
<?php echo form_input($email);?>
<label for="email"><?=lang('system_username')?></label>
<?php echo form_input($username);?>
</p>
<p>
<label for="password"><?=lang('system_password')?></label>
Expand Down
2 changes: 1 addition & 1 deletion mysql.sql
Expand Up @@ -78,7 +78,7 @@ CREATE TABLE `users` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `users` (`id`, `group_id`, `ip_address`, `username`, `password`, `salt`, `email`, `activation_code`, `forgotten_password_code`, `remember_code`, `created_on`, `last_login`, `active`) VALUES
(1, 1, '127.0.0.1', 'administrator', '59beecdf7fc966e2f17fd8f65a4a9aeb09d4a3d4', '9462e8eee0', 'admin@admin.com', '', NULL, NULL, 1268889823, 1268889823, 1);
(1, 1, '127.0.0.1', 'admin@admin.com', '59beecdf7fc966e2f17fd8f65a4a9aeb09d4a3d4', '9462e8eee0', 'admin@admin.com', '', NULL, NULL, 1268889823, 1268889823, 1);

CREATE TABLE `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
Expand Down

0 comments on commit 23e1d6c

Please sign in to comment.