예제 #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);
        }
예제 #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;
            }));
        }
예제 #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));
        }
예제 #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);
        }
예제 #5
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;
        }
예제 #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);
        }
예제 #7
0
        public Task SaveAsync(IBackOfficeUser backOfficeUser, string password)
        {
            var newUser = BackOfficeUserEntity.Create(backOfficeUser, password);

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

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

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