protected void btn_login_Click(object sender, EventArgs e) { /*1 - Grabbing the user's login info*/ String Username = txb_TUID.Text; String Password = txb_Password.Text; /*2 - Resetting controls to default values*/ lbl_Error.Text = ""; /*3 - Basic validation*/ if (Username.Equals("")) { lbl_Error.Text = "ERROR: The username field is empty."; lbl_Error.ForeColor = Color.Red; } else if (Password.Equals("")) { lbl_Error.Text = "ERROR: The password field is empty."; lbl_Error.ForeColor = Color.Red; } else if (valid.validateLogin(Username) || valid.validateLogin(Password)) { lbl_Error.Text = "ERROR: Illegal input character was used."; lbl_Error.ForeColor = Color.Red; } else { /*3 - Checking that the Username and Password are both correct*/ bool Correct_Login_Information = AuthenticateUser(Username, Password); if (!Correct_Login_Information) { lbl_Error.Text = "ERROR: Your username or password is incorrect."; lbl_Error.ForeColor = Color.Red; } else { /*4 - Requesting Web Service information*/ TempleUser.LDAPuser Temple_Information = TempleUser.WebService.getLDAPEntryByAccessnet(Username); TempleUser.StudentObj Student_Information = TempleUser.WebService.getStudentInfo(Temple_Information.templeEduID); /*5 - Checking we received something from Web Services*/ if (Temple_Information == null) { lbl_Error.Text = "ERROR: Web Services did not return anything."; } else if (Temple_Information != null) { /*Populating the Session Object with the user's information*/ Session["TU_ID"] = Temple_Information.templeEduID;//TUID Session["First_Name"] = Temple_Information.givenName; Session["Last_Name"] = Temple_Information.sn; Session["Email"] = Temple_Information.mail; Session["Title"] = Temple_Information.title; Session["Affiliation_Primary"] = Temple_Information.eduPersonPrimaryAffiliation; Session["Affiliation_Secondary"] = Temple_Information.eduPersonAffiliation; /*Security Session Variable*/ Session["Authenticated"] = true; /*If the user is also a student, we can also retreive their information and add them to the Session Object*/ if (Student_Information != null) { Session["School"] = Student_Information.school; Session["Major_1"] = Student_Information.major1; Session["Major_2"] = Student_Information.major2; } /*Successful Login - Allowed to be redirected to Home.aspx*/ DbMethods DbMethodsObj = new DbMethods(); bool test = DbMethodsObj.CheckIfAdminExists(Student_Information.tuid); //check if user is an Admin if (test == true) { //Security Session Variable for Admin Session["AdminToken"] = true; Response.Redirect("Admin.aspx"); } else { //check if expert exists in system int count = Convert.ToInt32(DbMethodsObj.CheckIfExpertExists(Student_Information.tuid)); if (count == 0) { Response.Redirect("CreateProfile.aspx"); } else { SessionMethods sessionMethodsObj = new SessionMethods(); sessionMethodsObj.storeExpertDataInSession(); //change isActive to true DbMethodsObj.SetExpertIsActiveTrue(); Expert expertProfileObj = (CapstoneBlackstone.Expert)Session["expertProfileObj"]; string user_name = expertProfileObj.username; var x = Session["Authenticated"]; //redirect to expert page Response.Redirect("ExpertPage.aspx?username=" + user_name);// conserve the session token at login } } } } } }//end logIn button clickEvent
protected void btnCreateProfile_Click(object sender, EventArgs e) { lblPicCheckSize.Visible = false; lblPicCheckType.Visible = false; int count = Convert.ToInt32(db.CheckIfUsernameExists(txtUsername.Text)); if (valid.IsBlank(txtFirstName.Text) || valid.IsBlank(txtLastName.Text) || valid.IsBlank(txtEmail.Text) || valid.IsBlank(txtUsername.Text) || valid.IsBlank(txtEmail.Text)) { lblRequired.Visible = true; } else if (count >= 1) { lblUsernameCheck.Visible = true; } else { string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName); //uploaded file extension int iFileSize = FileUpload1.PostedFile.ContentLength; //uploaded file size if (FileUpload1.FileContent != null && FileUpload1.HasFile) { if (valid.TestForLegalImageTypes(fileExtension) == false) {//fail lblPicCheckType.Visible = true; lblPicCheckType.Text = fileExtension + " file extension is not allowed. Please use .png, .gif, .jpg, .jpeg, .pdf, .pcd, .fpx, .tif instead"; } else if (iFileSize >= 90000) {//fail lblPicCheckSize.Visible = true; lblPicCheckSize.Text = "Your file size is " + iFileSize + " bytes. Please reduce the size to less than 90 KB (90000 bytes)."; } else { MemoryStream ms = new MemoryStream(); var img = System.Drawing.Image.FromStream(FileUpload1.FileContent); img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); imageBytes = ms.ToArray(); Session.Add("picture", imageBytes); } } else { string FilePath = System.Web.VirtualPathUtility.ToAbsolute("~/Images/TUOwls_logo.png"); FileStream fs = new FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read); imageBytes = new byte[fs.Length]; fs.Read(imageBytes, 0, Convert.ToInt32(fs.Length)); fs.Close(); MemoryStream ms = new MemoryStream(); Session.Add("picture", imageBytes); } Expert newExpert = new Expert { tuID = (string)Session["TU_ID"], username = txtUsername.Text, firstName = txtFirstName.Text, lastName = txtLastName.Text, college = (string)Session["School"], major = (string)Session["Major_1"], email = txtEmail.Text, dateJoined = DateTime.Now, phoneNumber = txtPhoneNumber.Text, aboutMe = aboutMe.Text, linkedIn = txtLinkedIn.Text, picture = (byte[])Session["picture"], isActive = true, skillGroupID = Int32.Parse(SkillGroupDropdown.SelectedValue), genderID = Int32.Parse(genderDropdown.SelectedValue), ethnicityID = Int32.Parse(ethnicityDropdown.SelectedValue), lastUpdateDate = DateTime.Now, lastUpdateUser = txtLastName.Text + ", " + txtFirstName.Text }; DbMethods dbmethods = new DbMethods(); SessionMethods sessionMethodsObj = new SessionMethods(); int result = dbmethods.CreateExpert(newExpert); sessionMethodsObj.storeExpertDataInSession(); Response.Redirect("ExpertPage.aspx?username=" + newExpert.username); //Response.Write(result); } }