public void CanNotConnectToCrowdApi_AuthenticateUser()
        {
            SetUpConnectionToAnUnboundPort();

            Action act = () => _crowdAuthenticatedUserClient.AuthenticateUser(_userName, _password);

            ShouldBeUnableToConnect(act);
        }
Beispiel #2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            IdentityUser authenticatedUser;

            try
            {
                authenticatedUser = _authenticatedUserClient.AuthenticateUser(model.UserName, model.Password);
            }
            catch (AuthenticatedUserClientException)
            {
                ModelState.AddModelError(string.Empty, _apiExceptionMessage);
                return(View(model));
            }

            if (authenticatedUser == null)
            {
                ModelState.AddModelError(string.Empty, _unauthenticatedErrorMessage);
                return(View(model));
            }
            await _signInManager.SignInAsync(authenticatedUser, model.RememberMe, rememberBrowser : true);

            var profile = _userProfileAccessManager.GetProfilesForUser(model.UserName).FirstOrDefault();

            if (profile == null)
            {
                // The user doesn't have permission to use *any* profiles
                ModelState.AddModelError("", "You do not have permission to use any AWS profiles. Contact an administrator.");
                return(View(model));
            }
            Session[WebPortalConstants.ActiveProfileId] = profile.Id;

            if (!returnUrl.IsNullOrWhiteSpace() && Url.IsLocalUrl(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }