Exemplo n.º 1
0
    protected void ButtonSalva_Click(object sender, EventArgs e)
    {
        SetValues();

        if (objUtente.existUser() != 0)
        {
            lblMessaggioError.InnerText = getDizionarioUI("ERR_UTE_VALORI_DUPLICATI");
            divRecordError.Visible      = true;
        }
        else
        {
            string PwdResetNotExist = getDizionarioUI("PWD_RESET_NOT_EXIST");

            switch (qMODALITA)
            {
            case "NEW":
                try
                {
                    //Ricavo dal cliente la password di default per settarla
                    objClienti.Read(Convert.ToInt32(DropDownListCliente.SelectedValue), qCultureInfoName);
                    if (objClienti.Cli_password_reset.ToString() != "" && !objClienti.Cli_password_reset.IsNull)
                    {
                        Database      db = DatabaseFactory.CreateDatabase("CONNECTION_STRING");
                        DbConnection  c  = db.CreateConnection();
                        DbTransaction t  = null;

                        try
                        {
                            c.Open();
                            t = c.BeginTransaction();

                            objUtente.Ute_password  = EncryptPwd(objClienti.Cli_password_reset.ToString());
                            objUtente.Ute_creato_da = base.idLoggedUser;
                            objUtente.Create(db, t);

                            RuoliUtente objRuoliUtente = new RuoliUtente();
                            objRuoliUtente.Ute_id_utente = objUtente.Ute_id_utente;
                            objRuoliUtente.CreateByDefaultCliente(Convert.ToInt32(DropDownListCliente.SelectedValue), db, t);

                            CrossUtenteWorkflow objCrossUtenteWorkflow = new CrossUtenteWorkflow();
                            objCrossUtenteWorkflow.Ute_id_utente = objUtente.Ute_id_utente;
                            objCrossUtenteWorkflow.CreateByDefaultCliente(Convert.ToInt32(DropDownListCliente.SelectedValue), db, t);

                            t.Commit();
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                t.Rollback();
                            }
                            catch (Exception ex2)
                            {
                                ex2.Data.Add("Class.Method", "frm_MSE_UTE.ButtonSalva.Rollback");
                                ex2.Data.Add("SQL", "Rollback error");
                            }

                            if (ex != null)
                            {
                                ex.Data["Class.Method"] += "frm_MSE_UTE.ButtonSalva";
                                ex.Data.Add("SQL", ex.Message);
                                throw ex;
                            }
                        }
                        finally
                        {
                            c.Close();
                        }

                        Response.Redirect("frm_MSE_UTE.aspx?MODALITA=EDIT&UTE_ID_UTENTE=" + objUtente.Ute_id_utente, false);
                    }
                    else
                    {
                        string strScript = @"<script type='text/javascript'>
                                alert('" + PwdResetNotExist + @"');                                
                                </script>";

                        if (!this.ClientScript.IsStartupScriptRegistered("Alert_JS"))
                        {
                            this.ClientScript.RegisterStartupScript(GetType(), "Alert_JS", strScript);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Gestione messaggistica all'utente e trace in DB dell'errore
                    ExceptionPolicy.HandleException(ex, "Propagate Policy");
                }
                break;

            case "EDIT":
                try
                {
                    //Update record relations
                    objUtente.Ute_aggiornato_da = base.idLoggedUser;
                    objUtente.Ute_id_utente     = qUTE_ID_UTENTE;
                    objUtente.Update();
                    Response.Redirect("frm_MSE_UTE.aspx?MODALITA=EDIT&UTE_ID_UTENTE=" + objUtente.Ute_id_utente, false);
                }
                catch (Exception ex)
                {
                    // Gestione messaggistica all'utente e trace in DB dell'errore
                    ExceptionPolicy.HandleException(ex, "Propagate Policy");
                }
                break;
            }

            GetValues();

            Page.ClientScript.RegisterStartupScript(this.GetType(), "varMODALITA", "$('#modalPage', parent.document).modal('hide');", true);
        }
    }
Exemplo n.º 2
0
    protected void ButtonInviaResetPwd_Click(object sender, EventArgs e)
    {
        try
        {
            string valore = "";
            int    contatoreUtentiSelez = 0;
            string emailAddress         = string.Empty;
            string password             = string.Empty;
            string msg            = string.Empty;
            string strChangePwdOK = GetValueDizionarioUI("PWD_INVIATE_OK");
            string strChangePwdKO = GetValueDizionarioUI("PWD_INVIATE_KO");
            char[] charSeparators = new char[] { ';' };

            if (this.fieldSelected.Value != "")
            {
                //Creo nuova riga nella hystory
                valore = fieldSelected.Value;
                string[] arrFieldSelected;
                arrFieldSelected = valore.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
                string emailMittente = ConfigurationManager.AppSettings["EmailMittente"];

                if (arrFieldSelected.Length > 0)
                {
                    for (int i = 0; i < arrFieldSelected.Length; i++)
                    {
                        objUtente.Ute_id_utente = Convert.ToInt32(arrFieldSelected[contatoreUtentiSelez].Replace("val_", ""));
                        objUtente.Read();
                        objClienti.Read(Convert.ToInt32(objUtente.Cli_id_cliente), qCultureInfoName);

                        emailAddress = (objUtente.Ute_email.IsNull) ? ("") : (objUtente.Ute_email.ToString());


                        MailMessage email = new MailMessage();
                        MailAddress oFrom = new MailAddress(emailMittente);
                        email.From       = oFrom;
                        email.IsBodyHtml = true;
                        email.Priority   = MailPriority.Normal;
                        email.Subject    = "Invio Password";
                        email.To.Clear();
                        email.To.Add(emailAddress);
                        email.Body = string.Empty;

                        if (emailAddress != "")
                        {
                            password   = objUtilita.GenerateRandomPassword();
                            msg        = "<p>Il link per accedere all'applicazione &egrave; : <strong><a href='" + objClienti.Cli_link_taf.ToString() + "'>" + objClienti.Cli_link_taf.ToString() + "</a></strong></p>";
                            msg       += "<p>La sua UserId &egrave; : <strong>" + objUtente.Ute_user_id.ToString() + "</strong></p>";
                            msg       += "<p>La sua Password &egrave; : <strong>" + password + "</strong></p>";
                            email.Body = Sistema.FormattaEmailPwd(msg);
                            Sistema.SendEmail(email);
                            objUtente.Ute_password         = EncryptPwd(password);
                            objUtente.Ute_flag_pwd_inviata = 1;
                            objUtente.Ute_data_invio_pwd   = DateTime.Now;
                            objUtente.Ute_expiration_date  = DateTime.Today.AddDays(-1);
                            objUtente.Update();
                            string strScript = @"<script type='text/javascript'>
                                alert('" + strChangePwdOK + @"');
                                </script>";

                            if (!this.ClientScript.IsStartupScriptRegistered("Alert_JS"))
                            {
                                this.ClientScript.RegisterStartupScript(GetType(), "Alert_JS", strScript);
                            }
                        }
                        contatoreUtentiSelez++;
                    }
                }
            }
            else
            {
                string strScript = "<script type='text/javascript'>alert('" + strChangePwdKO + "')</script>";
                if (!this.ClientScript.IsStartupScriptRegistered("Alert_JS"))
                {
                    this.ClientScript.RegisterStartupScript(GetType(), "Alert_JS", strScript);
                }
                throw new System.Exception("GridViewFatture:no DataKey objects Selected.");
            }
        }
        catch (Exception ex)
        {
            // Gestione messaggistica all'utente e trace in DB dell'errore
            ExceptionPolicy.HandleException(ex, "Propagate Policy");
            Response.End();
        }
    }
Exemplo n.º 3
0
    private void ButtonChangePassword_Click(object sender, EventArgs e)
    {
        int maxPassword = 1;

        strERRORE = "";
        bool passwordVerified = false;
        bool passwordValid    = false;

        try
        {
            objUtente.Ute_id_utente = Convert.ToInt32(Session["UTE_ID_UTENTE"]);
            objUtente.Read();

            if (Session["oldPassword"] == null)
            {
                oldPassword            = (string)objUtente.Ute_password;
                Session["oldPassword"] = oldPassword;
            }
            else
            {
                oldPassword = Session["oldPassword"].ToString();
            }

            if (EncryptPwd(InputOldPassword.Text).CompareTo(oldPassword) == 0)
            {
                // Recupero Password
                objUtenteTrc.Ute_id_utente = Convert.ToInt32(Session["UTE_ID_UTENTE"]);
                objUtenteTrc.Ute_password  = EncryptPwd(InputNewPassword.Text);

                try
                {
                    if (objSistema.Sis_max_password_consecutive != -1)
                    {
                        maxPassword = (int)objSistema.Sis_max_password_consecutive;
                    }

                    passwordVerified   = objUtenteTrc.CheckPassword(maxPassword);      //objUtente-> in Utente.cs
                    errMaxRipetizioni += " " + maxPassword.ToString() + " password.";
                }
                catch (Exception ex)
                {
                    strERRORE = ex.Message;

                    // Gestione messaggistica all'utente e trace in DB dell'errore
                    ExceptionPolicy.HandleException(ex, "Propagate Policy");
                }

                //Verifica caratteri obbligatori
                passwordValid = PasswordConstraints(InputNewPassword.Text);
                if (!passwordValid)
                {
                    Base_Alert(pwdAvviso);
                }
                else if (!passwordVerified)
                {
                    Base_Alert(errMaxRipetizioni);
                }
                else
                {
                    try
                    {
                        objUtente.Ute_id_utente = Convert.ToInt32(Session["UTE_ID_UTENTE"]);
                        objUtente.Read();
                        objUtente.Ute_password = EncryptPwd(InputNewPassword.Text);

                        if (objSistema.Sis_durata_password != -1)
                        {
                            objUtente.Ute_expiration_date = DateTime.Now.AddMonths((int)objSistema.Sis_durata_password);
                        }
                        else
                        {
                            objUtente.Ute_expiration_date = SqlDateTime.Null;
                        }

                        objUtente.Update();

                        objUtenteTrc.Ute_id_utente = Convert.ToInt32(Session["UTE_ID_UTENTE"]);
                        objUtenteTrc.Ute_password  = EncryptPwd(InputNewPassword.Text);
                        objUtenteTrc.Create();

                        if (objSistema.Sis_flag_visualizza_info_page == 1)
                        {
                            pagina = "frm_LGN_2.aspx";
                        }
                        else
                        {
                            pagina = "../HOME/mainpage.aspx";
                        }

                        string js_Redirect = "alert('" + GetValueDizionarioUI("CAMBIO_PWD") + "');document.location.href='" + pagina + "';";
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "msgRedirect", js_Redirect, true);
                    }
                    catch (Exception ex)
                    {
                        // Gestione messaggistica all'utente e trace in DB dell'errore
                        ExceptionPolicy.HandleException(ex, "Propagate Policy");
                    }
                }
            }
            else
            {
                Base_Alert(GetValueDizionarioUI("ERR_MSG_VECCHIA_PWD_ERRATA"));
            }
        }
        catch (Exception ex)
        {
            // Gestione messaggistica all'utente e trace in DB dell'errore
            ExceptionPolicy.HandleException(ex, "Propagate Policy");
        }
    }
Exemplo n.º 4
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");
        }
    }