//
        // GET: /Authentication/
        public JsonResult Login(string mail, string pass)
        {
            var authBll = new Domain.BLL.AuthenticationBLL();
            var people = authBll.Authorize(mail);
            if (people == null)
            {
                return Json(new { success = false, error = "Email inválido" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                if (people.Senha == new Utils.Cryptography.EncryptMd5().GetHash(pass))
                {
                    var token = authBll.GetToken(people.ID, 15);
                    //FormsAuthentication.SetAuthCookie(mail, false);
                    //Session.SetLoggedUser(people);
                    return Json(new
                    {
                        success = true,
                        user = new
                        {
                            id = people.ID,
                            token = token.Token,
                            name = people.Nome,
                            lastName = people.Sobrenome
                        }

                    }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { success = false, error = "Senha inválida" }, JsonRequestBehavior.AllowGet);
                }
            }
        }
        public ActionResult Autorize(string mail, string pass, string returnUrl)
        {
            var model = new Models.Authentication.IndexVM();

            model.UserMail = mail;
            var authBll = new Domain.BLL.AuthenticationBLL();
            var user = authBll.Authorize(mail);
            if (user != null)
            {
                if (user.Senha == new Utils.Cryptography.EncryptMd5().GetHash(pass))
                {
                    var peopleBll = new Domain.BLL.PeopleBLL();
                    user.PessoaEmpresas = peopleBll.GetPeopleCustomers(user.ID);
                    var customerBll = new Domain.BLL.CustomerBLL();
                    foreach (var peopleCustomer in user.PessoaEmpresas)
                    {
                        peopleCustomer.Empresas = customerBll.GetCustomer(peopleCustomer.EmpresaId);
                    }
                    Session.SetLoggedUser(user);
                    //Let us now set the authentication cookie so that we can use that later.
                    FormsAuthentication.SetAuthCookie(mail, false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    model.Error = "Senha Inválida";
                }
            }
            else
            {
                model.Error = "Email não encontrado";
            }
            return RedirectToAction("Index", new { error = model.Error });
        }