protected void LoginButton_Click(object sender, EventArgs e) { try { if (UserMgmt.UserExists(UserName.Text)) { Int64 userID = UserMgmt.CheckUser(UserName.Text, Password.Text); if (0 != userID) { Response.Cookies[Settings.Default.SessionCookieKey].Value = UserMgmt.CreateSession(userID).ToString(); string continueUrl = Request.QueryString["ReturnUrl"]; if (String.IsNullOrEmpty(continueUrl)) { continueUrl = "~/"; } Response.Redirect(continueUrl); } else { FailureText.Text = string.Format("Sorry {0}, that's not the password we have stored in the system. Please try again.", CleanUsername(UserName.Text)); } } else { FailureText.Text = string.Format("Sorry, the username {0} doesn't exist in the system", CleanUsername(UserName.Text)); } } catch (Exception ex) { ErrorLogging.AddException("Error in Register", ex); FailureText.Text = ex.ToString(); } }
private void SetUserCookie(Int64 userID) { Response.Cookies[Settings.Default.SessionCookieKey].Value = UserMgmt.CreateSession(userID).ToString(); }
protected void CreateUserButton_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(UserName.Text)) { if (!UserMgmt.UserExists(UserName.Text)) { Int64 userID = UserMgmt.CreateUser(UserName.Text, Email.Text, Password.Text); if (0 != userID) { Response.Cookies[Settings.Default.SessionCookieKey].Value = UserMgmt.CreateSession(userID).ToString(); string continueUrl = Request.QueryString["ReturnUrl"]; if (String.IsNullOrEmpty(continueUrl)) { continueUrl = "~/"; } Response.Redirect(continueUrl); } else { ErrorMessage.Text = "There was an error creating your user, please try again."; } } else { ErrorMessage.Text = "A user witht that username already exists"; } } else { ErrorMessage.Text = "Your username must be at least one character long"; } } catch (Exception ex) { ErrorLogging.AddException("Error in Register", ex); ErrorMessage.Text = ex.ToString(); } }