<?php
error_reporting(0);
ob_start();
session_start();
include "../../../../model/viewuser.php";
include "../../../../model/proseslogin.php";
include "../../../../controller/security.php";
include "../../../../konfig/dbconnect.php";

$db = new database();
$db->dbsql();

$aksi = $_GET[aksi];
if($aksi=='login'){
    $injeksi = new security();
    
    $username = $injeksi->anti_injection($_POST[username]);
    $password = $injeksi->anti_injection(md5($_POST[password]));
    
    
        $login = new proseslogin();
        $l = $login->login($username, $password);
        
        if($l[n] > 0){
            
            $_SESSION[username] = $l[username];
            $_SESSION[password] = $l[password];
            $_SESSION[id]       = $l[id];
            $_SESSION[nama]     = $l[nama];
            $_SESSION[status]   = $l[status];
            $_SESSION[level]    = $l[level];
            $_SESSION[logo]     = $l[logo];
            
            
            $sid_lama = session_id();
            session_regenerate_id();
            $sid_baru = session_id();
            
            $login->session($sid_baru, $username);
            
            header('location:../../../../index.php?module=home');
        }else{
            header('location:../../../../index.php?alt=4');
        }
    
}
elseif($aksi=='logout'){
    session_destroy();
    header('location:../../../../index.php');
}
elseif($aksi=='reset'){
    $user = new viewuser();
    
    if($_POST[password]==$_POST[rpassword]){
        $pass = md5($_POST[password]);
        $user->editpassword($pass, $_POST[username]);
        
        header('location:../../../../index.php?alt=5');
    }else{
        header('location:../../../../index.php?module=reset&alt=1');
    }
}

