Пример #1
0
            $hash = $data['hash'];
        } else {
            my_LoginError();
        }
    } else {
        // Search for the user's node by slug //
        $response['id'] = intval(node_GetNodeIdByParentIdAndSlug(CMW_NODE_USER, $login));
        // If a valid ID, retrieve the hash
        if ($response['id'] > 0) {
            $hash = user_GetHashById($response['id']);
        } else {
            my_LoginError();
        }
    }
    // If found, verify password against the stored hash.
    if (user_VerifyPassword($password, $hash)) {
        // Success! //
        user_StartSession(false);
        user_DoLogin($response['id']);
        user_EndSession();
        // TODO: Clear login attempt cache //
    } else {
        my_LoginError();
    }
    // ** Successfully Logged in ** //
    // Retrieve my info //
    // Retrieve my list of Favourites, and a list of most recent posts I've loved. //
} else {
    if ($action === 'logout') {
        user_Start();
        user_DoLogout();
Пример #2
0
function main()
{
    $out = "";
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $out .= print_r($_POST, true);
        $out .= "<br />";
        // Required Fields in the POST data //
        if (!isset($_POST['login'])) {
            return;
        }
        if (!isset($_POST['password'])) {
            return;
        }
        //if ( !isset($_POST['hashword']) ) return;
        // Password //
        $password = $_POST['password'];
        if (empty($password)) {
            return;
        }
        $login = $_POST['login'];
        // Can Login 3 ways:
        // - User Name (slug)
        // - Email
        // - User ID
        $mail = sanitize_Email($login);
        $id = sanitize_Id($login);
        $slug = sanitize_Slug($login);
        $hash = "";
        if (!empty($mail)) {
            $out .= "By Mail<br />";
            $data = user_GetIdAndHashByMail($mail);
            $id = $data['id'];
            $hash = $data['hash'];
        } else {
            if (!empty($id)) {
                $out .= "By User ID<br />";
                $hash = user_GetHashById($id);
            } else {
                if (!empty($slug)) {
                    $out .= "By Slug<br />";
                    $id = node_GetNodeIdByParentIdAndSlug(CMW_NODE_USER, $slug);
                    if ($id > 0) {
                        $hash = user_GetHashById($id);
                    }
                } else {
                    $out .= "Bad Login Method<br />";
                }
            }
        }
        $success = user_VerifyPassword($password, $hash);
        $out .= "Verify: " . ($success ? "Success!" : "failed") . "<br />";
        if ($success) {
            user_StartSession(true);
            user_SetLoginToken();
            user_SetID($id);
            user_EndSession();
        }
        $out .= "<br />";
    }
    return $out;
}