| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /laragon/www/sop/application/controllers/ |
Upload File : |
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
//if (!$this->session->userdata('email')) {
// redirect('auth');
//}
is_logged_in();
}
public function index()
{
$data['title'] = 'My Profile';
$data['title2'] = 'User Profile Informations';
$data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();
$this->load->view('templates/header', $data);
$this->load->view('templates/sidebar', $data);
$this->load->view('templates/topbar', $data);
$this->load->view('user/index', $data);
$this->load->view('templates/footer');
}
public function edit()
{
$data['title'] = 'Edit Profile';
$data['title2'] = 'Data User Profile';
$data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();
$this->form_validation->set_rules('name', 'Full Name', 'required|trim');
if ($this->form_validation->run() == false) {
$this->load->view('templates/header', $data);
$this->load->view('templates/sidebar', $data);
$this->load->view('templates/topbar', $data);
$this->load->view('user/edit', $data);
$this->load->view('templates/footer');
} else {
$name = $this->input->post('name');
$email = $this->input->post('email');
//cek jika ada gambar yg akan diupload
$upload_image = $_FILES['image']['name'];
if ($upload_image) {
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048';
$config['upload_path'] = './assets/img/profile/';
$this->load->library('upload', $config);
if ($this->upload->do_upload('image')) {
$old_image = $data['user']['image'];
if ($old_image != 'default.jpg') {
unlink(FCPATH . 'assets/img/profile/' . $old_image);
}
$new_image = $this->upload->data('file_name');
$this->db->set('image', $new_image);
} else {
echo $this->upload->display_errors();
}
}
$this->db->set('name', $name);
$this->db->where('email', $email);
$this->db->update('user');
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Your profile has been updated! </div>');
redirect('user');
}
}
public function changePassword()
{
$data['title'] = 'Change Password';
$data['title2'] = 'Edit Password For User Account';
$data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();
$this->form_validation->set_rules('current_password', 'Current Password', 'required|trim');
$this->form_validation->set_rules('new_password1', 'New Password', 'required|trim|min_length[3]|matches[new_password2]');
$this->form_validation->set_rules('new_password2', 'Confirm New Password', 'required|trim|min_length[3]|matches[new_password1]');
if ($this->form_validation->run() == false) {
$this->load->view('templates/header', $data);
$this->load->view('templates/sidebar', $data);
$this->load->view('templates/topbar', $data);
$this->load->view('user/changepassword', $data);
$this->load->view('templates/footer');
} else {
$current_password = $this->input->post('current_password');
$new_password = $this->input->post('new_password1');
if (!password_verify($current_password, $data['user']['password'])) {
$this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">Wrong current password! </div>');
redirect('user/changepassword');
} else {
if ($current_password == $new_password) {
$this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">New password cannot be the same as current password! </div>');
redirect('user/changepassword');
} else {
//password sdh ok
$password_hash = password_hash($new_password, PASSWORD_DEFAULT);
$this->db->set('password', $password_hash);
$this->db->where('email', $this->session->userdata('email'));
$this->db->update('user');
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Password changed! </div>');
redirect('user/changepassword');
}
}
}
}
}