Пример #1
0
        public async Task <IActionResult> Login(LoginModel model, [FromServices] IGenPasswordHash genPassHash)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            AdministratorUser user = await db.AdministratorUsers.FirstOrDefaultAsync(u => u.Login == model.Login);

            if (user != null)
            {
                if (genPassHash.IsPasswordMathcingHash(model.Password, user.PasswordHash))
                {
                    await Authenticate(user.Id, user.Login, user.Tier); // аутентификация

                    return(RedirectToAction("Products", "Products"));
                }
                else
                {
                    return(RedirectToRoute("ErrorMessage", new { Message = "Password invalid", RedirectRoute = "AdminLogin" }));
                }
            }
            else
            {
                return(RedirectToRoute("ErrorMessage", new { Message = $"Can't find user: {model.Login}", RedirectRoute = "AdminLogin" }));
            }
        }
Пример #2
0
        public async Task <IActionResult> Login(LoginModel model, [FromServices] IGenPasswordHash genPassHash)
        {
            if (ModelState.IsValid)
            {
                Author user = await db.Authors.FirstOrDefaultAsync(u => (u.Nickname == model.Login || u.Email == model.Login));

                if (user != null)
                {
                    if (genPassHash.IsPasswordMathcingHash(model.Password, user.PasswordHash))
                    {
                        await Authenticate(user.Nickname, user.CanPost);

                        return(RedirectToAction("GetIndex", "Display"));
                    }
                    else
                    {
                        return(RedirectToAction("ErrorMessage", "Utility", new { Message = "Password invalid", Action = "Login", Controller = "Account" }));
                    }
                }
                else
                {
                    return(RedirectToAction("ErrorMessage", "Utility", new { Message = $"cant find user {model.Login}", Action = "Login", Controller = "Account" }));
                }
            }
            return(View(model));
        }
Пример #3
0
        /// <summary>
        /// Checks if <c>model</c> is valid
        /// </summary>
        /// <param name="model">Login model</param>
        /// <returns>Status message with validaton information</returns>
        public async Task <IErrorHandler> CheckLogin(LoginModel model)
        {
            var statusMessage = errorHandlerFactory.NewErrorHandler(new Problem
            {
                Entity          = "Login process.",
                RedirectRoute   = AuthenticationRouting.Login,
                UseKeyWithRoute = false
            });

            // check if user exists
            var userAuth = await db.UserAuth.FirstOrDefaultAsync(u => u.Login == model.Login);

            if (userAuth != null)
            {
                // check if password correct with using of IGenPasswordHash service
                if (!genPassHash.IsPasswordMathcingHash(model.Password, userAuth.PasswordHash))
                {
                    statusMessage.AddProblem(new Problem
                    {
                        Entity          = "Password incorrect.",
                        Message         = "User with this password isn't found",
                        RedirectRoute   = AuthenticationRouting.Login,
                        UseKeyWithRoute = false
                    });
                }
            }
            else
            {
                statusMessage.AddProblem(new Problem
                {
                    Entity          = "Username incorrect.",
                    Message         = "User with this username isn't found",
                    RedirectRoute   = AuthenticationRouting.Login,
                    UseKeyWithRoute = false
                });
            }

            return(statusMessage);
        }
Пример #4
0
        /// <summary>
        /// Checks if user is valid password matching <c>passwordOld</c>
        /// </summary>
        /// <param name="key">Login of user to be found</param>
        /// <param name="passwordOld">Password to be compared</param>
        /// <returns>Status message with validaton information</returns>
        public async Task <IErrorHandler> CheckUpdateUserAuthUpdateModelAsync(object key, string passwordOld)
        {
            var statusMessage = await CheckUserExists(key);

            if (statusMessage.IsCompleted)
            {
                // compare password using IGenPasswordHash
                var userAuth = await db.UserAuth.SingleAsync(i => i.Login == (string)key);

                if (!genPasswordHash.IsPasswordMathcingHash(passwordOld, userAuth.PasswordHash))
                {
                    statusMessage.AddProblem(new Problem
                    {
                        Entity          = "User.",
                        EntityKey       = statusMessage.ProblemStatus.EntityKey,
                        Message         = "Old password incorrect.",
                        RedirectRoute   = UserManagmentRouting.Index,
                        UseKeyWithRoute = false
                    });
                }
            }

            return(statusMessage);
        }