private string CheckAvailability() { string suggestedAccount = (TextBoxAccount.Text.Trim() + "@" + DropDownMailDomain.SelectedValue).ToLower(); if (!Formatting.ValidateEmailFormat(suggestedAccount)) { suggestedAccount = (TextBoxAccount.Text.Trim()).ToLower(); if (!Formatting.ValidateEmailFormat(suggestedAccount)) { return("Bad format"); } } try { LabelAccount.Text = suggestedAccount.Split('@')[0];; DropDownMailDomain.SelectedValue = suggestedAccount.Split('@')[1]; } catch { return("Bad format"); } List <MailServerDatabase.MailAccount> objAcc = MailServerDatabase.SearchAccount(suggestedAccount); foreach (MailServerDatabase.MailAccount acc in objAcc) { if (acc.account.Trim().ToLower() == suggestedAccount) { return("Not available"); } } return(""); }
protected void Page_Load(object sender, EventArgs e) { state = ("" + Request["state"]).Trim().ToLower(); account = ("" + Request["account"]).Trim().ToLower(); currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name); _currentUser = Person.FromIdentity(currentUserId); _authority = _currentUser.GetAuthority(); if (!_authority.HasPermission(Permission.CanEditMailDB, Organization.PPSEid, -1, Authorization.Flag.AnyGeographyExactOrganization)) { Response.Write("You do not have authority to use this."); Response.End(); } if (!IsPostBack) { if (state == "edit") { LabelAccount.Text = account; LabelAccount.Font.Bold = true; addSpan.Visible = false; pwTR.Visible = true; ButtonDelete.Visible = true; List <MailServerDatabase.MailAccount> objAccList = MailServerDatabase.SearchAccount(account); TextBoxForward.Text = objAccList.Count > 0 ? "" + (objAccList[0].forwardedTo.Count > 0 ? objAccList[0].forwardedTo[0] : "") : ""; } else if (state == "add") { LabelAccount.Text = ""; TextBoxAccount.Text = account; addSpan.Visible = true; pwTR.Visible = true; ButtonDelete.Visible = false; } } }
protected void ButtonValidate_Click(object sender, EventArgs e) { string suggestedAccount = TextBoxForward.Text.Trim().ToLower(); if (!Formatting.ValidateEmailFormat(suggestedAccount)) { LabelValidateError.Text = "Format error"; } else if (suggestedAccount.Contains("@piratpartiet.se")) { List <MailServerDatabase.MailAccount> objAcc = MailServerDatabase.SearchAccount(suggestedAccount); LabelValidateError.Text = "Account not found."; foreach (MailServerDatabase.MailAccount acc in objAcc) { if (acc.account.Trim().ToLower() == suggestedAccount) { LabelValidateError.Text = ""; break; } } } }
private void PopulateGrid() { List <MailServerDatabase.MailAccount> accountList = MailServerDatabase.SearchAccount(TextBoxFindAccount.Text); RadGrid1.DataSource = accountList; }
protected void ButtonSaveChanges_Click(object sender, EventArgs e) { LabelSaveError.Text = "Not Allowed."; if (_authority.HasPermission(Permission.CanEditMailDB, Organization.PPSEid, -1, Authorization.Flag.AnyGeographyExactOrganization)) { LabelSaveError.Text = "Saved."; string suggestedAccount = (TextBoxAccount.Text.Trim() + "@" + DropDownMailDomain.SelectedValue).ToLower(); if (state == "add") { if (CheckAvailability() == "") { if (!Formatting.ValidateEmailFormat(suggestedAccount)) { suggestedAccount = (TextBoxAccount.Text.Trim()).ToLower(); } try { //MailServerDatabase.AddAccount(suggestedAccount, TextBoxPassword.Text, 1024); PWLog.Write(_currentUser, PWLogItem.MailAccount, 0, PWLogAction.MailAccountChanged, "Created account", "Manually changed in PW", suggestedAccount, "", ""); string forwardAccount = TextBoxForward.Text.Trim().ToLower(); if (forwardAccount != "") { MailServerDatabase.StartForwarding(suggestedAccount, forwardAccount); PWLog.Write(_currentUser, PWLogItem.MailAccount, 0, PWLogAction.MailAccountChanged, "Changed forwarding", "Manually changed in PW", account, "", forwardAccount); } ScriptManager.RegisterStartupScript(this, this.GetType(), "saved", "CloseAndRebind();", true); } catch (Exception ex) { LabelSaveError.Text = ex.Message; } } else { LabelSaveError.Text = "Account is NOT available"; } } else { try { List <MailServerDatabase.MailAccount> objAccList = MailServerDatabase.SearchAccount(account); string wasForwarded = objAccList.Count > 0 ? "" + (objAccList[0].forwardedTo.Count > 0 ? objAccList[0].forwardedTo[0] : "") : ""; if (TextBoxPassword.Text != "") { MailServerDatabase.SetNewPassword(account, TextBoxPassword.Text); PWLog.Write(_currentUser, PWLogItem.MailAccount, 0, PWLogAction.MailAccountChanged, "Changed password", "Manually changed in PW", account, "", ""); } string forwardAccount = TextBoxForward.Text.Trim().ToLower(); if (forwardAccount == "" && wasForwarded != "") { MailServerDatabase.StopForwarding(account); PWLog.Write(_currentUser, PWLogItem.MailAccount, 0, PWLogAction.MailAccountChanged, "Stopped forwarding", "Manually changed in PW", account, forwardAccount, ""); } else if (forwardAccount != wasForwarded) { MailServerDatabase.StartForwarding(account, forwardAccount); PWLog.Write(_currentUser, PWLogItem.MailAccount, 0, PWLogAction.MailAccountChanged, "Changed forwarding", "Manually changed in PW", account, wasForwarded, forwardAccount); } ScriptManager.RegisterStartupScript(this, this.GetType(), "saved", "CloseAndRebind();", true); } catch (Exception ex) { LabelSaveError.Text = ex.Message; } } } }