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

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

            return(_tableStorage.ReplaceAsync(partitionKey, rowKey, itm =>
            {
                itm.SetPassword(newPassword);
                return itm;
            }));
        }
Example #3
0
        public async Task <IBackOfficeUser> GetAsync(string id)
        {
            if (id == null)
            {
                return(null);
            }

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

            return(await _tableStorage.GetDataAsync(partitionKey, rowKey));
        }
Example #4
0
        public static BackOfficeUserEntity Create(IBackOfficeUser src, string password)
        {
            var result = new BackOfficeUserEntity
            {
                PartitionKey = GeneratePartitionKey(),
                RowKey       = GenerateRowKey(src.Id),
                IsAdmin      = src.IsAdmin,
                FullName     = src.FullName
            };

            result.SetPassword(password);

            return(result);
        }
        public static BackOfficeUserEntity Create(IBackOfficeUser src, string password)
        {
            var result = new BackOfficeUserEntity
            {
                PartitionKey = GeneratePartitionKey(),
                RowKey = GenerateRowKey(src.Id),
                IsAdmin = src.IsAdmin,
                FullName = src.FullName

            };

            result.SetPassword(password);

            return result;
        }
Example #6
0
        public async Task <IBackOfficeUser> AuthenticateAsync(string username, string password)
        {
            if (username == null || password == null)
            {
                return(null);
            }

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


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

            if (entity == null)
            {
                return(null);
            }


            return(entity.CheckPassword(password) ? entity : null);
        }
Example #7
0
        public Task SaveAsync(IBackOfficeUser backOfficeUser, string password)
        {
            var newUser = BackOfficeUserEntity.Create(backOfficeUser, password);

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

            return(entity.Hash == hash);
        }
Example #9
0
 public static void SetPassword(this BackOfficeUserEntity entity, string password)
 {
     entity.Salt = Guid.NewGuid().ToString();
     entity.Hash = CalcHash(password, entity.Salt);
 }
Example #10
0
        public async Task <IEnumerable <IBackOfficeUser> > GetAllAsync()
        {
            var partitionKey = BackOfficeUserEntity.GeneratePartitionKey();

            return(await _tableStorage.GetDataAsync(partitionKey));
        }