-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathuser.php
More file actions
116 lines (98 loc) · 2.72 KB
/
user.php
File metadata and controls
116 lines (98 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
class User extends CI_Controller {
/**
* Check if the user is logged in, if he's not,
* send him to the login page
* @return void
*/
function index()
{
if($this->session->userdata('is_logged_in')){
redirect('admin/products');
}else{
$this->load->view('admin/login');
}
}
/**
* encript the password
* @return mixed
*/
function __encrip_password($password) {
return md5($password);
}
/**
* check the username and the password with the database
* @return void
*/
function validate_credentials()
{
$this->load->model('Users_model');
$user_name = $this->input->post('user_name');
$password = $this->__encrip_password($this->input->post('password'));
$is_valid = $this->Users_model->validate($user_name, $password);
if($is_valid)
{
$data = array(
'user_name' => $user_name,
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('admin/products');
}
else // incorrect username or password
{
$data['message_error'] = TRUE;
$this->load->view('admin/login', $data);
}
}
/**
* The method just loads the signup view
* @return void
*/
function signup()
{
$this->load->view('admin/signup_form');
}
/**
* Create new user and store it in the database
* @return void
*/
function create_member()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('first_name', 'Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');
if($this->form_validation->run() == FALSE)
{
$this->load->view('admin/signup_form');
}
else
{
$this->load->model('Users_model');
if($query = $this->Users_model->create_member())
{
$this->load->view('admin/signup_successful');
}
else
{
$this->load->view('admin/signup_form');
}
}
}
/**
* Destroy the session, and logout the user.
* @return void
*/
function logout()
{
$this->session->sess_destroy();
unset($this->session->userdata);
redirect('admin');
}
}