protected void buttonFrontpageSave_OnClick(object sender, EventArgs e) { try { Database.Interface.open(); Database.Configuration configuration = new Database.Configuration(); if (configuration.select_all_where_name("Default")) { configuration.Start = textBoxEdit.Value; if (configuration.update_all_by_name()) { Utils.displayStatus(ref labelStatusEditConfig, Color.SeaGreen, "Startside informasjon oppdatert"); } else { Utils.displayStatus(ref labelStatusEditConfig, Color.Red, "Oppdatering av startside informasjon feilet"); } literalShowConfig.Text = textBoxEdit.Value; } else { Utils.displayStatus(ref labelStatusEditConfig, Color.Red, "Konfigurasjonen 'Default' ikke funnet"); } } catch (Exception ex) { Utils.displayStatus(ref labelStatusEditConfig, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
public static void reportStatus(ref Label label, Color color, string message) { displayStatus(ref label, color, message); if (ConfigurationManager.AppSettings["UseEmail"] == "yes") { if (ConfigurationManager.AppSettings["ReportSystemCriticalErrors"].ToLower() == "yes") { try { Database.Configuration configuration = new Database.Configuration(); Database.Interface.open(); if (!configuration.select_all_where_name("Default")) { return; } MailMessage mail = new MailMessage(); mail.To.Add(configuration.RingtestAdminEmail); mail.From = new MailAddress(configuration.RingtestAdminEmail); mail.BodyEncoding = System.Text.Encoding.Default; mail.IsBodyHtml = true; mail.Subject = "LORAKON - Feilmelding"; mail.Body = "LORAKON - Feilmelding " + DateTime.Now.ToLongTimeString() + "<br><br>" + message; SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["MailServer"], Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"])); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); } catch (Exception ex) { } finally { Database.Interface.close(); } } } }
protected void buttonSendRequest_OnClick(object sender, EventArgs e) { if (ConfigurationManager.AppSettings["UseEmail"] != "yes") { Utils.displayStatus(ref labelStatus, Color.Red, "Sending av epost er deaktivert"); return; } if (String.IsNullOrEmpty(tbCompanyName.Text)) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Missing_fields); return; } if (textBoxCAPTCHA.Text == Session["CaptchaImageText"].ToString()) { try { if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServer"]) || String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServerPort"])) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Email_no_server); return; } Database.Configuration configuration = new Database.Configuration(); Database.Interface.open(); if (!configuration.select_all_where_name("Default")) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Configuration + " " + Lang.not_found); return; } Database.Interface.close(); MailMessage mail = new MailMessage(); mail.To.Add(configuration.RingtestAdminEmail); mail.From = new MailAddress(configuration.RingtestAdminEmail); mail.IsBodyHtml = true; mail.BodyEncoding = System.Text.Encoding.Default; mail.Subject = "LORAKON - Konto har glemt passordet"; mail.Body = "Konto " + tbCompanyName.Text + " har glemt passordet til LORAKON sidene"; SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["MailServer"], Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"])); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); buttonCancel.Text = Lang.Back; buttonSendRequest.Enabled = false; Utils.displayStatus(ref labelStatus, Color.SeaGreen, Lang.Email_sent); } catch (Exception ex) { textBoxCAPTCHA.Text = ""; Utils.displayStatus(ref labelStatus, Color.Red, ex.Message); } } else { textBoxCAPTCHA.Text = ""; Utils.displayStatus(ref labelStatus, Color.Red, Lang.Numbers_from_picture_doesnt_match); } }
protected void buttonRequestUser_OnClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(textBoxFullname.Text) || String.IsNullOrEmpty(textBoxAddress.Text) || String.IsNullOrEmpty(textBoxPostal.Text) || String.IsNullOrEmpty(textBoxEmail.Text)) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Missing_fields); return; } if (!Utils.isValidEmail(textBoxEmail.Text)) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Email_invalid_address); return; } Database.Configuration configuration = new Database.Configuration(); try { if (textBoxCAPTCHA.Text == Session["CaptchaImageText"].ToString()) { Database.Interface.open(); if (!configuration.select_all_where_name("Default")) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Configuration + " " + Lang.not_found); return; } Database.PendingAccount pendingAccount = new Database.PendingAccount( textBoxFullname.Text, textBoxContact.Text, textBoxAddress.Text, "Field not active", textBoxPostal.Text, textBoxEmail.Text, textBoxPhone.Text, textBoxMobile.Text, textBoxFax.Text, textBoxWebsite.Text); pendingAccount.insert_with_ID(Guid.NewGuid()); Utils.displayStatus(ref labelStatus, Color.SeaGreen, Lang.Account_request_accepted); } else { textBoxCAPTCHA.Text = ""; Utils.displayStatus(ref labelStatus, Color.Red, Lang.Numbers_from_picture_doesnt_match); } } catch (Exception ex) { textBoxCAPTCHA.Text = ""; Utils.reportStatus(ref labelStatus, Color.Red, "CreateUser.buttonRequestUser_OnClick: " + ex.Message); } finally { Database.Interface.close(); } if (ConfigurationManager.AppSettings["UseEmail"] == "yes") { string receip = textBoxEmail.Text; string mailTitle = "Forespørsel om ny LORAKON konto"; string mailBody = "Forespørsel om ny LORAKON konto fra " + textBoxFullname.Text; buttonCancel.Text = Resources.Localization.Back; buttonRequestUser.Enabled = false; clearAllFields(); try { if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServer"]) || String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServerPort"])) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Account_request_accepted + ". " + Lang.Email_no_server); return; } MailMessage mail = new MailMessage(); mail.To.Add(configuration.RingtestAdminEmail); mail.From = new MailAddress(configuration.RingtestAdminEmail); mail.IsBodyHtml = true; mail.BodyEncoding = System.Text.Encoding.Default; mail.Subject = mailTitle; mail.Body = mailBody; SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["MailServer"], Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"])); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); Utils.displayStatus(ref labelStatus, Color.SeaGreen, Lang.Account_request_accepted + ". " + Resources.Localization.Email_sent); } catch (Exception ex) { Utils.displayStatus(ref labelStatus, Color.Red, ex.Message); } } }
protected void buttonCreateAccount_OnClick(object sender, EventArgs e) { bool accountCreated = false; Database.Account account = null; if (String.IsNullOrEmpty(tbUserName.Text) || String.IsNullOrEmpty(tbPassword.Text) || String.IsNullOrEmpty(tbEmail.Text) || String.IsNullOrEmpty(tbName.Text) || String.IsNullOrEmpty(tbAddress.Text) || String.IsNullOrEmpty(tbPostal.Text)) { Utils.displayStatus(ref labelStatusCreate, Color.Red, "Mangler informasjon"); return; } if (!Utils.isValidEmail(tbEmail.Text)) { Utils.displayStatus(ref labelStatusCreate, Color.Red, "Epost adresse har ugyldig format"); return; } if (tbPassword.Text.Length < Membership.MinRequiredPasswordLength) { Utils.displayStatus(ref labelStatusCreate, Color.Red, "Passordet må ha minst " + Membership.MinRequiredPasswordLength.ToString() + " tegn"); return; } if (tbPassword.Text != tbConfirmPassword.Text) { Utils.displayStatus(ref labelStatusCreate, Color.Red, "Passordene er ikke like"); return; } if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServer"]) || String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServerPort"])) { Utils.displayStatus(ref labelStatusCreate, Color.Red, "Innstillinger for mailserver mangler"); return; } Database.Configuration configuration = new Database.Configuration(); try { Membership.ApplicationName = "/Lorakon"; Database.Interface.open(); if (!configuration.select_all_where_name("Default")) { Utils.displayStatus(ref labelStatusCreate, Color.Red, "Finner ikke konfigurasjon"); return; } if (Database.Account.accountNameExists(tbName.Text)) { Utils.displayStatus(ref labelStatusCreate, Color.Red, "Navnet " + tbName.Text + " finnes allerede"); Membership.ApplicationName = "/LorakonAdmin"; return; } MembershipCreateStatus status = new MembershipCreateStatus(); MembershipUser user = Membership.CreateUser(tbUserName.Text, tbPassword.Text, tbEmail.Text, "question", "answer", true, out status); if (user == null) { Utils.displayStatus(ref labelStatusCreate, Color.Red, Utils.getErrorMessage(status)); Membership.ApplicationName = "/LorakonAdmin"; return; } account = new Database.Account( Guid.Empty, tbName.Text, tbContact.Text, tbAddress.Text, "Field not active", tbPostal.Text, tbEmail.Text, tbPhone.Text, tbMobile.Text, tbFax.Text, tbWebsite.Text, true, "", 0, 0, ""); accountCreated = account.insert_with_ID((Guid)user.ProviderUserKey); if (!String.IsNullOrEmpty(hiddenPendingUser.Value) && hiddenPendingUser.Value != Guid.Empty.ToString()) { Database.PendingAccount pendingAccount = new Database.PendingAccount(); if (pendingAccount.select_all_where_ID(new Guid(hiddenPendingUser.Value))) { pendingAccount.delete_by_ID(); } } ddUsers.DataBind(); ddAccountsA.DataBind(); } catch (Exception ex) { Membership.DeleteUser(tbUserName.Text); if (accountCreated) { account.delete_by_ID(); } Utils.displayStatus(ref labelStatusCreate, Color.Red, ex.Message); return; } finally { Database.Interface.close(); Membership.ApplicationName = "/LorakonAdmin"; } string userName = tbUserName.Text; string receip = tbEmail.Text; string mailTitle = "Ny LORAKON konto tildelt"; string mailBody = @"Velkommen som bruker av LORAKON nettjenester.<br> Hver bedrift får kun tildelt ett brukernavn og passord. Dersom bedriften har flere ansatte som skal være delaktige i nettverket må brukernavnet og passordet deles mellom disse.<br> Deres bedrift har fått tildelt følgende brukernavn: " + tbUserName.Text + " og passord: " + tbPassword.Text + @".<br> For å logge inn på sidene kan følgende lenke benyttes: <a href='" + ConfigurationManager.AppSettings["LorakonURL"] + "'>" + ConfigurationManager.AppSettings["LorakonURL"] + @"</a><br> NB! Brukernavnet er låst, men brukeren kan selv endre passordet ved behov via siden 'Bedriftens konto'<br><br> Hilsen Statens Strålevern"; clearAllCreateFields(); ddPendingUsers.DataBind(); ddUsers.DataBind(); ddAccountsA.DataBind(); if (ConfigurationManager.AppSettings["UseEmail"] == "yes") { try { MailMessage mail = new MailMessage(); mail.To.Add(receip); mail.From = new MailAddress(configuration.RingtestAdminEmail); mail.IsBodyHtml = true; mail.BodyEncoding = System.Text.Encoding.Default; mail.Subject = mailTitle; mail.Body = mailBody; SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["MailServer"], Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"])); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); Utils.displayStatus(ref labelStatusCreate, Color.SeaGreen, "Bruker " + userName + " ble opprettet, og e-post er sendt til " + receip); } catch (Exception ex) { Utils.displayStatus(ref labelStatusCreate, Color.Red, ex.Message); } } }
protected void Page_Load(object sender, EventArgs e) { try { if (!HttpContext.Current.User.Identity.IsAuthenticated) { Response.Redirect("~/Login.aspx"); } string[] roles = Roles.GetAllRoles(); foreach (string s in roles) { TableRow row = new TableRow(); tableRoles.Controls.Add(row); TableCell cell = new TableCell(); row.Controls.Add(cell); CheckBox cb = new CheckBox(); cb.Text = s; cb.CssClass = "TipText"; cb.AutoPostBack = true; cb.CheckedChanged += new EventHandler(cb_CheckedChanged); cell.Controls.Add(cb); } if (!Page.IsPostBack) { populateUserList(); Database.Interface.open(); Database.Configuration configuration = new Database.Configuration(); configuration.select_all_where_name("Default"); tbSectionManager.Text = configuration.SectionManager; tbRingtestAdminEmail.Text = configuration.RingtestAdminEmail; Database.Interface.close(); if (HttpContext.Current.User.IsInRole("Administrator")) { tabUser.Enabled = false; } else { tabAdmin.Enabled = false; ProfileCommon prof = Profile.GetProfile(HttpContext.Current.User.Identity.Name); tbEditNameUser.Text = prof.Name; tbEditTitleUser.Text = prof.Title; tbEditPhoneUser.Text = prof.Phone; tbEditEmailUser.Text = prof.Email; } } } catch (Exception ex) { if (HttpContext.Current.User.IsInRole("Administrator")) { Utils.displayStatus(ref labelStatus, Color.Red, ex.Message); } else { Utils.displayStatus(ref labelStatusUser, Color.Red, ex.Message); } } bool isAdministrator = HttpContext.Current.User.IsInRole("Administrator"); buttonCreateUser.Enabled = isAdministrator; buttonChangePassword.Enabled = isAdministrator; buttonUpdateUser.Enabled = isAdministrator; buttonDeleteUser.Enabled = isAdministrator; buttonUpdateSectionManager.Enabled = isAdministrator; tbCreateUser.Enabled = isAdministrator; tbCreateName.Enabled = isAdministrator; tbCreatePhone.Enabled = isAdministrator; tbCreateTitle.Enabled = isAdministrator; tbCreateEmail.Enabled = isAdministrator; tbCreatePassword.Enabled = isAdministrator; tbCreatePassword2.Enabled = isAdministrator; tbEditName.Enabled = isAdministrator; tbEditPhone.Enabled = isAdministrator; tbEditTitle.Enabled = isAdministrator; tbEditEmail.Enabled = isAdministrator; tbChangePassword.Enabled = isAdministrator; tbChangePassword2.Enabled = isAdministrator; tbSectionManager.Enabled = isAdministrator; }
protected void initializePage() { bool ringtestExists = false; bool hasStarted = false; try { Database.Interface.open(); Database.Configuration configuration = new Database.Configuration(); if (!configuration.select_all_where_name("Default")) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Configuration not found"); return; } Database.Ringtest ringtest = new Database.Ringtest(); if (ringtest.select_all_where_year(DateTime.Now.Year)) { ringtestExists = true; if (DateTime.Now >= ringtest.StartDate) { hasStarted = true; } if (hasStarted && ringtest.Finished) { multiViewRingtest.SetActiveView(viewFinished); return; } } Database.Account account = new Database.Account(); if (!account.select_all_where_ID(new Guid(hiddenAccountID.Value))) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Account not found"); return; } if (account.LastRegistrationYear != DateTime.Now.Year) { if (hasStarted) { // send info to admin multiViewRingtest.SetActiveView(viewSendMessage); labelSendMessage.Text = Lang.RingtestAlreadyStarted; } else { multiViewRingtest.SetActiveView(viewRegister); labelRegister.Text = Lang.RingtestAccountNotRegistered; } return; } if (hasStarted) { hiddenRingtestID.Value = ringtest.ID.ToString(); } else { multiViewRingtest.SetActiveView(viewNoInit); if (ringtestExists) { labelInit.Text = Lang.RingtestNotStarted + " " + ringtest.StartDate.ToShortDateString(); } else { labelInit.Text = Lang.RingtestDateNotDetermined; } return; } if (account.RingtestBoxID == Guid.Empty) { multiViewRingtest.SetActiveView(viewSendMessage); labelSendMessage.Text = Lang.RingtestAccountBoxNotAssigned; return; } hiddenRingtestBoxID.Value = account.RingtestBoxID.ToString(); Database.DeviceCategory category = new Database.DeviceCategory(); if (!category.select_all_where_name("Detektor")) { multiViewRingtest.SetActiveView(viewNoInit); labelInit.Text = Lang.DatabaseError; Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Category 'Detektor' not found"); return; } List <Database.Identifiers> idList = new List <Database.Identifiers>(); if (!Database.Device.select_identifiers_where_accountID_categoryID_status(account.ID, category.ID, "Ok", ref idList)) { multiViewRingtest.SetActiveView(viewNoInit); labelInit.Text = Lang.RingtestNoDetectors1 + " " + account.Name + Lang.RingtestNoDetectors2 + " " + configuration.RingtestAdminEmail + " " + Lang.RingtestNoDetectors3; return; } ddDetector.Items.Add(new ListItem("---", Guid.Empty.ToString())); foreach (Database.Identifiers ids in idList) { ddDetector.Items.Add(new ListItem(ids.Name, ids.ID.ToString())); } } catch (Exception ex) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: " + ex.Message); } finally { Database.Interface.close(); } multiViewRingtest.SetActiveView(viewSelectDetector); }
protected void buttonSendMessage_OnClick(object sender, EventArgs e) { if (ConfigurationManager.AppSettings["UseEmail"] != "yes") { Utils.displayStatus(ref labelStatusMessage, Color.Red, "Sending av epost er deaktivert"); return; } if (String.IsNullOrEmpty(tbMessage.Text)) { Utils.displayStatus(ref labelStatusMessage, Color.Red, Lang.Missing_fields); return; } try { Database.Interface.open(); Database.Configuration configuration = new Database.Configuration(); if (!configuration.select_all_where_name("Default")) { Utils.displayStatus(ref labelStatusMessage, Color.Red, Lang.Configuration + " " + Lang.not_found); return; } Database.Account account = new Database.Account(); if (!account.select_all_where_ID(new Guid(hiddenAccountID.Value))) { Utils.reportStatus(ref labelStatusMessage, Color.Red, "Ringtest.buttonSendMessage_OnClick: account.select_all_where_ID failed"); return; } if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServer"]) && !String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServerPort"])) { string mailTitle = "Forespørsel fra LORAKON konto " + account.Name + "(" + account.Email + ")"; string mailBody = tbMessage.Text; MailMessage mail = new MailMessage(); mail.To.Add(configuration.RingtestAdminEmail); mail.From = new MailAddress(configuration.RingtestAdminEmail); mail.BodyEncoding = System.Text.Encoding.Default; mail.IsBodyHtml = true; mail.Subject = mailTitle; mail.Body = mailBody; SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["MailServer"], Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"])); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); Utils.displayStatus(ref labelStatusMessage, Color.SeaGreen, Lang.Message_sent); } else { Utils.displayStatus(ref labelStatusMessage, Color.Red, Lang.Email_no_server); } tbMessage.Text = ""; } catch (Exception ex) { Utils.displayStatus(ref labelStatusMessage, Color.Red, "Ringtest.buttonSendMessage_OnClick: " + ex.Message); } finally { Database.Interface.close(); } }