Beispiel #1
0
        public JsonResult Login(Domain.Model.RegistroPassWpord_Response model)
        {
            BaseResponse <string> result = new BaseResponse <string>();
            string error = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(model.email))
                {
                    error = "(*) El email es una campo requerido <br/>";
                }

                if (string.IsNullOrEmpty(model.password))
                {
                    error = "(*) El password es una campo requerido";
                }

                if (!string.IsNullOrEmpty(error))
                {
                    throw new Exception(error);
                }

                string clave = MesaDinero.Domain.Helper.Encrypt.EncryptKey(model.password);
                Data.PersistenceModel.Tb_MD_ClienteUsuario login_result = null;
                using (MesaDinero.Data.PersistenceModel.MesaDineroContext context = new Data.PersistenceModel.MesaDineroContext())
                {
                    login_result = context.Tb_MD_ClienteUsuario.FirstOrDefault(x => x.Email.Equals(model.email) && x.Password.Equals(clave));

                    if (login_result == null)
                    {
                        throw new Exception("El email o el password son incorrectos.");
                    }
                }
                //ViewBag.nombreCliente = login_result.NombreCliente;
                //ViewBag.inicialesCliente = login_result.Iniciales;

                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.WindowsAccountName, model.email),
                    new Claim(ClaimTypes.Name, model.email),
                    new Claim(ClaimTypes.Actor, login_result.NombreCliente),
                    new Claim(ClaimTypes.SerialNumber, login_result.vNroDocumento),
                    new Claim(ClaimTypes.Role, ""),
                    new Claim(ClaimTypes.PrimarySid, login_result.IdUsuario.ToString()),
                    new Claim(ClaimTypes.DenyOnlySid, login_result.IdCliente.ToString()),
                    new Claim(ClaimTypes.PostalCode, login_result.TipoCliente.ToString()),
                    new Claim(ClaimTypes.NameIdentifier, model.email),
                    new Claim(ClaimTypes.Email, model.email),
                    new Claim(ClaimTypes.GivenName, login_result.Iniciales),
                    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", model.email)
                };
                var id  = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
                var ctx = Request.GetOwinContext();
                AuthenticationManager.SignIn(id);



                result.success = true;
            }
            catch (Exception ex)
            {
                result.success = false;
                result.error   = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult Index(Domain.Model.RegistroPassWpord_Response model)
        {
            try
            {
                bool error = false;

                if (string.IsNullOrEmpty(model.email))
                {
                    ModelState.AddModelError("", "El email es una campo requerido");
                    error = true;
                }

                if (string.IsNullOrEmpty(model.password))
                {
                    ModelState.AddModelError("", "El password es una campo requerido");
                    error = true;
                }

                if (error)
                {
                    throw new Exception("");
                }

                //  Data.PersistenceModel.Tb_MD_Pre_Clientes cliente = null;
                Data.PersistenceModel.Tb_MD_ClienteUsuario login_result = null;

                using (MesaDinero.Data.PersistenceModel.MesaDineroContext context = new Data.PersistenceModel.MesaDineroContext())
                {
                    string clave = MesaDinero.Domain.Helper.Encrypt.EncryptKey(model.password);
                    //     string clave = model.password;


                    login_result = context.Tb_MD_ClienteUsuario.FirstOrDefault(x => x.Email.Equals(model.email) && x.Password.Equals(clave));


                    if (login_result == null)
                    {
                        ModelState.AddModelError("", "El usuario o password es incorrecto.");
                        error = true;
                    }

                    if (error)
                    {
                        throw new Exception("");
                    }


                    // cliente = login_result.Tb_MD_Pre_Clientes;
                }



                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.WindowsAccountName, model.email),
                    new Claim(ClaimTypes.Name, model.email),
                    new Claim(ClaimTypes.Actor, login_result.NombreCliente),
                    new Claim(ClaimTypes.SerialNumber, login_result.vNroDocumento),
                    new Claim(ClaimTypes.Role, ""),
                    new Claim(ClaimTypes.PrimarySid, login_result.IdUsuario.ToString()),
                    new Claim(ClaimTypes.DenyOnlySid, login_result.IdCliente.ToString()),
                    new Claim(ClaimTypes.PostalCode, login_result.TipoCliente.ToString()),
                    new Claim(ClaimTypes.NameIdentifier, model.email),
                    new Claim(ClaimTypes.Email, model.email),
                    new Claim(ClaimTypes.GivenName, login_result.Iniciales),
                    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", model.email)
                };
                var id  = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
                var ctx = Request.GetOwinContext();
                AuthenticationManager.SignIn(id);

                if (!string.IsNullOrEmpty(model.ReturnUrl))
                {
                    return(Redirect(model.ReturnUrl));
                }
                return(RedirectToAction("", "Inicio"));
            }
            catch (Exception ex)
            {
                return(View(model));
            }
        }
        public ActionResult MyLogin(Domain.Model.RegistroPassWpord_Response model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.email))
                {
                    ModelState.AddModelError("", "El email es una campo requerido");
                }

                if (string.IsNullOrEmpty(model.password))
                {
                    ModelState.AddModelError("", "El password es una campo requerido");
                }

                if (ModelState.Count > 0)
                {
                    throw new Exception("");
                }

                Data.PersistenceModel.Tb_MD_Pre_Clientes clinete = null;

                using (MesaDinero.Data.PersistenceModel.MesaDineroContext context = new Data.PersistenceModel.MesaDineroContext())
                {
                    string clave = Encrypt.EncryptKey(model.password);

                    Data.PersistenceModel.Tb_MD_ClienteUsuario login_result = null;
                    login_result = context.Tb_MD_ClienteUsuario.FirstOrDefault(x => x.Email.Equals(model.email) && x.Password.Equals(clave));


                    if (login_result == null)
                    {
                        ModelState.AddModelError("", "El usuario o password son incorrectos");
                    }

                    if (ModelState.Count > 0)
                    {
                        throw new Exception("");
                    }

                    clinete = context.Tb_MD_Pre_Clientes.FirstOrDefault(x => x.idPreCliente == login_result.IdCliente);
                }


                if (ModelState.Count > 0)
                {
                    throw new Exception("");
                }

                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.WindowsAccountName, model.email),
                    new Claim(ClaimTypes.Name, model.email),
                    new Claim(ClaimTypes.Actor, clinete.vNroDocumento),
                    new Claim(ClaimTypes.Role, ""),
                    new Claim(ClaimTypes.Country, clinete.SecretId.ToString()),
                    new Claim(ClaimTypes.PostalCode, clinete.vTipoCliente.ToString()),
                    new Claim(ClaimTypes.NameIdentifier, model.email),
                    new Claim(ClaimTypes.DenyOnlySid, clinete.idPreCliente.ToString()),
                    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", model.email)
                    //new Claim(ClaimTypes., curUser.UserGroupID.ToString())
                };
                var id  = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
                var ctx = Request.GetOwinContext();
                AuthenticationManager.SignIn(id);

                return(RedirectToAction("", "Inicio"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("", "Acceso", model));
            }
        }