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(); } }
protected void Page_Load(object sender, EventArgs e) { if (null != Request.Cookies[Settings.Default.SessionCookieKey]) { if (0 != UserMgmt.LookupSession(Request.Cookies[Settings.Default.SessionCookieKey].Value)) { Response.Redirect("~/Default.aspx"); } } }
/// <summary> /// Initiates users /// If any are found, add them to the list ( UserMgmt.AddUsers ) /// If no users are found, create them /// </summary> public static void UserInit() { string[] users = Directory.GetDirectories(KernelVariables.homedir); if (users.Length == 0) { Environment_variables.current_usr = UserMgmt.NewUser(); } else { UserMgmt.AddUsers(); Environment_variables.current_usr = UserMgmt.Login(); } }
protected void Page_Load(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(Request.Cookies[Settings.Default.SessionCookieKey].Value)) { UserMgmt.RemoveSession(Convert.ToInt64(Request.Cookies[Settings.Default.SessionCookieKey].Value)); } Response.Cookies[Settings.Default.SessionCookieKey].Value = ""; Response.Redirect("~/"); } catch (Exception ex) { ErrorLogging.AddException("Error in " + Path.GetFileName(Request.PhysicalPath), ex); Response.Write(ex.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(); } }
private void SetUserCookie(Int64 userID) { Response.Cookies[Settings.Default.SessionCookieKey].Value = UserMgmt.CreateSession(userID).ToString(); }