Beispiel #1
0
        public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userPool.FindByIdAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("User Not Found", "A user with the given address was not found");
                return(View(model));
            }

            var userManager = _userManager as CognitoUserManager <CognitoUser>;

            var result = await userManager.ConfirmSignUpAsync(user, model.Code, true);

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.Code, error.Description);
                }

                return(View(model));
            }

            return(RedirectToAction(controllerName: "Home", actionName: "Index"));
        }
        public async Task <IActionResult> Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userPool.FindByIdAsync(model.Email).ConfigureAwait(false);

                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false).ConfigureAwait(false);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("LoginError", "Email and Password do not match");
                }
            }
            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _pool.FindByIdAsync(model.Email);// GetUser(model.Email);

            if (user != null)
            {
                ModelState.AddModelError("UserExists", "User with this email already exists");
                return(View(model));
            }

            user.Attributes.Add(CognitoAttribute.Name.ToString(), model.Email);
            var userCreated = await _userManager.CreateAsync(user, model.Password);

            if (userCreated.Succeeded)
            {
                return(RedirectToAction("Confirm"));
            }
            return(View(model));
        }
        public CognitoUser FindUser(string userName)
        {
            try
            {
                using (AmazonCognitoIdentityProviderClient userProvider = GetCognitoIdentityProvider())
                {
                    string poolID       = CognitoSettings.Values.UserPoolId;
                    string clientID     = CognitoSettings.Values.UserPoolClientId;
                    string clientSecret = CognitoSettings.Values.UserPoolClientSecret;

                    var pool = new CognitoUserPool(poolID,
                                                   clientID, userProvider, clientSecret);


                    var user = pool.FindByIdAsync(userName).ConfigureAwait(false).GetAwaiter().GetResult();

                    return(user as CognitoUser);
                }
            }
            catch (AmazonCognitoIdentityProviderException e)
            {
                throw new CognitoServiceException("Failed to find the Cognito User by userName", e);
            }
        }