protected void btnLogin_Click(object sender, EventArgs e) { /*string[] lines = { Request.UserHostName, Request.UserHostAddress, Request.UserAgent, Request.UrlReferrer.ToString() }; File.WriteAllLines(@"C:\Users\micks\Documents\BitBucket\UAttendWeb\WebApp\temp\" + txtEmail.Value, lines);*/ string loginResult = " "; string email = txtEmail.Value; string password = txtPassword.Value; int lecturerID = 0; string redirectURL = "Dashboard.aspx"; if ((string)Session["LoginRedirect"] != null) { redirectURL = (string)Session["LoginRedirect"]; } LecturerHandler lecturerHandler = new LecturerHandler(); Lecturer lecturer = new Lecturer(); lecturer = lecturerHandler.ValidateLogin(email, password); try { loginResult = lecturer.LecturerID.ToString(); lecturerID = lecturer.LecturerID; Session["LecturerID"] = lecturerID; Session["FirstName"] = lecturer.FirstName; Session["Surname"] = lecturer.Surname; Response.Redirect(redirectURL); } catch (NullReferenceException) { litAlert.Text = "<div class='alert alert-danger'>The username or password you entered is incorrect</div>"; } }
protected void Page_Load(object sender, EventArgs e) { int lecturerID = (int)Session["LecturerID"]; if (lecturerID == 0) Response.Redirect("Login.aspx"); LecturerHandler lecturerHandler = new LecturerHandler(); Lecturer lecturer = new Lecturer(); lecturer = lecturerHandler.GetLecturerDetails(lecturerID); if (!IsPostBack) { try { txtEmail.Value = lecturer.Email; txtFirstName.Value = lecturer.FirstName; txtSurname.Value = lecturer.Surname; } catch (NullReferenceException) { Response.Redirect("Default.aspx"); } } }
protected void btnUpdateProfile_Click(object sender, EventArgs e) { int lecturerID = 0; try { lecturerID = Convert.ToInt32(Request.QueryString["id"]); } catch (NullReferenceException) { } LecturerHandler lecturerHandler = new LecturerHandler(); Lecturer lecturer = new Lecturer(); lecturer = lecturerHandler.GetLecturerDetails(lecturerID); lecturer.LecturerID = lecturerID; lecturer.FirstName = txtFirstName.Value; lecturer.Surname = txtSurname.Value; lecturer.Email = txtEmail.Value; lecturer.Password = txtPassword.Value; if (txtPassword.Value == "") lecturerHandler.UpdateLecturer(lecturer); else if (txtPassword.Value != "") lecturerHandler.UpdateLecturerWithPassword(lecturer); Response.Redirect("Profile.aspx?id=" + lecturerID.ToString()); }
protected void btnSearch_Click(object sender, EventArgs e) { lstLecturers.Items.Clear(); string searchQuery = txtSearch.Value.Replace(" ", "%"); searchQuery = searchQuery.Trim(); LecturerHandler lectuerHandler = new LecturerHandler(); lstLecturers.DataSource = lectuerHandler.GetLecturerSearchList(searchQuery); lstLecturers.DataTextField = "FirstName"; lstLecturers.DataValueField = "LecturerID"; lstLecturers.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["FirstName"] == null) { Response.Redirect("Default.aspx"); } Lecturer lecturer = new Lecturer(); LecturerHandler lecturerHandler = new LecturerHandler(); lecturer = lecturerHandler.GetLecturerDetails(Convert.ToInt32(Session["LecturerID"])); if (lecturer.Role != 2) { Response.Redirect("Dashboard.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { int lecturerID = (int)Session["LecturerID"]; if (lecturerID == 0) Response.Redirect("Login.aspx"); LecturerHandler lecturerHandler = new LecturerHandler(); Lecturer lecturer = new Lecturer(); lecturer = lecturerHandler.GetLecturerDetails(lecturerID); litLecturerName.Text = "Profile for " + lecturer.FirstName + " " + lecturer.Surname; txtEmail.Value = lecturer.Email; txtFirstName.Value = lecturer.FirstName; txtSurname.Value = lecturer.Surname; }
//lecturer log in //get /api/mobile/a@a/123 public int Get(string email, string password) { //log in here int lecturerId = 0; LecturerHandler lecturerHandler = new LecturerHandler(); Lecturer lecturer = new Lecturer(); lecturer = lecturerHandler.ValidateLogin(email, password); try { lecturerId = lecturer.LecturerID; } catch (Exception) { } return lecturerId; }
protected void Page_Load(object sender, EventArgs e) { if (Session["FirstName"] == null) { Response.Redirect("Default.aspx"); } Lecturer lecturer = new Lecturer(); LecturerHandler lecturerHandler = new LecturerHandler(); lecturer = lecturerHandler.GetLecturerDetails(Convert.ToInt32(Session["LecturerID"])); if (lecturer.Role == 2) { litAdminMenu.Text = "<h3>Admin tools</h3><br /><a href='AddModuleAdmin.aspx' class='btn btn-success'>Add Module</a><br /><br />"; //business button for litAdminMenu //<a href='BusinessSettings.aspx' class='btn btn-success'>Business Settings</a> } }
protected void btnRegister_Click(object sender, EventArgs e) { lblInvalidEmail.Text = ""; lblConfirmPassword.Text = ""; string option = ""; double num = 0; Lecturer lecturer = new Lecturer(); lecturer.Email = txtEmail.Value; lecturer.Password = txtPassword.Value; lecturer.FirstName = txtFirstName.Value; lecturer.Surname = txtSurname.Value; LecturerHandler lecturerHandler = new LecturerHandler(); if (txtPassword.Value == txtConfirmPassword.Value) { if (lecturerHandler.ValidateEmail(txtEmail.Value) == false/* && double.TryParse(option, out num) == true*/) { if (lecturerHandler.AddNewLecturer(lecturer) == false) Response.Redirect("Login.aspx?registered=1"); } else if (lecturerHandler.ValidateEmail(txtEmail.Value) == true) { lblInvalidEmail.Text = "This E-Mail address is already in use"; txtPassword.Attributes.Add("value", txtPassword.Value); txtConfirmPassword.Attributes.Add("value", txtConfirmPassword.Value); } else if (double.TryParse(option, out num) == false) { lblInvalidEmail.Text = ""; txtPassword.Attributes.Add("value", txtPassword.Value); txtConfirmPassword.Attributes.Add("value", txtConfirmPassword.Value); } } else { lblConfirmPassword.Text = "Passwords do not match"; } }
protected void btnRecoverPassword_Click(object sender, EventArgs e) { LecturerHandler lecturerHandler = new LecturerHandler(); Lecturer lecturer = null; BusinessHandler businessHandler = null; Business business = null; string destinationEmail = txtEmail.Value; //check email exists if (lecturerHandler.ValidateEmail(destinationEmail) == false) { //email doesn't exist in DB litAlert.Text = "<div class='alert alert-danger'>Invalid Email Address</div>"; } else { //get business email and password string name, email, password, emailServer, newPassword; int port; businessHandler = new BusinessHandler(); business = new Business(); business = businessHandler.GetBusinessDetails(); name = business.Name; email = business.Email; password = business.EmailPassword; emailServer = business.EmailServer; port = business.EmailPort; //generate new password newPassword = Membership.GeneratePassword(7, 0); //update database lecturer = new Lecturer(); lecturer.Email = destinationEmail; lecturer.Password = newPassword; //send email try { MailMessage mail = new MailMessage(); SmtpClient smtpClient = new SmtpClient(emailServer); mail.From = new MailAddress(email); mail.To.Add(destinationEmail); mail.Subject = name + " Password Reset"; mail.Body = "Your password has been reset. Please use the following phrase as your new password when you log in: " + newPassword; //code to include an attatchment //System.Net.Mail.Attachment attachment; //attachment = new System.Net.Mail.Attachment("attatchment.jpg"); //mail.Attachments.Add(attachment); smtpClient.Port = port; smtpClient.Credentials = new NetworkCredential(email, password); smtpClient.EnableSsl = true; smtpClient.Send(mail); lecturerHandler.UpdateLecturerPassword(lecturer); litAlert.Text = "<div class='alert alert-success'>An email was sent, check you email for your new password.</div>"; //delay redirect to alert user of page change /*lblRedirect.Text = "Redirecting to log in, in 5 seconds."; Response.Write("<script type=\"text/javascript\">setTimeout(function () { window.location.href = \"Login.aspx\"; }, 5000);</script>");*/ } catch (Exception) { litAlert.Text = "<div class='alert alert-warning'>Failed to send an email</div>"; } } }