Пример #1
0
    /// <summary>
    /// Invio mail
    /// </summary>
    /// <param name="email"></param>
    void SendEmail(MailMessage email)
    {
        BusinessObjects.ConfigurationSetting objConfigurationSetting = new BusinessObjects.ConfigurationSetting();
        string SmtpServer = objConfigurationSetting.getValue("SmtpServer");

        string smtpUserName  = string.Empty;
        string smtpPassword  = string.Empty;
        string smtpHost      = string.Empty;
        string smtpEnableSsl = string.Empty;
        string smtpPort      = string.Empty;

        try
        {
            SmtpClient Smtp = new SmtpClient();
            Smtp.Host = SmtpServer;

            smtpUserName  = objConfigurationSetting.getValue("SmtpUserName");
            smtpPassword  = objConfigurationSetting.getValue("SmtpPassword");
            smtpEnableSsl = objConfigurationSetting.getValue("SmtpEnableSsl");
            smtpPort      = objConfigurationSetting.getValue("SmtpPort");

            if (smtpPort != string.Empty)
            {
                Smtp.Port = Convert.ToInt32(smtpPort);
            }

            if (smtpEnableSsl == "true")
            {
                Smtp.EnableSsl = true;
            }

            // Add credentials if the SMTP server requires them.
            if (smtpUserName != string.Empty && smtpPassword != string.Empty && SmtpServer != "localhost")
            {
                Smtp.Credentials = new System.Net.NetworkCredential(smtpUserName, smtpPassword);
            }
            else
            {
                Smtp.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            }

            Smtp.Send(email);

            // Clean up.
            email.Dispose();
        }
        catch (Exception ex)
        {
            if (email != null)
            {
                ((IDisposable)email).Dispose();
            }

            ex.Data.Add("Class.Method", "frm_LGN.SendEmail.");
            // Gestione messaggistica all'utente e trace in DB dell'errore
            ExceptionPolicy.HandleException(ex, "Propagate Policy");
        }
    }
Пример #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
#if DEBUG
        infoCompilationMode.InnerText = "MODALITA' DEBUG";
        infoCompilationMode.Visible   = true;
#endif

        // Visualizza l'ultima data di compilazione della dll
        DateTime cd = File.GetCreationTime(GetType().Assembly.Location);
        lastBuild.InnerText = GetValueDizionarioUI("LOGIN_LAST_RELEASE_DATE") + " " + cd.Day.ToString().PadLeft(2, '0') + "/" + cd.Month.ToString().PadLeft(2, '0') + "/" + cd.Year.ToString() + " " + cd.Hour.ToString().PadLeft(2, '0') + ":" + cd.Minute.ToString().PadLeft(2, '0');

        strERRORE   = Request.QueryString["ERROR"];
        idMailClick = Request.QueryString["idMailClick"];

        if (IsMobile())
        {
            Session["isMobile"]          = "1";
            bodyLgn.Attributes["class"] += "mobile";
        }
        else
        {
            Session["isMobile"] = "0";
        }


        //AAAAAAAAAAAAAAAAAAAAAAAA
        //AAAAAAAAAAAAAAAAAAAAAAAA
        //AAAAAAAAAAAAAAAAAAAAAAAA
        // Session["isMobile"] = "1";
        //AAAAAAAAAAAAAAAAAAAAAAAA
        //AAAAAAAAAAAAAAAAAAAAAAAA
        //AAAAAAAAAAAAAAAAAAAAAAAA

        isMobile.Value = Session["isMobile"].ToString();

        //Questo pezzo di codice mi serve per bypassare il login nel caso provengo da un link alla richiesta presente nella mail.
        if (idMailClick != "" && idMailClick != "ERRORE" && idMailClick != null)
        {
            ByPassLogin(idMailClick);
        }

        if (strERRORE != "" && strERRORE != null)
        {
            LabelMessage.InnerHtml  = strERRORE;
            divLoginMessage.Visible = true;
        }

        if (!IsPostBack)
        {
            BusinessObjects.ConfigurationSetting objConfigurationSetting = new BusinessObjects.ConfigurationSetting();
            string EnableAutoLoginKerberos = objConfigurationSetting.getValue("EnableAutoLoginKerberos").ToString();

            if (!String.IsNullOrEmpty(HttpContext.Current.User.Identity.Name) && EnableAutoLoginKerberos == "True")
            {
                autoLoginKerberosVerified = false;

                autoLoginId = HttpContext.Current.User.Identity.Name;
                autoLoginId = autoLoginId.Substring(autoLoginId.LastIndexOf("\\") + 1);

                if (HttpContext.Current.Request.UrlReferrer == null && (ConfigurationManager.AppSettings.Get("Maintenance") != "true"))
                {
                    ButtonLogin_Click(sender, e);
                }
            }
        }

        isMobile.Value = Session["isMobile"].ToString();

        //Questo pezzo di codice mi serve per bypassare il login nel caso provengo da un link alla richiesta presente nella mail.
        if (idMailClick != "" && idMailClick != "ERRORE" && idMailClick != null)
        {
            ByPassLogin(idMailClick);
        }

        if (strERRORE != "" && strERRORE != null)
        {
            LabelMessage.InnerHtml  = strERRORE;
            divLoginMessage.Visible = true;
        }

        if (!IsPostBack)
        {
            hLingua.SelectedValue = objSistema.Naz_id_nazione.ToString();
            idLingua = (objSistema.Naz_id_nazione.IsNull) ? (1) : (Convert.ToInt32(objSistema.Naz_id_nazione.ToString()));
        }

        errMessage            = GetValueDizionarioUI("ERRORE_LOGIN");
        errDisabledUser       = GetValueDizionarioUI("LOGIN_USER_DISABLED");
        infoProject.InnerText = GetValueDizionarioUI("MSG_INFO_PROJECT");
    }
