public async Task <SuccessOrError> RevokeToken(string token)
        {
            var oldRefreshToken = await _context.RefreshTokens
                                  .Include(x => x.User)
                                  .SingleOrDefaultAsync(x => x.Token == token);

            if (oldRefreshToken == null)
            {
                return(IdentityErrors.InvalidRefreshToken);
            }

            _context.Remove(oldRefreshToken);
            await _context.SaveChangesAsync();

            return(SuccessOrError.FromSuccess());
        }
        public async Task <SuccessOrError> Register(string emailAddress, string password, string userName)
        {
            var emailAddressTaken = await _context.Users
                                    .AnyAsync(x =>
                                              x.EmailAddress.ToLower() == emailAddress.ToLower() ||
                                              x.UserName.ToLower() == userName.ToLower());

            if (emailAddressTaken)
            {
                return(IdentityErrors.EmailTaken);
            }

            var hashedPassword = new SimpleHash().Compute(password);
            var newUser        = User.Create(emailAddress, hashedPassword, userName);
            await _context.Users.AddAsync(newUser);

            await _context.SaveChangesAsync();

            return(SuccessOrError.FromSuccess());
        }
Exemplo n.º 3
0
        public async Task <SuccessOrError> Handle(Guid userId)
        {
            var user = await _context.Users.SingleOrDefaultAsync(x => x.Id == userId);

            if (user == null)
            {
                return(CommonErrors.UserNotExist);
            }

            if (user.WasSetup)
            {
                return(SuccessOrError.FromSuccess());
            }

            await InitializeDefaultExpenseTypes(user.Id);

            user.Setup();
            await _context.SaveChangesAsync();

            return(SuccessOrError.FromSuccess());
        }