//---------------------------------------------------------------------------------------// protected void btnSubmit_Click(object sender, System.EventArgs e) { string userName = txtUsername.Text.Trim(); string email = txtEmail.Text.Trim(); string prompt = "Please enter "; string errorMessage = null; if (userName.Length == 0) { errorMessage = prompt + "Username"; } else if (email.Length == 0) { errorMessage = prompt + "Email Address"; } if (errorMessage != null) { lblResponse.Text = Utilities.FormatErrorMessage(errorMessage); lblResponse.Visible = true; return; } AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); int userID = wrapper.GetUserIDWrapper(userName); if (userID < 0) { // userID does not exist in the database lblResponse.Text = Utilities.FormatErrorMessage("This username does not exist."); lblResponse.Visible = true; return; } User[] lostPassUsers = wrapper.GetUsersWrapper(new int[] { userID }); if (lostPassUsers[0].userID == 0) { // userID does not exist in the database lblResponse.Text = Utilities.FormatErrorMessage("This username does not exist."); lblResponse.Visible = true; } else if (email.ToLower() != wrapper.GetUsersWrapper(new int[] { userID })[0].email.ToLower()) { // email does not match email record in our database lblResponse.Text = Utilities.FormatErrorMessage("Please use the username AND email you were registered with."); lblResponse.Visible = true; } else // send password to requestor's email address { // // Email new password to user // string subject = "[" + this.serviceBrokerName + "] Lost Password"; StringWriter message = new StringWriter(); message.WriteLine("Username: "******"Email: " + email); message.WriteLine(); message.WriteLine("Your old password has been reset to the following password." + " For security reasons, please login and use the 'My Account' page to reset your password."); message.WriteLine(); message.WriteLine("Password: "******"Your request has been submitted. A new password will be created and emailed to you at the email address specified."); lblResponse.Visible = true; } catch (Exception ex) { // trouble sending request for password // Report detailed SMTP Errors string smtpErrorMsg; smtpErrorMsg = "Exception: " + ex.Message; //check the InnerException if (ex.InnerException != null) smtpErrorMsg += "<br>Inner Exceptions:"; while (ex.InnerException != null) { smtpErrorMsg += "<br>" + ex.InnerException.Message; ex = ex.InnerException; } lblResponse.Text = Utilities.FormatErrorMessage("Trouble sending email. Your request could not be submitted - please inform an administrator.<br>" + smtpErrorMsg); lblResponse.Visible = true; } } }
protected void btnSaveChanges_Click(object sender, System.EventArgs e) { BrokerDB brokerDB = new BrokerDB(); AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); if(txtNewPassword.Text.CompareTo(txtConfirmPassword.Text) != 0 ) { lblResponse.Text = Utilities.FormatErrorMessage("Password fields don't match. Try again!"); lblResponse.Visible = true; txtNewPassword.Text = null; txtConfirmPassword.Text = null; } else { //if a field is left blank, it is not updated try { User userInfo = wrapper.GetUsersWrapper(new int[] {Convert.ToInt32(Session["UserID"])})[0]; Authority auth = brokerDB.AuthorityRetrieve(userInfo.authID); if (txtUsername.Text.Trim()=="") { txtUsername.Text = userInfo.userName; } if(txtFirstName.Text.Trim() == "") { txtFirstName.Text = userInfo.firstName ; } if(txtLastName.Text.Trim() == "") { txtLastName.Text = userInfo.lastName ; } if(txtEmail.Text.Trim() == "") { txtEmail.Text = userInfo.email ; } if (userInfo.reason==null) userInfo.reason = ""; if (userInfo.affiliation==null) userInfo.affiliation=""; if (userInfo.xmlExtension==null) userInfo.xmlExtension=""; wrapper.ModifyUserWrapper (userInfo.userID,txtUsername.Text,auth.authorityID,auth.authTypeID, txtFirstName.Text , txtLastName.Text , txtEmail.Text ,userInfo.affiliation, userInfo.reason, userInfo.xmlExtension,userInfo.lockAccount ); lblResponse.Text = Utilities.FormatConfirmationMessage("User \"" + txtUsername.Text + "\" information has been updated."); lblResponse.Visible = true; if (auth.authTypeID == (int) AuthenticationType.AuthTypeID.Native) { if (txtNewPassword.Text != "") { wrapper.SetNativePasswordWrapper(Convert.ToInt32(Session["UserID"]), txtNewPassword.Text); } } if (txtUsername.Text.CompareTo(Session["UserName"].ToString())!= 0) Session["UserName"]= txtUsername.Text; // Send a confirmation message to the user string email; if(txtEmail.Text.Trim() == "") { // use old email if it wasn't changed, new if it was email = userInfo.email; } else { email = txtEmail.Text.Trim(); } if (email != null && email.Length > 0) { MailMessage mail = new MailMessage(); mail.From = registrationMailAddress; mail.To = email; mail.Subject = "[iLabs] Service Broker Account Update Confirmation"; mail.Body = "Your Service Broker account has been updated to the following:\n\r"; mail.Body += "-------------------------------------------------------------\n\r\n\r"; mail.Body += "User Name: " + txtUsername.Text + "\n\r"; mail.Body += "First Name: " + txtFirstName.Text + "\n\r"; mail.Body += "Last Name: " + txtLastName.Text + "\n\r"; mail.Body += "Email: " + txtEmail.Text + "\n\r\n\r"; mail.Body += "For security reasons, your password has not been included in this message." + "\n\r"; SmtpMail.SmtpServer = "127.0.0.1"; try { SmtpMail.Send(mail); } catch(Exception e2) { // if the confirmation message fails, c'est la vie... string msg = "Error sending email notification: (" + e2.Message + ". " + e2.GetBaseException() + "). Contact " + supportMailAddress + "."; lblResponse.Text = Utilities.FormatErrorMessage(msg); lblResponse.Visible = true; } } } catch (Exception ex) { string msg = "Error updating account ("+ex.Message+". "+ex.GetBaseException()+"). Contact " + supportMailAddress + "."; lblResponse.Text = Utilities.FormatErrorMessage(msg); lblResponse.Visible = true; } } }
protected void Page_Load(object sender, System.EventArgs e) { AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); if(! IsPostBack) { LoadAuthorityList(); //Populate textboxes with User's data User sessionUser = new User(); sessionUser = wrapper.GetUsersWrapper(new int[]{Convert.ToInt32(Session["UserID"])})[0]; txtUsername.Text = sessionUser.userName; txtFirstName.Text = sessionUser.firstName; txtLastName.Text = sessionUser.lastName; txtEmail.Text = sessionUser.email; txtNewPassword.Text = ""; txtConfirmPassword.Text = ""; ddlAuthorities.SelectedValue = sessionUser.authID.ToString(); ddlAuthorities.Enabled = false; // To list all the groups a user belongs to int userID = Convert.ToInt32(Session["UserID"]); int[] groupIDs = wrapper.ListGroupsForUserWrapper (userID); //since we already have the groups a user has access // if we use wrapper here, it will deny authentication Group[] gps = AdministrativeAPI.GetGroups(groupIDs); ArrayList nonRequestGroups = new ArrayList(); ArrayList requestGroups = new ArrayList(); foreach(Group g in gps) { if (g.groupName.EndsWith("request")) requestGroups.Add(g); else if(!g.groupName.Equals("NewUserGroup")) nonRequestGroups.Add(g); } //List Groups that user belongs to in blue box if ((nonRequestGroups!=null)&& (nonRequestGroups.Count>0)) { for (int i=0;i<nonRequestGroups.Count;i++) { lblGroups.Text+= ((Group)nonRequestGroups[i]).groupName; if (i != nonRequestGroups.Count-1) lblGroups.Text +=", "; } } else { lblGroups.Text = "No group"; } //List Groups that user has requested to in blue box if ((requestGroups!=null)&& (requestGroups.Count>0)) { for (int i=0;i<requestGroups.Count;i++) { int origGroupID = AdministrativeAPI.GetAssociatedGroupID(((Group)requestGroups[i]).groupID); string origGroupName = AdministrativeAPI.GetGroups(new int[] {origGroupID})[0].groupName; lblRequestGroups.Text+= origGroupName; if (i != requestGroups.Count-1) lblRequestGroups.Text +=", "; } } else { lblRequestGroups.Text = "No group"; } } }
//---------------------------------------------------------------------------------------// protected void btnSave_Click(object sender, EventArgs e) { AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); if (txtNewPassword.Text.CompareTo(txtConfirmPassword.Text) != 0) { lblResponse.Text = Utilities.FormatErrorMessage("Password fields don't match. Try again!"); lblResponse.Visible = true; txtNewPassword.Text = null; txtConfirmPassword.Text = null; } else { //if a field is left blank, it is not updated try { User userInfo = wrapper.GetUsersWrapper(new int[] { Convert.ToInt32(Session["UserID"]) })[0]; if (txtUsername.Text.Trim() == "") { txtUsername.Text = userInfo.userName; } if (txtFirstName.Text.Trim() == "") { txtFirstName.Text = userInfo.firstName; } if (txtLastName.Text.Trim() == "") { txtLastName.Text = userInfo.lastName; } if (txtEmail.Text.Trim() == "") { txtEmail.Text = userInfo.email; } if (userInfo.reason == null) userInfo.reason = ""; if (userInfo.affiliation == null) userInfo.affiliation = ""; if (userInfo.xmlExtension == null) userInfo.xmlExtension = ""; wrapper.ModifyUserWrapper(userInfo.userID, txtUsername.Text, txtUsername.Text, AuthenticationType.NativeAuthentication, txtFirstName.Text, txtLastName.Text, txtEmail.Text, userInfo.affiliation, userInfo.reason, userInfo.xmlExtension, userInfo.lockAccount); lblResponse.Text = Utilities.FormatConfirmationMessage("User \"" + txtUsername.Text + "\" information has been updated."); lblResponse.Visible = true; if (txtNewPassword.Text != "") { wrapper.SetNativePasswordWrapper(Convert.ToInt32(Session["UserID"]), txtNewPassword.Text); } if (txtUsername.Text.CompareTo(Session["UserName"].ToString()) != 0) Session["UserName"] = txtUsername.Text; // Send a confirmation message to the user string email; if (txtEmail.Text.Trim() == "") { // use old email if it wasn't changed, new if it was email = userInfo.email; } else { email = txtEmail.Text.Trim(); } // // Email account update confirmation // string subject = "[" + this.serviceBrokerName + "] Account Update Confirmation"; StringWriter message = new StringWriter(); message.WriteLine("Your ServiceBroker account has been updated to the following:"); message.WriteLine("------------------------------------------------------------"); message.WriteLine(); message.WriteLine("User Name: " + txtUsername.Text); message.WriteLine("First Name: " + txtFirstName.Text); message.WriteLine("Last Name: " + txtLastName.Text); message.WriteLine("Email Address: " + txtEmail.Text); message.WriteLine(); message.WriteLine("For security reasons, your password has not been included in this message."); string body = message.ToString(); string from = registrationMailAddress; string to = email; MailMessage mailMessage = new MailMessage(from, to, subject, body); SmtpClient smtpClient = new SmtpClient(Consts.STR_LocalhostIP); try { smtpClient.Send(mailMessage); } catch { // if the confirmation message fails, c'est la vie... } } catch (Exception ex) { string msg = "Error updating account (" + ex.Message + ". " + ex.GetBaseException() + "). Contact " + supportMailAddress + "."; lblResponse.Text = Utilities.FormatErrorMessage(msg); lblResponse.Visible = true; } } }
//---------------------------------------------------------------------------------------// protected void Page_Load(object sender, EventArgs e) { lblResponse.Visible = false; if (!IsPostBack) { // // Populate textboxes with the user's information // AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); User sessionUser = new User(); int userID = Convert.ToInt32(Session[Consts.STRSSN_UserID]); sessionUser = wrapper.GetUsersWrapper(new int[] { userID })[0]; txtUsername.Enabled = false; txtUsername.Text = sessionUser.userName; txtFirstName.Text = sessionUser.firstName; txtLastName.Text = sessionUser.lastName; txtEmail.Text = sessionUser.email; txtNewPassword.Text = ""; txtConfirmPassword.Text = ""; // To list all the groups a user belongs to int[] groupIDs = wrapper.ListGroupsForAgentWrapper(userID); //since we already have the groups a user has access // if we use wrapper here, it will deny authentication Group[] gps = AdministrativeAPI.GetGroups(groupIDs); ArrayList nonRequestGroups = new ArrayList(); ArrayList requestGroups = new ArrayList(); foreach (Group g in gps) { if (g.groupName.EndsWith("request")) requestGroups.Add(g); else if (!g.groupName.Equals("NewUserGroup")) nonRequestGroups.Add(g); } // // List Groups for which the user is a member // StringBuilder sb = new StringBuilder(); if ((nonRequestGroups != null) && (nonRequestGroups.Count > 0)) { for (int i = 0; i < nonRequestGroups.Count; i++) { sb.Append(((Group)nonRequestGroups[i]).groupName); if (i < nonRequestGroups.Count - 1) { sb.Append("<br />"); } } } else { sb.Append("No group"); } lblGroups.Text = sb.ToString(); // // List Groups for which the user has requested membership // sb = new StringBuilder(); if ((requestGroups != null) && (requestGroups.Count > 0)) { for (int i = 0; i < requestGroups.Count; i++) { int origGroupID = AdministrativeAPI.GetAssociatedGroupID(((Group)requestGroups[i]).groupID); string origGroupName = AdministrativeAPI.GetGroups(new int[] { origGroupID })[0].groupName; sb.Append(origGroupName); if (i < requestGroups.Count - 1) { sb.Append("<br />"); } } } else { sb.Append("No group"); } lblRequestGroups.Text = sb.ToString(); } }
protected void btnSubmit_Click(object sender, System.EventArgs e) { AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); if(txtUsername.Text == "") { lblResponse.Text = Utilities.FormatErrorMessage("Missing user ID field."); lblResponse.Visible = true; return; } else { string userName = txtUsername.Text; int userID = wrapper.GetUserIDWrapper(userName) ; if (txtEmail.Text == "") { lblResponse.Text = Utilities.FormatErrorMessage("Missing email field."); lblResponse.Visible = true; return; } else { string email = txtEmail.Text ; User[] lostPassUsers = wrapper.GetUsersWrapper (new int[]{userID}); if (lostPassUsers[0].userID == 0) { // userID does not exist in the database lblResponse.Text = Utilities.FormatErrorMessage("This user does not exist."); lblResponse.Visible = true; } else if( email.ToLower () != wrapper.GetUsersWrapper (new int[] {userID})[0].email.ToLower ()) { // email does not match email record in our database lblResponse.Text = Utilities.FormatErrorMessage("Please use the user ID AND email you were registered with."); lblResponse.Visible = true; } else // send password to requestor's email address { MailMessage mail = new MailMessage(); mail.From = registrationMailAddress; mail.To = email; mail.Subject = "[iLabs] Service Broker Password Reminder" ; mail.Body = "Username: "******"\n\r"; mail.Body += "Email: " + email + "\n\r\n\r"; mail.Body +="Your old password has been reset to the following password. For security reasons, please login and use the 'My Account' page to reset your password.\n\r\n\r"; mail.Body += "Password: "******"127.0.0.1"; try { SmtpMail.Send(mail); // email sent message lblResponse.Text = Utilities.FormatConfirmationMessage("Your request has been submitted. A new password will be created and emailed to the email address you entered below."); lblResponse.Visible = true; } catch (Exception ex) { // trouble sending request for password // Report detailed SMTP Errors string smtpErrorMsg; smtpErrorMsg = "Exception: " + ex.Message; //check the InnerException if (ex.InnerException != null) smtpErrorMsg += "<br>Inner Exceptions:"; while( ex.InnerException != null ) { smtpErrorMsg += "<br>" + ex.InnerException.Message; ex = ex.InnerException; } lblResponse.Text = Utilities.FormatErrorMessage("Trouble sending email. Your request could not be submitted - please inform an administrator.<br>" + smtpErrorMsg); lblResponse.Visible = true; } } } } }