Пример #3
0
    /// <summary>
    /// Reset della password. Viene inviata una mail all'utente con la nuova password.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ButtonReset_Click(object sender, EventArgs e)
    {
        try
        {
            string emailDestinatario = string.Empty;

            BusinessObjects.ConfigurationSetting objConfigurationSetting = new BusinessObjects.ConfigurationSetting();
            string emailMittente = objConfigurationSetting.getValue("EmailNoReply");

            string  idDestinatario = string.Empty;
            string  Password       = objUtilita.GenerateRandomPassword();
            Utente  objUtente      = new Utente();
            Clienti objClienti     = new Clienti();
            objUtente.ReadByUser(InputUser.Text);
            emailDestinatario = objUtente.Ute_email.ToString();

            objClienti.Read(objUtente.Cli_id_cliente, qCultureInfoName);

            if (objUtente.Ute_id_utente.IsNull)
            {
                idDestinatario = "";
            }
            else
            {
                idDestinatario = objUtente.Ute_id_utente.ToString();
            }

            MailMessage email = new MailMessage();
            MailAddress oFrom = new MailAddress(emailMittente);
            email.From = oFrom;
            //Devo prima cancellare i valori precedenti.
            email.To.Clear();
            email.IsBodyHtml = true;
            email.Priority   = MailPriority.Normal;
            email.Subject    = "Invio / Reset password di accesso";
            email.Body       = FormattaEmail(Password, objClienti.Cli_link_taf.ToString());

            if (idDestinatario == "")
            {
                divLoginMessage.Visible = true;
                LabelMessage.InnerText  = "Errore durante il reset della password User Id non presente o errato.";
                LabelMessage.Style.Add("color", "red");
            }
            else
            {
                objUtente.Ute_id_utente = Convert.ToInt32(idDestinatario);
                objUtente.Read();

                email.To.Add(emailDestinatario);
                SendEmail(email);

                objUtente.Ute_password        = EncryptPwd(Password);
                objUtente.Ute_expiration_date = DateTime.Now.AddDays(-1);

                objUtente.Update();

                divLoginMessage.Visible = true;
                LabelMessage.InnerText  = "Password resettata correttamente, controllare la casella di posta elettronica.";
            }
        }
        catch (Exception ex)
        {
            strERRORE = ex.Message;
            ExceptionPolicy.HandleException(ex, "Propagate Policy");
        }
    }