コード例 #1
0
        public ActionResult CrearUsuario(RegistroCrearPassWord_Request model)
        {
            BaseResponse <string> result = new BaseResponse <string>();

            try
            {
                result.success = true;
                Domain.DataAccess.RegistroCliente          _regsitroDataAccess = new Domain.DataAccess.RegistroCliente();
                BaseResponse <RegistroPassWpord_Response2> result_             = _regsitroDataAccess.CrearPasswprd(model);

                if (result_.success == true)
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.WindowsAccountName, result_.data.email),
                        new Claim(ClaimTypes.Name, result_.data.email),
                        new Claim(ClaimTypes.Actor, result_.data.NombreCliente),
                        new Claim(ClaimTypes.SerialNumber, result_.data.vNroDocumento),
                        new Claim(ClaimTypes.Role, ""),
                        new Claim(ClaimTypes.PrimarySid, result_.data.IdUsuario.ToString()),
                        new Claim(ClaimTypes.DenyOnlySid, result_.data.IdCliente.ToString()),
                        new Claim(ClaimTypes.PostalCode, result_.data.TipoCliente.ToString()),
                        new Claim(ClaimTypes.NameIdentifier, result_.data.email),
                        new Claim(ClaimTypes.Email, result_.data.email),
                        new Claim(ClaimTypes.GivenName, result_.data.Iniciales),
                        new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", result_.data.email)
                    };
                    var id  = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
                    var ctx = Request.GetOwinContext();
                    AuthenticationManager.SignIn(id);
                }
                else
                {
                    throw new Exception(result_.error);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.error   = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public ActionResult Password(RegistroCrearPassWord_Request model)
        {
            BaseResponse <string> result = new BaseResponse <string>();

            try
            {
                if (model.password.Length < 6 || model.password.Length > 10)
                {
                    throw new Exception("La contraseña debe tener entre 6 a 10 caracteres");
                }

                bool hashLetter = MesaDineroHelper.hashLetter(model.password), hashNumber = MesaDineroHelper.hashNumber(model.password);

                if (!hashLetter || !hashNumber)
                {
                    throw new Exception("La contraseña debe constar de letras y numeros");
                }

                if (model.password != model.rePassword)
                {
                    throw new Exception("Las contraseñas no coinciden. Por favor asegurece de haber escrito bien su contraseña en ambos campos");
                }


                result.success = true;
                Domain.DataAccess.RegistroCliente          _regsitroDataAccess = new Domain.DataAccess.RegistroCliente();
                BaseResponse <RegistroPassWpord_Response2> result_ = _regsitroDataAccess.CrearPasswprd(model);

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

                return(RedirectToAction("", "Inicio"));
            }
            catch (Exception ex)
            {
                result.success = false;
                result.error   = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                TempData["error"] = result.error;
                return(RedirectToAction("Password", new { id = model.sid }));
            }
        }