protected void ButtonSubmit_Click(object sender, EventArgs e) { Facilitator newFac = new Facilitator(); CSS RequestDirector = new CSS(); bool Confirmation; //if getfacilitator returns default facilitator values, that email has not been used if (RequestDirector.GetFacilitatorByEmail(EmailTxt.Text).Email == default(string)) { newFac.FirstName = FirstNameTxt.Text; newFac.LastName = LastNameTxt.Text; newFac.Title = TitleTxt.Text; newFac.Email = EmailTxt.Text; newFac.Organization = OrgTxt.Text; newFac.Location = LocTxt.Text; //generate password hash newFac.Salt = RequestDirector.CreateSalt(5); newFac.Password = RequestDirector.CreatePasswordHash(PasswordTxt.Text, newFac.Salt); newFac.Roles = "Facilitator|"; //attempt to create an account Confirmation = RequestDirector.CreateFacilitator(newFac); //if account creation successful, log in and redirect to home if (Confirmation) { if (RequestDirector.IsAuthenticated(EmailTxt.Text, PasswordTxt.Text)) { Facilitator pullFacilitator = RequestDirector.GetFacilitatorByEmail(EmailTxt.Text); string roles = pullFacilitator.Roles; FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, RequestDirector.GetFacilitatorByEmail(EmailTxt.Text).FacilitatorID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, roles); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); Response.Cookies.Add(authCookie); Response.Redirect("Default.aspx"); } else { MsgLbl.Text = "Your email or password is incorrect"; } } else { MsgLbl.Text = "Error creating account."; } } else { MsgLbl.Text = "This email is already associated with an account."; } }
protected void ButtonLogin_Click(object sender, EventArgs e) { //only validate if user has agreed to terms if (consentCheck.Checked) { CSS RequestManager = new CSS(); //validate user login info if (RequestManager.IsAuthenticated(EmailTxt.Text, PasswordTxt.Text)) { //if //get info for email input Facilitator pullFacilitator = RequestManager.GetFacilitatorByEmail(EmailTxt.Text); string roles = pullFacilitator.Roles; //create authentication cookie FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, RequestManager.GetFacilitatorByEmail(EmailTxt.Text).FacilitatorID.ToString(), DateTime.Now, DateTime.Now.AddHours(24), RememberChk.Checked, roles); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); Response.Cookies.Add(authCookie); //create consent cookie if there isn't one var consentCookie = Request.Cookies["ConsentCookie"]; if (consentCookie == null) { HttpCookie newConsent = new HttpCookie("ConsentCookie", "true"); //set cookie to expire in 100 days newConsent.Expires = DateTime.UtcNow.AddDays(100); Response.Cookies.Add(newConsent); } string Redirect; Redirect = Request["ReturnUrl"]; if (Redirect == null) { Redirect = "Default.aspx"; } Response.Redirect(Redirect, true); } else { MsgLbl.Text = "Your email or password is incorrect"; } } else { consentCheck.ForeColor = System.Drawing.Color.Red; } }
//update facilitator account info protected void UpdateBtn_Click(object sender, EventArgs e) { CustomPrincipal cp = HttpContext.Current.User as CustomPrincipal; CSS requestDirector = new CSS(); //get facilitator info Facilitator activeFac = new Facilitator(); activeFac.FacilitatorID = Convert.ToInt32(cp.Identity.Name); activeFac = requestDirector.GetFacilitator(activeFac.FacilitatorID); //check if facilitator changed email if (Emailtxt.Text != activeFac.Email) { //if new email, check if email already in use if (requestDirector.GetFacilitatorByEmail(Emailtxt.Text).Email == default(string)) { activeFac.Email = Emailtxt.Text; activeFac.FirstName = FNametxt.Text; activeFac.LastName = LNametxt.Text; activeFac.Title = Titletxt.Text; activeFac.Organization = Orgtxt.Text; activeFac.Location = Loctxt.Text; if (requestDirector.UpdateFacilitator(activeFac)) { Msglbl.Text = "Account Information Updated"; } else { Msglbl.Text = "Account Information Update Failed"; } } else { Msglbl.Text = "That email is used by another account"; } } else { activeFac.Email = Emailtxt.Text; activeFac.FirstName = FNametxt.Text; activeFac.LastName = LNametxt.Text; activeFac.Title = Titletxt.Text; activeFac.Organization = Orgtxt.Text; activeFac.Location = Loctxt.Text; if (requestDirector.UpdateFacilitator(activeFac)) { Msglbl.Text = "Account Information Updated"; } else { Msglbl.Text = "Account Information Update Failed"; } } }