Skip to content
Snippets Groups Projects
Commit f8b16f4c authored by Jubi Dition's avatar Jubi Dition
Browse files

new controllers

parent 60a066ae
No related branches found
No related tags found
No related merge requests found
......@@ -32,26 +32,22 @@ class Admin extends CI_Controller
$this->form_validation->set_rules('email', 'Email', 'required|max_length[40]|valid_email');
$this->form_validation->set_rules('pwd', 'Password', 'required|max_length[20]|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Adding</strong> failed!"
));
echo $json;
}
else{
} else {
$is_added = $this->contacts_model->add_user($this->input->post('email'), $this->input->post('pwd'));
if($is_added)
{
if ($is_added) {
$message = "<strong>".$this->input->post('email')."</strong> has been added!";
$json = json_encode(array(
'isSuccessful' => TRUE,
'message' => $message
));
echo $json;
}
else{
} else {
$message = "<strong>".$this->input->post('email')."</strong> already exists!";
$json = json_encode(array(
'isSuccessful' => FALSE,
......@@ -77,15 +73,13 @@ class Admin extends CI_Controller
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|max_length[40]|valid_email');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Deletion</strong> failed!"
));
echo $json;
}
else{
} else {
$email = $this->input->post('email');
$this->contacts_model->delete_user($email);
......@@ -115,15 +109,13 @@ class Admin extends CI_Controller
$this->form_validation->set_rules('email', 'Email', 'required|max_length[40]|valid_email');
$this->form_validation->set_rules('pwd', 'Password', 'required|max_length[20]|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Editing</strong> failed!"
));
echo $json;
}
else{
} else {
$this->contacts_model->update_user($this->input->post('email'), $this->input->post('pwd'));
$message = "Editing for <strong>".$this->input->post('email')."</strong> has been done!";
......@@ -141,8 +133,7 @@ class Admin extends CI_Controller
$this->form_validation->set_rules('name', 'Name', 'required|max_length[40]|alpha_name');
if ($this->form_validation->run() == FALSE) {
$this->index();
}
else{
} else {
$contact = $this->contacts_model->get_contact_data(
$this->session->userdata('uid'), $this->input->post('name'));
......@@ -167,19 +158,16 @@ class Admin extends CI_Controller
$this->form_validation->set_rules('curpwd', 'Current Password', 'required|max_length[20]|alpha_numeric');
$this->form_validation->set_rules('newpwd', 'New Password', 'required|max_length[20]|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Changing</strong> failed!"
));
echo $json;
}
else{
} else {
$pwd_valid = $this->contacts_model->validate_admin_password(
$this->session->userdata('admin'), $this->input->post('curpwd'));
if($pwd_valid)
{
if ($pwd_valid) {
$this->contacts_model->update_admin_password(
$this->session->userdata('admin'), $this->input->post('newpwd'));
......@@ -189,8 +177,7 @@ class Admin extends CI_Controller
'message' => $message
));
echo $json;
}
else{
} else {
$message = "<strong>Current Password</strong> is wrong!";
$json = json_encode(array(
'isSuccessful' => FALSE,
......
......@@ -6,8 +6,7 @@ class Adminlogin extends CI_Controller
{
if (!$this->is_logged_in()) {
$this->load->view('admin_login', array('message' => FALSE));
}
else{
} else {
redirect('admin');
}
}
......@@ -17,15 +16,13 @@ class Adminlogin extends CI_Controller
$this->load->library('form_validation');
$this->form_validation->set_rules('admin', 'Admin', 'required|max_length[40]|alpha_numeric');
$this->form_validation->set_rules('pwd', 'Password', 'required|max_length[20]|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
redirect('login/login_failed');
}
else{
} else {
$admin = $this->input->post('admin');
$is_admin = $this->contacts_model->is_admin($admin, $this->input->post('pwd'));
if($is_admin)
{
if ($is_admin) {
$data = array(
'is_logged_in' => FALSE,
'is_admin' => TRUE,
......@@ -33,8 +30,7 @@ class Adminlogin extends CI_Controller
);
$this->session->set_userdata($data);
redirect('admin');
}
else{
} else {
redirect('adminlogin/login_failed');
}
}
......@@ -49,8 +45,7 @@ class Adminlogin extends CI_Controller
{
if (!$this->is_logged_in()) {
redirect('login');
}
else{
} else {
$this->session->set_userdata(array('is_admin' => FALSE));
$this->session->sess_destroy();
$this->load->view('admin_login', array('message' => FALSE));
......
......@@ -15,48 +15,39 @@ class Signup extends CI_Controller
$this->form_validation->set_rules('email2', 'Email2', 'required|max_length[40]|valid_email');
$this->form_validation->set_rules('pwd', 'Password', 'required|max_length[20]|alpha_numeric');
$this->form_validation->set_rules('pwd2', 'Password2', 'required|max_length[20]|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Registration</strong> failed! Incorrect input."
));
echo $json;
}
else
{
} else {
$email = $this->input->post('email');
$pwd = $this->input->post('pwd');
if($email != $this->input->post('email2'))
{
if ($email != $this->input->post('email2')) {
$message = "<strong>Emails</strong> do not match!";
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => $message
));
echo $json;
}
elseif ($pwd != $this->input->post('pwd2'))
{
} elseif ($pwd != $this->input->post('pwd2')) {
$message = "<strong>Passwords</strong> do not match!";
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => $message
));
echo $json;
}
elseif($this->contacts_model->add_user($email, $pwd))
{
} elseif($this->contacts_model->add_user($email, $pwd)) {
$message = "<strong>Registration</strong> successful!";
$json = json_encode(array(
'isSuccessful' => TRUE,
'message' => $message
));
echo $json;
}
else
{
} else {
$message = "<strong>Email</strong> already exists!";
$json = json_encode(array(
'isSuccessful' => FALSE,
......@@ -67,4 +58,4 @@ class Signup extends CI_Controller
}
}//end sign_up
}
/*End of file login.php*/
\ No newline at end of file
/*End of file signup.php*/
......@@ -33,27 +33,23 @@ class Site extends CI_Controller
$this->form_validation->set_rules('email', 'Email', 'required|max_length[40]|valid_email');
$this->form_validation->set_rules('phone', 'Phone', 'required|max_length[15]|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Adding</strong> failed!"
));
echo $json;
}
else{
} else {
$is_added = $this->contacts_model->add_contact($this->input->post('name'), $this->input->post('email'),
$this->input->post('phone'), $this->session->userdata('uid'));
if($is_added)
{
if ($is_added) {
$message = "<strong>".$this->input->post('name')."</strong> has been added!";
$json = json_encode(array(
'isSuccessful' => TRUE,
'message' => $message
));
echo $json;
}
else{
} else {
$message = "<strong>".$this->input->post('name')."</strong> already exists!";
$json = json_encode(array(
'isSuccessful' => FALSE,
......@@ -79,15 +75,13 @@ class Site extends CI_Controller
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required|max_length[40]|alpha_name');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Deletion</strong> failed!"
));
echo $json;
}
else{
} else {
$name = $this->input->post('name');
$this->contacts_model->delete_contact($name, $this->session->userdata('uid'));
......@@ -125,15 +119,13 @@ class Site extends CI_Controller
$this->form_validation->set_rules('email', 'Email', 'required|max_length[40]|valid_email');
$this->form_validation->set_rules('phone', 'Phone', 'required|max_length[15]|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Editing</strong> failed!"
));
echo $json;
}
else{
} else {
$this->contacts_model->update_contact($this->input->post('name'), $this->input->post('email'),
$this->input->post('phone'), $this->session->userdata('uid'));
......@@ -156,8 +148,7 @@ class Site extends CI_Controller
'message' => "No <strong>Data</strong> for contact!"
));
echo $json;
}
else{
} else {
$contact = $this->contacts_model->get_contact_data(
$this->session->userdata('uid'), $this->input->post('name'));
if (count($contact) == 0) {
......@@ -166,8 +157,7 @@ class Site extends CI_Controller
'message' => "No <strong>Data</strong> for contact!"
));
echo $json;
}
else{
} else {
$json = json_encode(array(
'isSuccessful' => TRUE,
'email' => $contact['email'],
......@@ -190,21 +180,18 @@ class Site extends CI_Controller
$this->form_validation->set_rules('curpwd', 'Current Password', 'required|max_length[20]|alpha_numeric');
$this->form_validation->set_rules('newpwd', 'New Password', 'required|max_length[20]|alpha_numeric');
if ($this->form_validation->run() == FALSE)
{
if ($this->form_validation->run() == FALSE) {
$json = json_encode(array(
'isSuccessful' => FALSE,
'message' => "<strong>Changing</strong> failed!"
));
echo $json;
}
else{
$pwd_valid = $this->contacts_model->validate_password($this->session->userdata('uid'),
$this->input->post('curpwd'));
if($pwd_valid)
{
$this->contacts_model->update_password($this->session->userdata('uid'),
$this->input->post('newpwd'));
} else {
$pwd_valid = $this->contacts_model->validate_password(
$this->session->userdata('uid'), $this->input->post('curpwd'));
if ($pwd_valid) {
$this->contacts_model->update_password(
$this->session->userdata('uid'), $this->input->post('newpwd'));
$message = "<strong>Password</strong> has been changed!";
$json = json_encode(array(
......@@ -212,8 +199,7 @@ class Site extends CI_Controller
'message' => $message
));
echo $json;
}
else{
} else {
$message = "<strong>Current Password</strong> is wrong!";
$json = json_encode(array(
'isSuccessful' => FALSE,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment