72 lines
3.1 KiB
PHP
72 lines
3.1 KiB
PHP
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
|
class Ms extends CI_Controller {
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->load->helper('form');
|
|
$this->load->library('form_validation');
|
|
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
|
|
}
|
|
public function login() {
|
|
$this->form_validation->set_rules('username', 'lang:username', 'trim|required|alpha_numeric|max_length[32]');
|
|
$this->form_validation->set_rules('password', 'lang:password', 'trim|required');
|
|
if($this->form_validation->run() == TRUE) {
|
|
$username = $_POST['username'];
|
|
$password = $_POST['password'];
|
|
if($this->ms->login($username, $password)) {
|
|
$this->load->view('ms/block-login-success');
|
|
} else {
|
|
$data['login_error'] = true;
|
|
$this->load->view('ms/block-login-frm', $data);
|
|
}
|
|
} else {
|
|
$this->load->view('ms/block-login-frm');
|
|
}
|
|
}
|
|
public function update_user() {
|
|
$this->form_validation->set_rules('username', 'Username', 'trim|required');
|
|
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
|
|
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
|
|
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
|
|
//$this->form_validation->set_rules('mobile', 'Mobile Number', 'trim|required');
|
|
$this->form_validation->set_rules('social_security', 'Social Security', 'trim|required|numeric|exact_length[12]');
|
|
if($this->form_validation->run() == true) {
|
|
$user_id = $this->session->userdata('user_id');
|
|
$username = $_POST['username'];
|
|
$first_name = $_POST['first_name'];
|
|
$last_name = $_POST['last_name'];
|
|
$email = $_POST['email'];
|
|
$mobile = $_POST['mobile'];
|
|
$social_security = $_POST['social_security'];
|
|
$result = $this->ms->update_user($user_id, $username, $first_name, $last_name, $email, $mobile, $social_security);
|
|
if($result > 0) {
|
|
$this->load->view('block-success');
|
|
} else {
|
|
$data['db_error'] = true;
|
|
$this->load->view('ms/block-frm-details', $data);
|
|
}
|
|
} else {
|
|
$this->load->view('ms/block-frm-details');
|
|
}
|
|
}
|
|
public function update_user_password() {
|
|
$this->form_validation->set_rules('old_password', 'Old Password', 'trim|required');
|
|
$this->form_validation->set_rules('new_password', 'New Password', 'trim|required|min_length[10]');
|
|
$this->form_validation->set_rules('new_password_conf', 'Password Confirmation', 'trim|required|matches[new_password]');
|
|
if($this->form_validation->run() == true) {
|
|
$user_id = $this->session->userdata('user_id');
|
|
$old_password = $this->ms->generate_password_hash($_POST['old_password']);
|
|
$new_password = $this->ms->generate_password_hash($_POST['new_password']);
|
|
$result = $this->ms->update_user_password($user_id, $old_password, $new_password);
|
|
if($result > 0) {
|
|
$this->load->view('block-success');
|
|
} else {
|
|
$data['login_error'] = true;
|
|
$this->load->view('ms/block-frm-password', $data);
|
|
}
|
|
} else {
|
|
$this->load->view('ms/block-frm-password');
|
|
}
|
|
}
|
|
}
|
|
?>
|