PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Kronos/Kronos/Register.aspx.cs

https://github.com/lle/soen341kronos
C# | 106 lines | 90 code | 12 blank | 4 comment | 18 complexity | b504bd140b9a394f21378608016bc7f9 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.SqlClient;
  8. using System.Data;
  9. using System.Data.Linq;
  10. using System.Configuration;
  11. using Kronos.CLASSES;
  12. using System.Net.Mail;
  13. using System.Net;
  14. namespace Kronos
  15. {
  16. public partial class Register : System.Web.UI.Page
  17. {
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. register_label.Visible = false;
  21. }
  22. protected void Button1_Click(object sender, EventArgs e)
  23. {
  24. #region REGISTER
  25. //check passwords match
  26. if (password_textbox1.Text != password_text2box.Text)
  27. {
  28. register_label.Visible = true;
  29. register_label.Text = "Passwords do not match";
  30. }
  31. //check its not empty the password
  32. else if(password_text2box.Text=="" || password_textbox1.Text=="")
  33. {
  34. register_label.Visible = true;
  35. register_label.Text = "Don't leave passwords blank stupid";
  36. }
  37. else
  38. {
  39. soen341dBEntities soen341dB_context = new soen341dBEntities();
  40. registration newuser = new registration();
  41. //checking if either the user or email is already registered
  42. var username_in_dB = (from a_username in soen341dB_context.registrations
  43. where a_username.Username == username_textbox.Text
  44. select a_username).FirstOrDefault();
  45. var email_in_dB = (from an_email in soen341dB_context.registrations
  46. where an_email.email == email_textbox.Text
  47. select an_email).FirstOrDefault();
  48. var studentid_in_dB = (from a_student_id in soen341dB_context.registrations
  49. where a_student_id.StudentId == studentid_textbox.Text
  50. select a_student_id).FirstOrDefault();
  51. if (email_in_dB != null) { register_label.Text = "Email already registered"; register_label.Visible = true; }
  52. if (username_in_dB != null) { register_label.Text = "Username already Exists"; register_label.Visible = true; }
  53. if (studentid_in_dB != null) { register_label.Text = "Student ID Already taken"; register_label.Visible = true; }
  54. //if it doesnt retrieve records make a new record
  55. if (email_in_dB == null && username_in_dB == null)
  56. {
  57. try
  58. {
  59. newuser.Username = username_textbox.Text;
  60. newuser.Password = globalvariables.EncodePassword(password_textbox1.Text);
  61. newuser.email = email_textbox.Text;
  62. newuser.StudentId = studentid_textbox.Text;
  63. soen341dB_context.registrations.Add(newuser);
  64. soen341dB_context.SaveChanges();
  65. }
  66. catch (Exception error)
  67. {
  68. register_label.Visible=true;
  69. register_label.Text = "Database Exception Occured: " + error.ToString();
  70. }
  71. finally
  72. {
  73. register_label.Visible = true;
  74. register_label.Text = "Thank You for registering, You should have recieved an email from us!";
  75. MailMessage mail = new MailMessage();
  76. mail.To.Add(email_textbox.Text);
  77. mail.From = new MailAddress("admin@341.atsebak.com");
  78. mail.Subject = "mYScheduler Registration Confirmation";
  79. mail.Body = "Thank You for registering to the Concordia University mYScheduler. Your username is: " + username_textbox.Text +" Please report bugs and suggestions to admin@341.atsebak.com";
  80. mail.IsBodyHtml = true;
  81. SmtpClient smtp = new SmtpClient();
  82. smtp.Host = "mail.atsebak.com";
  83. smtp.Port = 587;
  84. smtp.UseDefaultCredentials = true;
  85. smtp.Credentials = new NetworkCredential("admin@341.atsebak.com", "softwareprocess");
  86. smtp.EnableSsl = false;
  87. smtp.Send(mail);
  88. }
  89. }
  90. }
  91. #endregion
  92. }
  93. }
  94. }