public async Task <IUserAuth> UpdateUserAuthAsync(IUserAuth existingUser, IUserAuth newUser, string password, CancellationToken token = default)
        {
            newUser.ValidateNewUser(password);

            await AssertNoExistingUserAsync(mongoDatabase, newUser, existingUser, token).ConfigAwait();

            newUser.Id = existingUser.Id;
            newUser.PopulatePasswordHashes(password, existingUser);
            newUser.CreatedDate  = existingUser.CreatedDate;
            newUser.ModifiedDate = DateTime.UtcNow;
            await SaveUserAsync(newUser, token).ConfigAwait();

            return(newUser);
        }
Exemplo n.º 2
0
        public IUserAuth CreateUserAuth(IUserAuth newUser, string password)
        {
            newUser.ValidateNewUser(password);

            AssertNoExistingUser(newUser);

            newUser.PopulatePasswordHashes(password);
            newUser.CreatedDate  = DateTime.UtcNow;
            newUser.ModifiedDate = newUser.CreatedDate;

            newUser = UserAuthRepository.CreateUpdate(new JarsUserAuth(newUser), MODIEFIED_BY);

            return(newUser);
        }
        public IUserAuth UpdateUserAuth(IUserAuth existingUser, IUserAuth newUser, string password)
        {
            newUser.ValidateNewUser(password);

            AssertNoExistingUser(mongoDatabase, newUser, existingUser);

            newUser.Id = existingUser.Id;
            newUser.PopulatePasswordHashes(password, existingUser);
            newUser.CreatedDate  = existingUser.CreatedDate;
            newUser.ModifiedDate = DateTime.UtcNow;
            SaveUser(newUser);

            return(newUser);
        }
Exemplo n.º 4
0
        public IUserAuth CreateUserAuth(IUserAuth newUser, string password)
        {
            newUser.ValidateNewUser(password);

            AssertNoExistingUser(newUser);

            newUser.PopulatePasswordHashes(password);
            newUser.CreatedDate  = DateTime.UtcNow;
            newUser.ModifiedDate = newUser.CreatedDate;

            var nhSession = GetCurrentSessionFn(sessionFactory);

            nhSession.Save(new UserAuthNHibernate(newUser));

            return(newUser);
        }
Exemplo n.º 5
0
        public IUserAuth CreateUserAuth(IUserAuth newUser, string password)
        {
            newUser.ValidateNewUser(password);

            AssertNoExistingUser(newUser);

            newUser.PopulatePasswordHashes(password);
            newUser.CreatedDate  = DateTime.UtcNow;
            newUser.ModifiedDate = newUser.CreatedDate;

            using var session = documentStore.OpenSession();
            session.Store(newUser);
            UpdateIntKey(newUser);
            session.SaveChanges();
            return(newUser);
        }
        public async Task <IUserAuth> CreateUserAuthAsync(IUserAuth newUser, string password, CancellationToken token = default)
        {
            newUser.ValidateNewUser(password);

            await AssertNoExistingUserAsync(newUser, token : token).ConfigAwait();

            newUser.PopulatePasswordHashes(password);
            newUser.CreatedDate  = DateTime.UtcNow;
            newUser.ModifiedDate = newUser.CreatedDate;

            using var session = documentStore.OpenSession();
            session.Store(newUser);
            session.SaveChanges();

            return(newUser);
        }
Exemplo n.º 7
0
        public async Task <IUserAuth> CreateUserAuthAsync(IUserAuth newUser, string password, CancellationToken token = default)
        {
            newUser.ValidateNewUser(password);

            await AssertNoExistingUserAsync(newUser, token : token);

            Sanitize(newUser);

            newUser.PopulatePasswordHashes(password);
            newUser.CreatedDate  = DateTime.UtcNow;
            newUser.ModifiedDate = newUser.CreatedDate;

            await Db.PutItemAsync((TUserAuth)newUser, token : token);

            newUser = DeSanitize(Db.GetItem <TUserAuth>(newUser.Id));
            return(newUser);
        }
Exemplo n.º 8
0
        public virtual IUserAuth UpdateUserAuth(IUserAuth existingUser, IUserAuth newUser, string password)
        {
            newUser.ValidateNewUser(password);

            return(Exec(db =>
            {
                AssertNoExistingUser(db, newUser, existingUser);

                newUser.Id = existingUser.Id;
                newUser.PopulatePasswordHashes(password, existingUser);
                newUser.CreatedDate = existingUser.CreatedDate;
                newUser.ModifiedDate = DateTime.UtcNow;

                db.Save((TUserAuth)newUser);

                return newUser;
            }));
        }
