示例#1
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByEmailAsync(model.Email);

                //if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code }, Request.Url.Scheme);
                var mensaje     = string.Format("Para recuperar su contraseña haga clic  <a href=\"{0}\">aqui</a>", callbackUrl);

                var service = new WebVentasServices();

                try
                {
                    var usuario = service.UsuarioService.ObtenerPorApplicationUserId(user.Id);

                    if (usuario == null)
                    {
                        return(View("ForgotPasswordConfirmation"));
                    }

                    var respuesta = "";

                    UniOdonto.Comun.Helper.EnviarCorreo(
                        usuario.Empresa.EmailDe,
                        model.Email,
                        usuario.Empresa.EmailCc, usuario.Empresa.EmailCco,
                        "Recuperar Contraseña",
                        mensaje,
                        usuario.Empresa.SmtpServidor,
                        usuario.Empresa.SmtpUsuario,
                        usuario.Empresa.SmtpClave,
                        usuario.Empresa.SmtpPuerto,
                        usuario.Empresa.SmtpHabilitaSsl,
                        null, ref respuesta);
                }
                finally
                {
                    service.Dispose();
                }

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : false);

            var user = await UserManager.FindAsync(model.UserName, model.Password);

            if (user != null)
            {
                var service = new WebVentasServices();
                try
                {
                    var usuario       = service.UsuarioService.ObtenerPorApplicationUserId(user.Id);
                    var configEmpresa = EmpresaService.ObtenerConfiguracion(usuario.EmpresaId);
                    Context.NumeroDecimales = configEmpresa.Decimales;
                }
                finally
                {
                    service.Dispose();
                }
            }


            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Usuario o Contraseña inválidos.");
                return(View(model));
            }
        }
示例#3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
            {
                return(false);
            }

            if (IsPublicAction)
            {
                return(true);
            }

            var isAuthorized = base.AuthorizeCore(httpContext);

            if (!isAuthorized)
            {
                return(false);
            }

            if (NotValidateMenu)
            {
                return(true);
            }

            var service = new WebVentasServices();

            try
            {
                var userId = httpContext.User.Identity.GetUserId();
                var flag   = service.UsuarioService.IsAuthorizedPage(userId, ModuleName, Action);

                if (!flag)
                {
                    httpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                }
                return(flag);
            }
            finally
            {
                service.Dispose();
            }
        }