﻿function AuthenticationService_LoginWithCallback(username, password,successCallback,failureCallback) {
    Sys.Services.AuthenticationService.login(username, password, false, null, null, successCallback, failureCallback, username);
}
function AuthenticationService_LoginRedirectWithCallback(username, password, redirectUrl, successCallback, failureCallback) {
    Sys.Services.AuthenticationService.login(username, password, false, null, redirectUrl, successCallback, failureCallback, username);
}
function AuthenticationService_Login(username,password) {
    Sys.Services.AuthenticationService.login(username, password, false, null, null, AuthenticationService_LoginSuccess, AuthenticationService_LoginFailed, username);
}
function AuthenticationService_LoginSuccess(validCredentials, userContext, methodName) {
    if (validCredentials)
        alert('Login for ' + userContext + ' succeeded.');
    else
        alert('Login for ' + userContext + ' failed.');
}
function AuthenticationService_LoginFailed(error, userContext, methodName) {
    alert(error.get_message());
}

function AuthenticationService_LogoutWithCallback(successCallback, failureCallback) {
    Sys.Services.AuthenticationService.logout(null, successCallback, failureCallback, null);
}
function AuthenticationService_Logout() {
    Sys.Services.AuthenticationService.logout(null, AuthenticationService_LogoutSuccess, AuthenticationService_LogoutFailed, null);
}
function AuthenticationService_LogoutSuccess(result, userContext, methodName) {
    alert("You have successfully signed out.");
}
function AuthenticationService_LogoutFailed(error, userContext, methodName) {
    alert(error.get_message());
}

function AuthenticationService_IsUserLoggedIn() {
    return Sys.Services.AuthenticationService.get_isLoggedIn();
}
