Example #1
0
        public ViewResult Login_update(LoginViewModel model)
        {
            int             _id           = 0;
            Sistema_bll     sistema_Class = new Sistema_bll(_connection);
            string          sLogin        = Session["hashfname"].ToString();
            TAcessoFunction tacesso_Class = new TAcessoFunction();
            string          _oldPwd       = "";

            if (Session["hashfunc"].ToString() == "S")
            {
                _oldPwd = tacesso_Class.DecryptGTI(sistema_Class.Retorna_User_Password(Session["hashlname"].ToString()));
            }
            else
            {
                Usuario_web user = sistema_Class.Retorna_Usuario_Web(Session["hashlname"].ToString());
                _id     = user.Id;
                _oldPwd = Functions.Decrypt(user.Senha);
            }


            if (model.Senha != _oldPwd)
            {
                ViewBag.Result = "Senha atual não confere!";
            }
            else
            {
                if (Session["hashfunc"].ToString() == "N")
                {
                    Exception ex = sistema_Class.Alterar_Usuario_Web_Senha(_id, Functions.Encrypt(model.Senha2));
                    if (ex != null)
                    {
                        ViewBag.Result = "Erro, senha não alterada";
                    }
                    else
                    {
                        ViewBag.Result = "Sua senha foi alterada, por favor efetue login novamente";
                        return(View("sysMenu"));
                    }
                }
                else
                {
                    Usuario reg = new Usuario {
                        Nomelogin = Session["hashlname"].ToString(),
                        Senha     = tacesso_Class.Encrypt128(model.Senha2)
                    };
                    Exception ex = sistema_Class.Alterar_Senha(reg);
                    if (ex != null)
                    {
                        ViewBag.Result = "Erro, senha não alterada";
                    }
                    else
                    {
                        ViewBag.Result = "Sua senha foi alterada, por favor efetue login novamente";
                    }
                }
            }
            return(View(model));
        }
