Ejemplo n.º 1
0
        public override void Error(string message)
        {
            base.Error(message);

            var log = new LogRecord
            {
                LogLevel     = LogLevel.Error,
                ShortMessage = message,
                //CreatedOnUtc = DateTime.UtcNow
                CreatedOnUtc = DateTime.Now
            };

            logRepository.CreateAsync(log);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> _LoginHomeForm(LoginViewModel model, string returnUrl)
        {
            var modelParent = new HomeLoginViewModel();

            modelParent.LoginHomeViewModel    = model;
            modelParent.RegisterHomeViewModel = new RegisterHomeViewModel();

            if (!ModelState.IsValid)
            {
                return(View(modelParent));
            }

            // 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.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                var user = await UserManager.FindAsync(model.Email, model.Password);

                if (UserManager.IsInRole(user.Id, "CustomerUser") || UserManager.IsInRole(user.Id, "CustomerAdminUser"))
                {
                    base.CurrentUserEmail    = ((CustomerUser)user).Email;
                    base.CurrentUserId       = ((CustomerUser)user).Id;
                    base.CurrentUserFullName = ((CustomerUser)user).FullName;

                    base.CurrentCustomerID      = ((CustomerUser)user).CustomerID;
                    base.CurrentCustomerCompany = GetCustomer(((CustomerUser)user).CustomerID).Company;

                    base.CurrentUserIsSellerUser        = false;
                    base.CurrentUserEditGlobalVariables = false;
                    base.CurrentUserEditMarginOrPrice   = false;
                    base.CurrentUserSeeCosting          = false;

                    var log = new LogRecord
                    {
                        LogLevel     = LogLevel.Information,
                        ShortMessage = "Login Usuario - (Usuario Cliente: " + model.Email + ")",
                        //CreatedOnUtc = DateTime.UtcNow
                        CreatedOnUtc = DateTime.Now
                    };
                    await logRecordRepository.CreateAsync(log);
                }
                if (UserManager.IsInRole(user.Id, "AdminUser"))
                {
                    base.CurrentUserEmail    = ((AdminUser)user).Email;
                    base.CurrentUserId       = ((AdminUser)user).Id;
                    base.CurrentUserFullName = ((AdminUser)user).FullName;

                    base.CurrentUserIsSellerUser        = true;
                    base.CurrentUserEditGlobalVariables = true;
                    base.CurrentUserEditMarginOrPrice   = true;
                    base.CurrentUserSeeCosting          = true;

                    var log = new LogRecord
                    {
                        LogLevel     = LogLevel.Information,
                        ShortMessage = "Login Usuario - (Usuario Admin: " + model.Email + ")",
                        //CreatedOnUtc = DateTime.UtcNow
                        CreatedOnUtc = DateTime.Now
                    };
                    await logRecordRepository.CreateAsync(log);
                }
                if ((UserManager.IsInRole(user.Id, "SellerUser")) && !UserManager.IsInRole(user.Id, "AdminUser"))
                {
                    base.CurrentUserEmail       = ((SellerUser)user).Email;
                    base.CurrentUserId          = ((SellerUser)user).Id;
                    base.CurrentUserFullName    = ((SellerUser)user).FullName;
                    base.CurrentCustomerCompany = "";

                    base.CurrentUserIsSellerUser        = true;
                    base.CurrentUserEditGlobalVariables = ((SellerUser)user).EditGlobalVariables;
                    base.CurrentUserEditMarginOrPrice   = ((SellerUser)user).EditMarginOrPrice;
                    base.CurrentUserSeeCosting          = ((SellerUser)user).SeeCosting;

                    var log = new LogRecord
                    {
                        LogLevel     = LogLevel.Information,
                        ShortMessage = "Login Usuario - (Usuario Vendedor: " + model.Email + ")",
                        //CreatedOnUtc = DateTime.UtcNow
                        CreatedOnUtc = DateTime.Now
                    };
                    await logRecordRepository.CreateAsync(log);
                }

                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 incorrectos.");
                return(View(modelParent));
            }
        }