示例#1
0
        public ActionResult Authentication(AuthenticationPostModel postModel)
        {
            var model = new AuthenticationViewModel();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var userName = postModel.Username;
            var password = _passwordHashProvidcer.Hash(postModel.Password, _salt);
            var user     = _unitOfWork.UserRepository.GetUserByUsernameAndPassword(userName, password);

            if (user != null)
            {
                FormsAuthentication.SetAuthCookie(user.UserName, false);
                // Not a good practice
                Session[SessionUserKey] = user;
                // Map User to Model
                model = new AuthenticationViewModel()
                {
                    IdHashed = _encryptionProvider.Encrypt(user.Id.ToString(), _key, _vector),
                    Name     = user.Name,
                    EMail    = user.EMail.SanitizeEmail()
                };
            }
            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> Authentication(AuthenticationPostModel request)
        {
            var serviceRepsonse = await userService.AuthenticateAsync(request.Username, request.Password);

            return(Ok(serviceRepsonse));
        }