public async Task <bool> UserExists(string id)
        {
            string partitionKey = BackOfficeUserEntity.GeneratePartitionKey();
            string rowKey       = BackOfficeUserEntity.GenerateRowKey(id);

            return(await _tableStorage.GetDataAsync(partitionKey, rowKey) != null);
        }
        public Task ChangePasswordAsync(string id, string newPassword)
        {
            string partitionKey = BackOfficeUserEntity.GeneratePartitionKey();
            string rowKey       = BackOfficeUserEntity.GenerateRowKey(id);

            return(_tableStorage.ReplaceAsync(partitionKey, rowKey, itm =>
            {
                itm.SetPassword(newPassword);
                return itm;
            }));
        }
        public Task UpdateAsync(IBackOfficeUser backOfficeUser)
        {
            string partitionKey = BackOfficeUserEntity.GeneratePartitionKey();
            string rowKey       = BackOfficeUserEntity.GenerateRowKey(backOfficeUser.Id);

            return(_tableStorage.MergeAsync(partitionKey, rowKey, entity =>
            {
                entity.Edit(backOfficeUser);
                return entity;
            }));
        }
        public async Task <IBackOfficeUser> GetAsync(string id)
        {
            if (id == null)
            {
                return(null);
            }

            string partitionKey = BackOfficeUserEntity.GeneratePartitionKey();
            string rowKey       = BackOfficeUserEntity.GenerateRowKey(id);

            return(await _tableStorage.GetDataAsync(partitionKey, rowKey));
        }
        public async Task <IBackOfficeUser> AuthenticateAsync(string username, string password)
        {
            if (username == null || password == null)
            {
                return(null);
            }

            string partitionKey = BackOfficeUserEntity.GeneratePartitionKey();
            string rowKey       = BackOfficeUserEntity.GenerateRowKey(username);


            BackOfficeUserEntity entity = await _tableStorage.GetDataAsync(partitionKey, rowKey);

            return(entity == null
                ? null
                : (entity.CheckPassword(password)
                    ? entity
                    : null));
        }
        public async Task <IEnumerable <IBackOfficeUser> > GetAllAsync()
        {
            string partitionKey = BackOfficeUserEntity.GeneratePartitionKey();

            return(await _tableStorage.GetDataAsync(partitionKey));
        }
        public Task CreateAsync(IBackOfficeUser backOfficeUser, string password)
        {
            var newUser = BackOfficeUserEntity.Create(backOfficeUser, password);

            return(_tableStorage.InsertOrReplaceAsync(newUser));
        }
Example #8
0
 public static void SetPassword(this BackOfficeUserEntity entity, string password)
 {
     entity.Salt = Guid.NewGuid().ToString();
     entity.Hash = CalcHash(password, entity.Salt);
 }
Example #9
0
 public static bool CheckPassword(this BackOfficeUserEntity entity, string password)
 {
     var hash = CalcHash(password, entity.Salt);
     return entity.Hash == hash;
 }