Ejemplo n.º 1
0
function login($obj)
{
    $name = isset($obj->name) ? $obj->name : '';
    $password = isset($obj->password) ? $obj->password : '';
    $rememberme = isset($obj->rememberme) ? $obj->rememberme : false;
    $user = new user();
    $listUser = $user->getbynameandpassword($name, $password);
    if (count($listUser) > 0) {
        $role = new role();
        $_SESSION['id'] = $listUser[0]->id;
        $_SESSION['name'] = $listUser[0]->name;
        $_SESSION['group_id'] = $listUser[0]->group_id;
        $_SESSION['role'] = $role->getbyid($listUser[0]->group_id);
        if ($rememberme) {
            setcookie("tasktrack", "id=" . $listUser[0]->id, time() + 86400, "/");
        }
        return array("status" => "success", "msg" => "Login Successful");
    } else {
        return array("status" => "warning", "msg" => "Your User name and password is incorrect!");
    }
}