Exemple #1
0
        public async Task <bool> ConfirmAccount(string userId)
        {
            var user = await GetUserToManage(userId);

            if (UserConfirmedSpecification.Create().IsSatisfied(user))
            {
                return(false);
            }

            var currentAdmin = GetCurrentAdmin(userId);

            user.ConfirmAccount();

            return(await database.Complete());
        }
Exemple #2
0
        public async Task <AuthResult> SignIn(string email, string password)
        {
            var user = await database.UserRepository.Find(u => u.Email.ToLower() == email.ToLower()) ?? throw new InvalidCredentialsException("Invalid email or password");

            if (!UserConfirmedSpecification.Create().IsSatisfied(user))
            {
                throw new AccountNotConfirmedException("Account has not been activated");
            }

            if (UserBlockedSpecification.Create().IsSatisfied(user))
            {
                throw new BlockException("Your account is blocked");
            }

            if (hashGenerator.VerifyHash(password, user.PasswordHash, user.PasswordSalt))
            {
                var token = await jwtAuthorizationTokenGenerator.GenerateToken(user);

                return(new AuthResult(token, user));
            }

            throw new InvalidCredentialsException("Invalid email or password");
        }
Exemple #3
0
        public async Task <IdentityResult> SignIn(string email, string password)
        {
            var user = await userManager.FindByEmailAsync(email) ?? throw new InvalidCredentialsException("Invalid email address or password");

            if (UserIsExternalSpecification.Create().IsSatisfied(user))
            {
                throw new InvalidCredentialsException("Invalid email address or password");
            }

            if (!UserConfirmedSpecification.Create().IsSatisfied(user))
            {
                throw new AccountNotConfirmedException("Account is not confirmed");
            }

            if (UserBlockedSpecification.Create().IsSatisfied(user))
            {
                throw new BlockException();
            }

            return((await signInManager.CheckPasswordSignInAsync(user, password, false)).Succeeded
                ? new IdentityResult(await jwtAuthorizationTokenGenerator.GenerateToken(user), user)
                : throw new InvalidCredentialsException("Invalid email address or password"));
        }
 public async Task <int> CountAccounts()
 => (await unitOfWork.UserRepository.GetWhere(u => UserConfirmedSpecification.Create().IsSatisfied(u) || string.IsNullOrEmpty(u.PasswordHash))).Count();