Posted
on Jul 13, 2009
(permalink)
In my current project that I'm trying to merge into Sitefinity, I handled the login via Javascript so that I could integrate the login into the site instead of separate page. Here is the coding that successfully controlled the login functionality using the built in .NET provider:
protected void Page_Load(object sender, EventArgs e)
{
if
(Context.User.Identity.IsAuthenticated)
{
Label
firstName = LoginView1.FindControl("FirstName") as Label;
Label
lastName = LoginView1.FindControl("LastName") as Label;
firstName.Text = Profile.FirstName;
lastName.Text =
Profile.LastName;
string scriptString = "";
scriptString += "<script type=\"text/javascript\">";
scriptString += "function logoutButton_Click() {";
scriptString
+= "Sys.Services.AuthenticationService.logout('Home.aspx', null, errorCallback,
null);";
scriptString += "}";
scriptString +=
"function errorCallback(error) {";
scriptString +=
"alert(error.get_message());";
scriptString +=
"}";
scriptString += "</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "logoutView",
scriptString);
}
else
{
RadMultiPage loginPage = LoginView1.FindControl("RadMultiPage1") as
RadMultiPage;
string scriptString = "";
scriptString += "<script type=\"text/javascript\">";
scriptString += "function loginView_Show() {";
scriptString +=
"var loginPage = $find('" + loginPage.ClientID + "');";
scriptString += "loginPage.set_selectedIndex(1);";
scriptString
+= "setTimeout('usernameGetFocus();',500);";
scriptString +=
"setTimeout('loginView_Hide();',30000);";
scriptString +=
"}";
scriptString += "function loginView_Hide()
{";
scriptString += "var loginPage = $find('" +
LoginView1.FindControl("RadMultiPage1").ClientID + "');";
scriptString += "loginPage.set_selectedIndex(0);";
scriptString
+= "}";
scriptString += "function usernameGetFocus()
{";
scriptString += "$get(\"userName\").focus();";
scriptString += "}";
scriptString += "function
loginCallback(loggedIn) {";
scriptString += "if (loggedIn ==
false) {";
scriptString += "alert(\"The username and password you
supplied is invalid.\");";
scriptString +=
"$get(\"userName\").value = \"\";";
scriptString +=
"$get(\"password\").value = \"\";";
scriptString +=
"$get(\"userName\").focus();";
scriptString +=
"}";
scriptString += "}";
scriptString +=
"function loginButton_Click() {";
scriptString +=
"Sys.Services.AuthenticationService.login($get(\"userName\").value,
$get(\"password\").value, false, null, 'default.aspx', loginCallback,
errorCallback);";
scriptString += "}";
scriptString += "function errorCallback(error) {";
scriptString
+= "alert(error.get_message());";
scriptString +=
"}";
scriptString += "</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "loginView",
scriptString);
}
}
This scripting doesn't seem to work in Sitefinity. The displaying of the controls works fine, but hitting login/logout doesn't seem to work, which makes me think the Sys.Services.AuthenticationService Javascript methods either don't work properly with Sitefinity or that I have to use a different method.
Can you let me know if the approach I used before will work with Sitefinity and how to modify my script to work? Thanks for the assistance.