Example #2
0
 private void GravarButton_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(Pwd1Text.Text) || String.IsNullOrEmpty(Pwd2Text.Text))
     {
         MessageBox.Show("Digite a nova senha e confirme a senha.", "Erro de gravação", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         if (string.Compare(Pwd1Text.Text, Pwd2Text.Text) != 0)
         {
             MessageBox.Show("Confirmação da senha diferente da senha digitada.", "Erro de gravação", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             if (Pwd1Text.Text.Length < 6)
             {
                 MessageBox.Show("Senha deve ter no mínimo 6 caracteres.", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 string          _connection       = gtiCore.Connection_Name();
                 Sistema_bll     sistemaRepository = new Sistema_bll(_connection);
                 string          sPwd     = sistemaRepository.Retorna_User_Password(LoginText.Text);
                 TAcessoFunction _tAcesso = new TAcessoFunction();
                 if (!string.IsNullOrEmpty(sPwd) && _tAcesso.DecryptGTI(sPwd) != PwdText.Text)
                 {
                     MessageBox.Show("Senha atual inválida!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     GTI_Models.Models.Usuario reg = new GTI_Models.Models.Usuario {
                         Nomelogin = LoginText.Text.ToUpper(),
                         Senha     = _tAcesso.Encrypt128(Pwd1Text.Text)
                     };
                     Exception ex = sistemaRepository.Alterar_Senha(reg);
                     if (ex != null)
                     {
                         ErrorBox eBox = new ErrorBox("Atenção", "Erro ao gravar nova senha.", ex);
                         eBox.ShowDialog();
                     }
                     else
                     {
                         MessageBox.Show("Senha alterada.", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         LoginText.Enabled   = true;
                         SenhaButton.Enabled = true;
                         LoginButton.Enabled = true;
                         SairButton.Enabled  = true;
                         PwdText.Text        = Pwd1Text.Text;
                         this.Size           = new Size(this.Size.Width, OriginSize);
                     }
                 }
             }
         }
     }
 }
Example #3
0
        protected void AcessoButton_Click(object sender, EventArgs e)
        {
            string sLogin = Login.Text, sNewPwd = Pwd.Text, sOldPwd, sOldPwd2, sName;
            int    UserId;

            if (sLogin == "")
            {
                lblMsg.Text = "Digite o Login!";
            }
            else
            {
                if (sNewPwd == "")
                {
                    lblMsg.Text = "Digite a senha!";
                }
                else
                {
                    Sistema_bll     sistema_Class = new Sistema_bll("GTIconnection");
                    TAcessoFunction tacesso_Class = new TAcessoFunction();
                    sOldPwd = sistema_Class.Retorna_User_Password(sLogin);
                    UserId  = sistema_Class.Retorna_User_LoginId(sLogin);
                    sName   = sistema_Class.Retorna_User_FullName(UserId);
                    if (sOldPwd == null)
                    {
                        lblMsg.Text        = "Usuário/Senha inválido!";
                        Session["pUserId"] = 0;
                    }
                    else
                    {
                        gtiCore.pUserId        = UserId;
                        gtiCore.pUserFullName  = sName;
                        gtiCore.pUserLoginName = sLogin;
                        sOldPwd2 = tacesso_Class.DecryptGTI(sOldPwd);
                        if (sOldPwd2 != sNewPwd)
                        {
                            lblMsg.Text        = "Usuário/Senha inválido!";
                            Session["pUserId"] = 0;
                        }
                        else
                        {
                            lblMsg.Text        = "";
                            Session["pUserId"] = UserId;
                            //Label lbl = Master.FindControl("lblLogin") as Label;
                            //lbl.Text = sName;
                            Response.Redirect("gtiMenu3.aspx");
                        }
                    }
                }
            }
        }
Example #4
0
 protected void OKButton_Click(object sender, EventArgs e)
 {
     if (SenhaAtual.Text.Trim() == "" || NovaSenha.Text.Trim() == "" || Confirmacao.Text.Trim() == "")
     {
         lblMsg.Text = "Preencha todos os campos!";
     }
     else
     {
         Sistema_bll     sistema_Class = new Sistema_bll("GTIconnection");
         TAcessoFunction tacesso_Class = new TAcessoFunction();
         string          _oldPwd       = tacesso_Class.DecryptGTI(sistema_Class.Retorna_User_Password(gtiCore.pUserLoginName));
         if (SenhaAtual.Text != _oldPwd)
         {
             lblMsg.Text = "Senha atual não confere!";
         }
         else
         {
             if (NovaSenha.Text != Confirmacao.Text)
             {
                 lblMsg.Text = "Nova senha e a confirmação de senha são diferentes!";
             }
             else
             {
                 Usuario reg = new Usuario {
                     Nomelogin = gtiCore.pUserLoginName,
                     Senha     = tacesso_Class.Encrypt128(NovaSenha.Text)
                 };
                 Exception ex = sistema_Class.Alterar_Senha(reg);
                 if (ex != null)
                 {
                     lblMsg.Text = "Erro, senha não alterada";
                 }
                 else
                 {
                     gtiCore.pUserId    = 0;
                     Session["pUserId"] = 0;
                     ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "MsgChange();", true);
                     Response.Redirect("Login.aspx");
                 }
             }
         }
     }
 }
Example #5
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (txtLogin.Text.Equals(string.Empty))
            {
                MessageBox.Show("Digite o nome de login.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtPwd.Text.Equals(string.Empty))
            {
                MessageBox.Show("Digite a senha.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            gtiCore.Ocupado(this);
            gtiCore.ServerName = txtServer.Text;

            string      _connection   = gtiCore.Connection_Name();
            Sistema_bll sistema_Class = new Sistema_bll(_connection);

            try {
                string sUser = sistema_Class.Retorna_User_FullName(txtLogin.Text);
                gtiCore.Liberado(this);
                if (string.IsNullOrEmpty(sUser))
                {
                    gtiCore.Liberado(this);
                    MessageBox.Show("Usuário não cadastrado!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string sPwd    = sistema_Class.Retorna_User_Password(txtLogin.Text);
                string sPwdOld = sistema_Class.Retorna_User_Password_Old(txtLogin.Text);

                TAcessoFunction _access  = new TAcessoFunction();
                string          _decrypt = _access.DecryptGTI(sPwdOld);
                if (string.IsNullOrEmpty(_decrypt))
                {
                    gtiCore.Liberado(this);
                    MessageBox.Show("Por favor cadastre uma senha!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SenhaButton_Click(null, null);
                    return;
                }
                else
                {
                    if (string.Compare(txtPwd.Text, _decrypt) != 0)
                    {
                        gtiCore.Liberado(this);
                        MessageBox.Show("Senha inválida.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            } catch (Exception ex) {
                gtiCore.Liberado(this);
                MessageBox.Show(ex.InnerException.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            gtiCore.LastUser = txtLogin.Text.ToUpper();
            gtiCore.UserId   = sistema_Class.Retorna_User_LoginId(txtLogin.Text);
            //gtiCore.LastUser = txtLogin.Text.ToUpper();
            //Properties.Settings.Default.Save();
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.AppSettings.Settings["lastuser"].Value = txtLogin.Text.ToUpper();
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");

            int nId = gtiCore.UserId;

            LoadDBSettings(nId);

            usuarioStruct cUser  = sistema_Class.Retorna_Usuario(nId);
            int?          nSetor = cUser.Setor_atual;

            if (nSetor == null || nSetor == 0)
            {
                Usuario_Setor form = new Usuario_Setor();
                form.nId = nId;
                var result = form.ShowDialog(this);
                if (result != DialogResult.OK)
                {
                    return;
                }
            }
            gtiCore.UpdateUserBinary();
            //Update user Binary
            //string sTmp = sistema_Class.GetUserBinary(nId);
            //int nSize = sistema_Class.GetSizeofBinary();
            //GtiTypes.UserBinary = gtiCore.Decrypt(sTmp);
            //if (nSize > GtiTypes.UserBinary.Length) {
            //    int nDif = nSize - GtiTypes.UserBinary.Length;
            //    sTmp = new string('0', nDif);
            //    GtiTypes.UserBinary += sTmp;
            //}
            //     string h = GtiTypes.UserBinary;
            Close();
            Main f1 = (Main)Application.OpenForms["Main"];

            f1.UserToolStripStatus.Text = gtiCore.LastUser;
            f1.LockForm(false);
            gtiCore.Liberado(this);
        }
Example #6
0
        private void LoginButton_Click(object?sender, EventArgs?e)
        {
            if (LoginText.Text.Equals(string.Empty))
            {
                MessageBox.Show("Digite o nome de login.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (PwdText.Text.Equals(string.Empty))
            {
                MessageBox.Show("Digite a senha.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Ocupado(this);
            gtiProperty.ServerName = ServerText.Text;
            string _connection = gtiProperty.ConnectionString;

            if (string.IsNullOrEmpty(_connection))
            {
                _connection = gtiCore.Connection_Name();
                gtiProperty.ConnectionString = _connection;
            }


            Sistema_bll sistemaRepository = new Sistema_bll(_connection);

            try {
                string sUser = sistemaRepository.Retorna_User_FullName(LoginText.Text);
                //gtiCore.Liberado(this);
                if (string.IsNullOrEmpty(sUser))
                {
                    //gtiCore.Liberado(this);
                    MessageBox.Show("Usuário não cadastrado!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string sPwd = sistemaRepository.Retorna_User_Password(LoginText.Text);
                if (string.IsNullOrEmpty(sPwd))
                {
                    //   gtiCore.Liberado(this);
                    MessageBox.Show("Por favor cadastre uma senha!", "Senha não cadastrada", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SenhaButton_Click(null, null);
                    return;
                }
                else
                {
                    TAcessoFunction _tAcesso = new TAcessoFunction();
                    if (string.Compare(PwdText.Text, _tAcesso.DecryptGTI(sPwd)) != 0)
                    {
                        //     gtiCore.Liberado(this);
                        MessageBox.Show("Senha inválida.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        PwdText.Text = "";
                        return;
                    }
                }
            } catch (Exception ex) {
                //gtiCore.Liberado(this);
                MessageBox.Show(ex.InnerException.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            gtiProperty.ServerName = ServerText.Text.ToUpper();
            gtiProperty.LastUser   = LoginText.Text.ToUpper();
            gtiProperty.UserId     = sistemaRepository.Retorna_User_LoginId(LoginText.Text);

            int           nId    = gtiProperty.UserId;
            usuarioStruct cUser  = sistemaRepository.Retorna_Usuario(nId);
            int?          nSetor = cUser.Setor_atual;

            if (nSetor == null || nSetor == 0)
            {
                //Usuario_Setor form = new Usuario_Setor();
                //form.nId = nId;
                //var result = form.ShowDialog(this);
                //if (result != DialogResult.OK)
                //    return;
            }
            gtiCore.UpdateUserBinary();
            //Update user Binary
            //string sTmp = sistema_Class.GetUserBinary(nId);
            //int nSize = sistema_Class.GetSizeofBinary();
            //GtiTypes.UserBinary = gtiCore.Decrypt(sTmp);
            //if (nSize > GtiTypes.UserBinary.Length) {
            //    int nDif = nSize - GtiTypes.UserBinary.Length;
            //    sTmp = new string('0', nDif);
            //    GtiTypes.UserBinary += sTmp;
            //}
            //     string h = GtiTypes.UserBinary;
            Close();
            Main f1 = (Main)Application.OpenForms["Main"];

            f1.UserToolStripStatus.Text = gtiProperty.LastUser;
            f1.LockForm(false);
            //gtiCore.Liberado(this);
        }
Example #7
0
        public ActionResult Login(LoginViewModel model)
        {
            string         sLogin = model.Usuario.Trim(), sNewPwd = model.Senha, sOldPwd, sOldPwd2, sName;
            LoginViewModel loginViewModel = new LoginViewModel();

            Sistema_bll     sistemaRepository = new Sistema_bll(_connection);
            TAcessoFunction tacesso_Class     = new TAcessoFunction();

            bool bFuncionario = model.Usuario.LastIndexOf('@') > 1 ? false : true;

            Session["hashfunc"] = bFuncionario ? "S" : "N";

            var cookieF = new HttpCookie("2fN*", Functions.Encrypt(bFuncionario ? "S" : "N"));

            cookieF.Expires = DateTime.Now.AddHours(1);
            System.Web.HttpContext.Current.Response.Cookies.Add(cookieF);


            Tributario_bll tributarioRepository = new Tributario_bll(_connection);
            Form_Redirect  fr = new Form_Redirect();

            if (bFuncionario)
            {
                sOldPwd = sistemaRepository.Retorna_User_Password(sLogin);
                int UserId = sistemaRepository.Retorna_User_LoginId(sLogin);
                if (sOldPwd == null)
                {
                    Session.Remove("hashid");
                    ViewBag.Result = "Usuário/Senha inválido!";
                    return(View(loginViewModel));
                }
                else
                {
                    sOldPwd2 = tacesso_Class.DecryptGTI(sOldPwd);
                    if (sOldPwd2 != sNewPwd)
                    {
                        ViewBag.Result = "Usuário/Senha inválido!";
                        Session.Remove("hashid");
                        return(View(loginViewModel));
                    }
                    else
                    {
                        ViewBag.Result    = "";
                        Session["hashid"] = UserId;
                    }
                }

                if (UserId == 0)
                {
                    ViewBag.Result = "Usuário/Senha inválido.";
                    return(View(loginViewModel));
                }

                usuarioStruct _user = sistemaRepository.Retorna_Usuario(UserId);
                if (_user.Ativo == 0)
                {
                    ViewBag.Result = "Usuário inativo.";
                    return(View(loginViewModel));
                }
                else
                {
                    Session["hashlname"]         = _user.Nome_login;
                    Session["hashfname"]         = _user.Nome_completo;
                    Session["hashfiscalitbi"]    = _user.Fiscal_Itbi ? "S" : "N";
                    Session["hashfiscalpostura"] = _user.Fiscal_postura ? "S" : "N";
                    Session["hashfiscalmov"]     = _user.Fiscal_mov ? "S" : "N";
                    Session["hashfiscal"]        = _user.Fiscal ? "S" : "N";
                    if (Session["hashid"] == null)
                    {
                        Session.Add("hashid", _user.Id);
                        Session.Add("hashfname", _user.Nome_completo);
                        Session.Add("hashlname", _user.Nome_login);
                        Session.Add("hashfiscalitbi", "N");
                        Session.Add("hashfiscalpostura", "N");
                        Session.Add("hashfiscalmov", "N");
                        Session.Add("hashfiscal", "N");
                        Session.Add("hashfunc", "N");
                    }
                    int  _userid = Convert.ToInt32(Session["hashid"]);
                    bool _func   = Session["hashfunc"].ToString() == "S" ? true : false;

                    //log
                    //LogWeb regWeb = new LogWeb() {UserId=_userid,Evento=1,Pref=true};
                    //sistemaRepository.Incluir_LogWeb(regWeb);
                    //***

                    List <int> ListaUsoPlataforma = tributarioRepository.Lista_Rodo_Uso_Plataforma_UserEmpresa(_userid, _func);
                    if (ListaUsoPlataforma.Count == 0)
                    {
                        ViewBag.UsoPlataforma = "N";
                    }
                    else
                    {
                        ViewBag.UsoPlataforma = "S";
                    }

                    // **Rememeber me
                    if (model.RememberMe)
                    {
                        var cookie = new HttpCookie("2lG*", Functions.Encrypt(model.Usuario));
                        cookie.Expires = DateTime.Now.AddDays(30);
                        System.Web.HttpContext.Current.Response.Cookies.Add(cookie);

                        cookie         = new HttpCookie("2pW*", Functions.Encrypt(model.Senha));
                        cookie.Expires = DateTime.Now.AddDays(30);
                        System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
                    }
                    else
                    {
                        Response.Cookies["2lG*"].Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies["2pW*"].Expires = DateTime.Now.AddDays(-1);
                    }
                    //******************
                    var cookie2 = new HttpCookie("2lG1H*", Functions.Encrypt(model.Usuario));
                    cookie2.Expires = DateTime.Now.AddHours(1);
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie2);
                    var cookie3 = new HttpCookie("2uC*", Functions.Encrypt(_userid.ToString()));
                    cookie3.Expires = DateTime.Now.AddHours(1);
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie3);

                    if (Session["hashform"] == null)
                    {
                        return(View("../Home/SysMenu"));
                    }
                    else
                    {
                        fr = RedirectToForm(Session["hashform"].ToString());
                    }
                }
            }
            else
            {
                Usuario_web user_web = sistemaRepository.Retorna_Usuario_Web(model.Usuario);
                if (user_web == null)
                {
                    ViewBag.Result = "Usuário/Senha inválido.";
                    return(View(loginViewModel));
                }
                else
                {
                    if (model.Senha != Functions.Decrypt(user_web.Senha))
                    {
                        ViewBag.Result = "Usuário/Senha inválido.";
                        return(View(loginViewModel));
                    }
                    else
                    {
                        if (!user_web.Ativo)
                        {
                            ViewBag.Result = "Esta conta encontra-se inativa.";
                            return(View(loginViewModel));
                        }
                        else
                        {
                            if (user_web.Bloqueado)
                            {
                                ViewBag.Result = "Esta conta encontra-se bloqueada.";
                                return(View(loginViewModel));
                            }
                            else
                            {
                                Session["hashid"]    = user_web.Id;
                                Session["hashlname"] = user_web.Email;
                                Session["hashfname"] = user_web.Nome;
                                Session.Add("hashfiscalitbi", "N");
                                Session.Add("hashfiscal", "N");
                                Session.Add("hashfunc", "N");
                                int  _userid = Convert.ToInt32(Session["hashid"]);
                                bool _func   = Session["hashfunc"].ToString() == "S" ? true : false;

                                //log
                                //LogWeb regWeb = new LogWeb() { UserId = _userid, Evento = 1, Pref = false };
                                //sistemaRepository.Incluir_LogWeb(regWeb);
                                //***
                                // **Rememeber me
                                if (model.RememberMe)
                                {
                                    var cookie = new HttpCookie("2lG*", Functions.Encrypt(model.Usuario));
                                    cookie.Expires = DateTime.Now.AddDays(30);
                                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie);

                                    cookie         = new HttpCookie("2pW*", Functions.Encrypt(model.Senha));
                                    cookie.Expires = DateTime.Now.AddDays(30);
                                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
                                }
                                else
                                {
                                    Response.Cookies["2lG*"].Expires = DateTime.Now.AddDays(-1);
                                    Response.Cookies["2pW*"].Expires = DateTime.Now.AddDays(-1);
                                }
                                //******************
                                var cookie2 = new HttpCookie("2lG1H*", Functions.Encrypt(model.Usuario));
                                cookie2.Expires = DateTime.Now.AddDays(1);
                                System.Web.HttpContext.Current.Response.Cookies.Add(cookie2);
                                var cookie3 = new HttpCookie("2uC*", Functions.Encrypt(user_web.Id.ToString()));
                                cookie3.Expires = DateTime.Now.AddHours(1);
                                System.Web.HttpContext.Current.Response.Cookies.Add(cookie3);



                                List <int> ListaUsoPlataforma = tributarioRepository.Lista_Rodo_Uso_Plataforma_UserEmpresa(_userid, _func);
                                if (ListaUsoPlataforma.Count == 0)
                                {
                                    ViewBag.UsoPlataforma = "N";
                                }
                                else
                                {
                                    ViewBag.UsoPlataforma = "S";
                                }
                                if (Session["hashform"] == null)
                                {
                                    return(View("../Home/SysMenu"));
                                }
                                else
                                {
                                    fr = RedirectToForm(Session["hashform"].ToString());
                                }
                            }
                        }
                    }
                }
            }
            return(RedirectToAction(fr.Action, fr.Controller));
        }