Exemplo n.º 9
0
        public virtual IUserAuth CreateUserAuth(IUserAuth newUser, string password)
        {
            newUser.ValidateNewUser(password);

            return(Exec(db =>
            {
                AssertNoExistingUser(db, newUser);

                newUser.PopulatePasswordHashes(password);
                newUser.CreatedDate = DateTime.UtcNow;
                newUser.ModifiedDate = newUser.CreatedDate;

                db.Save((TUserAuth)newUser);

                newUser = db.SingleById <TUserAuth>(newUser.Id);
                return newUser;
            }));
        }
        public virtual async Task <IUserAuth> UpdateUserAuthAsync(IUserAuth existingUser, IUserAuth newUser, string password, CancellationToken token = default)
        {
            newUser.ValidateNewUser(password);

            return(await ExecAsync(async db =>
            {
                await AssertNoExistingUserAsync(db, newUser, existingUser, token).ConfigAwait();

                newUser.Id = existingUser.Id;
                newUser.PopulatePasswordHashes(password, existingUser);
                newUser.CreatedDate = existingUser.CreatedDate;
                newUser.ModifiedDate = DateTime.UtcNow;

                await db.SaveAsync((TUserAuth)newUser, token: token).ConfigAwait();

                return newUser;
            }).ConfigAwait());
        }
Exemplo n.º 11
0
        public static void RecordSuccessfulLogin(this IUserAuthRepository repo, IUserAuth userAuth, bool rehashPassword, string password)
        {
            var feature = HostContext.GetPlugin <AuthFeature>();

            if (feature?.MaxLoginAttempts == null)
            {
                return;
            }

            userAuth.InvalidLoginAttempts = 0;
            userAuth.LastLoginAttempt     = userAuth.ModifiedDate = DateTime.UtcNow;

            if (rehashPassword)
            {
                userAuth.PopulatePasswordHashes(password);
            }

            repo.SaveUserAuth(userAuth);
        }
Exemplo n.º 12
0
        public static async Task RecordSuccessfulLoginAsync(this IUserAuthRepositoryAsync repo, IUserAuth userAuth, bool rehashPassword, string password, CancellationToken token = default)
        {
            var recordLoginAttempts = HostContext.GetPlugin <AuthFeature>()?.MaxLoginAttempts != null;

            if (recordLoginAttempts)
            {
                userAuth.InvalidLoginAttempts = 0;
                userAuth.LastLoginAttempt     = userAuth.ModifiedDate = DateTime.UtcNow;
            }

            if (rehashPassword)
            {
                userAuth.PopulatePasswordHashes(password);
            }

            if (recordLoginAttempts || rehashPassword)
            {
                await repo.SaveUserAuthAsync(userAuth, token);
            }
        }
Exemplo n.º 13
0
        public virtual async Task <IUserAuth> UpdateUserAuthAsync(IUserAuth existingUser, IUserAuth newUser, string password, CancellationToken token = default)
        {
            newUser.ValidateNewUser(password);

            await using var redis = await factory.GetClientAsync(token).ConfigAwait();
            await AssertNoExistingUserAsync(redis, newUser, existingUser, token).ConfigAwait();

            if (existingUser.UserName != newUser.UserName && existingUser.UserName != null)
            {
                await redis.RemoveEntryFromHashAsync(IndexUserNameToUserId, existingUser.UserName, token).ConfigAwait();
            }
            if (existingUser.Email != newUser.Email && existingUser.Email != null)
            {
                await redis.RemoveEntryFromHashAsync(IndexEmailToUserId, existingUser.Email, token).ConfigAwait();
            }

            newUser.Id = existingUser.Id;
            newUser.PopulatePasswordHashes(password, existingUser);
            newUser.CreatedDate  = existingUser.CreatedDate;
            newUser.ModifiedDate = DateTime.UtcNow;

            var userId = newUser.Id.ToString(CultureInfo.InvariantCulture);

            if (!newUser.UserName.IsNullOrEmpty())
            {
                await redis.SetEntryInHashAsync(IndexUserNameToUserId, newUser.UserName, userId, token).ConfigAwait();
            }
            if (!newUser.Email.IsNullOrEmpty())
            {
                await redis.SetEntryInHashAsync(IndexEmailToUserId, newUser.Email, userId, token).ConfigAwait();
            }

            await redis.StoreAsync(newUser, token).ConfigAwait();

            return(newUser);
        }