Ejemplo n.º 1
0
    protected void buttonDeletePendingAccount_OnClick(object sender, EventArgs e)
    {
        if (ddPendingUsers.SelectedValue == Guid.Empty.ToString())
        {
            Utils.displayStatus(ref labelStatusCreate, Color.Red, "Ingen ventende brukere valgt");
            return;
        }

        try
        {
            string delAccount = ddPendingUsers.SelectedItem.Text;
            Database.Interface.open();
            Database.PendingAccount pendingAccount = new Database.PendingAccount();
            pendingAccount.ID = new Guid(ddPendingUsers.SelectedValue);
            pendingAccount.delete_by_ID();
            ddPendingUsers.DataBind();

            clearAllCreateFields();

            Utils.displayStatus(ref labelStatusCreate, Color.SeaGreen, "Ventende konto '" + delAccount + "' slettet");
        }
        catch (Exception ex)
        {
            Utils.displayStatus(ref labelStatusCreate, Color.Red, ex.Message);
        }
        finally
        {
            Database.Interface.close();
        }
    }
Ejemplo n.º 2
0
    protected void ddPendingUsers_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddPendingUsers.SelectedValue == Guid.Empty.ToString())
        {
            hiddenPendingUser.Value = Guid.Empty.ToString();
            clearAllCreateFields();
            return;
        }

        hiddenPendingUser.Value = ddPendingUsers.SelectedValue;

        try
        {
            Database.Interface.open();
            Database.PendingAccount pendingAccount = new Database.PendingAccount();
            pendingAccount.select_all_where_ID(new Guid(ddPendingUsers.SelectedValue));

            tbName.Text    = pendingAccount.Name;
            tbContact.Text = pendingAccount.Contact;
            tbAddress.Text = pendingAccount.Address;
            tbPostal.Text  = pendingAccount.Postal;
            tbEmail.Text   = pendingAccount.Email;
            tbPhone.Text   = pendingAccount.Phone;
            tbMobile.Text  = pendingAccount.Mobile;
            tbFax.Text     = pendingAccount.Fax;
            tbWebsite.Text = pendingAccount.Website;
        }
        catch (Exception ex)
        {
            Utils.displayStatus(ref labelStatusCreate, Color.Red, ex.Message);
        }
        finally
        {
            Database.Interface.close();
        }
    }
Ejemplo n.º 3
0
    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);
            }
        }
    }
Ejemplo n.º 4
0
    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);
            }
        }
    }