Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BttConferma_Click(object sender, System.EventArgs e)
        {
            Classi.Sicurezza _Sic    = new Classi.Sicurezza();
            Classi.Utente    _Utente = new TheSite.Classi.Utente();

            txtsPasword.Text = _Sic.EncryptMD5(txtsPasword.Text);
            //txtsPasword.Text = _Sic.EncryptSHA1(txtsPasword.Text);
            try
            {
                int i_IdUtente = _Utente.Login(this);

                if (i_IdUtente > 0)
                {
                    string url = FormsAuthentication.GetRedirectUrl(txtsUserName.Text, false);
                    //					FormsAuthentication.SetAuthCookie(txtsUserName.Text,false);
                    //
                    //					Response.Redirect(url);
                    string[] a_roles = _Utente.GetRuoli(txtsUserName.Text);

                    string roleStr = "";
                    double ore     = 8;
                    foreach (String role in a_roles)
                    {
                        //if(role.ToUpper()=="CALLCENTER")
                        //	ore=8;
                        roleStr += role;
                        roleStr += ";";
                    }

                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        1,
                        txtsUserName.Text,
                        DateTime.Now,                                           // issue time
                        DateTime.Now.AddHours(ore),                             // expires every hour
                        false,                                                  // don't persist cookie
                        roleStr,                                                // roles
                        FormsAuthentication.FormsCookiePath);

                    // Encrypt the ticket.
                    string encTicket = FormsAuthentication.Encrypt(ticket);

                    // Create the cookie.
                    Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

                    // Redirect back to original URL.
                    Response.Redirect(url);
                }
                else
                {
                    PanelMess.ShowError("Utenza o Password errati", true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //PanelMess.ShowError("Errore interno al Data Base.", true);
                PanelMess.ShowError(ex.Message.ToString(), true);
            }
        }
        /// <summary>
        /// Popola le listbox dei ruoli
        /// </summary>
        private void AggiornaListBox()
        {
            _DsListBox = new DataSet();

            this.CreaTabelle();

            if (itemId > 0)
            {
                Classi.Utente _Utente = new TheSite.Classi.Utente();

                DataView o_Dv = new DataView(_Utente.GetRuoli(itemId).Tables[0]);
                if (o_Dv.Count > 0)
                {
                    foreach (DataRowView o_Drv in o_Dv)
                    {
                        DataRow o_Dr = _DsListBox.Tables["UtentiRuoli"].NewRow();
                        o_Dr["Id"]       = o_Drv["RUOLO_ID"].ToString();
                        o_Dr["Ruolo"]    = o_Drv["DESCRIZIONE"].ToString();
                        o_Dr["IdUtente"] = o_Drv["UTENTE_ID"].ToString();
                        _DsListBox.Tables["UtentiRuoli"].Rows.Add(o_Dr);
                    }
                }
            }
            Session.Add("UtentiRuoli", _DsListBox.Tables["UtentiRuoli"]);

            this.ListBoxRight.DataSource     = _DsListBox.Tables["UtentiRuoli"];
            this.ListBoxRight.DataValueField = "Id";
            this.ListBoxRight.DataTextField  = "Ruolo";
            this.ListBoxRight.DataBind();
            this.ListBoxRight.SelectedIndex = 0;

            Classi.Ruolo _Ruolo = new TheSite.Classi.Ruolo();

            DataView o_DvRuoli = new DataView(_Ruolo.GetData().Tables[0]);

            if (o_DvRuoli.Count > 0)
            {
                foreach (DataRowView o_DrvR in o_DvRuoli)
                {
                    if (ListBoxRight.Items.FindByValue(o_DrvR["ID"].ToString()) == null)
                    {
                        DataRow o_DrR = _DsListBox.Tables["Ruoli"].NewRow();
                        o_DrR["Id"]    = o_DrvR["ID"].ToString();
                        o_DrR["Ruolo"] = o_DrvR["DESCRIZIONE"].ToString();
                        _DsListBox.Tables["Ruoli"].Rows.Add(o_DrR);
                    }
                }
            }

            this.ListBoxLeft.DataSource     = _DsListBox.Tables["Ruoli"];
            this.ListBoxLeft.DataValueField = "Id";
            this.ListBoxLeft.DataTextField  = "Ruolo";
            this.ListBoxLeft.DataBind();
            this.ListBoxLeft.SelectedIndex = 0;
        }