示例#1
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie != null)
            {
                FormsAuthenticationTicket ticket   = FormsAuthentication.Decrypt(cookie.Value);
                FormsIdentity             identity = new FormsIdentity(ticket);

                byte[]     buffer  = Convert.FromBase64String(ticket.UserData);
                UserLogado userLog = new UserLogado();
                using (Stream myStream = new MemoryStream(buffer))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    userLog = (UserLogado)formatter.Deserialize(myStream);
                }

                //MVCUser user = new MVCUser(identity, new string[] {"Adm","FInanceiro" });
                MvcUser user = new MvcUser(identity, null)
                {
                    ID             = userLog.ID,
                    Nome           = userLog.Nome,
                    PathFotoPerfil = userLog.PathFotoPerfil
                };

                HttpContext.Current.User = user;
            }
        }
示例#2
0
        private static string SerializarUser(UserLogado user)
        {
            string          userData = null;
            BinaryFormatter bf       = new BinaryFormatter();

            using (MemoryStream stream = new MemoryStream())
            {
                bf.Serialize(stream, user);
                stream.Position = 0;
                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, (int)stream.Length);
                userData = Convert.ToBase64String(buffer);
            }

            return(userData);
        }
        public ActionResult Index(Models.DadosTabela.Login login)
        {
            UserLogado cl = tLogin.testeLogin(login);

            //string acesso = tLogin.testeAcesso(login);

            if (cl.Login1.Loguin == login.Loguin && cl.Login1.Senha == login.Senha)
            {
                Session["StatusLogin"]   = "******";
                Session["ClienteLogado"] = cl;

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                TempData["ErroLogin"] = "******";
                return(View());
            }
        }
示例#4
0
        private void CriarCookie(bool lembrar, BLLResponse <Usuario> response)
        {
            UserLogado user = new UserLogado
            {
                ID             = response.Data.ID,
                Nome           = response.Data.Nome,
                PathFotoPerfil = response.Data.PathFotoPerfil
            };

            string userData = SerializarUser(user);

            FormsAuthenticationTicket ticket =
                new FormsAuthenticationTicket(1, FormsAuthentication.FormsCookieName, DateTime.Now, DateTime.Now.AddDays(1), lembrar, userData);
            string     cookieEncriptado = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie           = new HttpCookie(FormsAuthentication.FormsCookieName, cookieEncriptado);

            cookie.HttpOnly = true;
            cookie.Expires  = DateTime.Now.AddDays(1);
            Response.Cookies.Add(cookie);
        }
        public ActionResult PageForm(Descricao descricao)
        {
            UserLogado cl = Session["ClienteLogado"] as UserLogado;

            descricao.Coduser = cl.Usuario.Coduser;

            if (clCadDesc.insertCadastro(descricao) == false)
            {
                //TempData["error"] = "true";
                // TempData["StatusCadastro"] = "ERRO";
                ModelState.Clear();
                return(View());
            }
            else
            {
                // TempData["StatusCadastro"] = "OK";

                ModelState.Clear();
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult Index()
        {
            if (Session["StatusLogin"] == "LOGADO")
            {
                Usuario     user  = new Usuario();
                clBuscaDesc busca = new clBuscaDesc();

                var dtHoje = DateTime.Today;

                if (dtHoje.Month == 1)
                {
                    Session["MesAtual"] = "Janeiro";
                }
                else if (dtHoje.Month == 2)
                {
                    Session["MesAtual"] = "Fevereiro";
                }
                else if (dtHoje.Month == 3)
                {
                    Session["MesAtual"] = "Março";
                }
                else if (dtHoje.Month == 4)
                {
                    Session["MesAtual"] = "Abril";
                }
                else if (dtHoje.Month == 5)
                {
                    Session["MesAtual"] = "Maio";
                }
                else if (dtHoje.Month == 6)
                {
                    Session["MesAtual"] = "Junho";
                }
                else if (dtHoje.Month == 7)
                {
                    Session["MesAtual"] = "Julho";
                }
                else if (dtHoje.Month == 8)
                {
                    Session["MesAtual"] = "Agosto";
                }
                else if (dtHoje.Month == 9)
                {
                    Session["MesAtual"] = "Setembro";
                }
                else if (dtHoje.Month == 10)
                {
                    Session["MesAtual"] = "Outubro";
                }
                else if (dtHoje.Month == 11)
                {
                    Session["MesAtual"] = "Novembro";
                }
                else if (dtHoje.Month == 12)
                {
                    Session["MesAtual"] = "Dezembro";
                }
                else
                {
                    Session["MesAtual"] = "ERRO";
                }

                if (Session["StatusLogin"] == "CLI")
                {
                    UserLogado cl = Session["ClienteLogado"] as UserLogado;

                    Session["NomeUser"]      = cl.Usuario.Nomeuser;
                    Session["SobrenomeUser"] = cl.Usuario.Sobrenomeuser;
                }

                if (Session["ClienteLogado"] == null)
                {
                    return(RedirectToAction("Index", "Login"));
                }

                UserLogado us       = Session["ClienteLogado"] as UserLogado;
                var        listDesc = busca.buscaDesc(int.Parse(us.Usuario.Coduser));

                double total = 0;
                for (int i = 0; i < listDesc.Count; i++)
                {
                    total   = total + listDesc[i].Preco;
                    dataAtt = listDesc[i].Datac;
                }

                var listMesAtual = busca.buscaMesAtual(dtHoje.Month, dtHoje.Year, int.Parse(us.Usuario.Coduser));

                double totalMesAtual = 0;

                for (int i = 0; i < listMesAtual.Count; i++)
                {
                    totalMesAtual = totalMesAtual + listMesAtual[i].Preco;
                }

                Session["dataAtt"]       = dataAtt;
                Session["totalMesAtual"] = totalMesAtual;
                Session["TotalGasto"]    = total;
                Session["anoAtual"]      = dtHoje.Year;

                return(View(listDesc));
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }