Untitled

 avatar
unknown
plain_text
3 years ago
2.9 kB
6
Indexable
<?php

namespace App\Controllers;

use App\Models\ClientModel;

class ClientLogin extends BaseController
{
    public function index()
    {
        $session = session();
        if ($session->get('LOGGED_IN') == TRUE) {
            return redirect()->to('client/dashboard');
        }
        echo view('client/dashboard/includes/header');
        echo view('client/dashboard/login');
        echo view('client/dashboard/includes/footer');
    }

    public function LoginAuth()
    {
        $session = session();
        if ($session->get('LOGGED_IN') == TRUE) {
            return redirect()->to('client/dashboard');
        }
        $model = new ClientModel();
        $nohp = str_replace("'", "", htmlspecialchars($this->request->getVar('nohp'), ENT_QUOTES));
        $password = str_replace("'", "", htmlspecialchars($this->request->getVar('password'), ENT_QUOTES));
        $data = $model->where('nohp_customer', $nohp)->first();
        if ($data) {
            $pass = $data['PASSWORD_CUSTOMER'];
            $verifypass = password_verify($password, $pass);
            if ($data['STATUS_CUSTOMER'] == 'aktif') {
                if ($verifypass) {
                    $ses_data = [
                        'ID_CUSTOMER'       => $data['ID_CUSTOMER'],
                        'NOHP_CUSTOMER'     => $data['NOHP_CUSTOMER'],
                        'EMAIL_CUSTOMER'    => $data['EMAIL_CUSTOMER'],
                        'LOGGED_IN'     => TRUE
                    ];
                    $session->set($ses_data);
                    return redirect()->to('/client/dashboard');
                } else {
                    $session->setFlashdata('msg', 'Wrong Password');
                    return redirect()->to('/client/login');
                }
            } elseif ($data['STATUS_CUSTOMER'] == 'belum aktif') {
                if ($verifypass) {
                    $ses_data = [
                        'ID_CUSTOMER'       => $data['ID_CUSTOMER'],
                        'NOHP_CUSTOMER'     => $data['NOHP_CUSTOMER'],
                        'EMAIL_CUSTOMER'    => $data['EMAIL_CUSTOMER'],
                        'LOGGED_IN'     => TRUE
                    ];
                    $session->set($ses_data);
                    return redirect()->to('/client/register/otp');
                } else {
                    $session->setFlashdata('msg', 'Wrong Password');
                    return redirect()->to('/client/login');
                }
            } else {
                $session->setFlashdata('msg', 'Data Customer not Found');
                return redirect()->to('client/login');
            }
        } else {
            $session->setFlashdata('msg', 'Data Customer not Found');
            return redirect()->to('client/login');
        }
    }
}
Editor is loading...