Exemplo n.º 1
0
        public async Task <bool> UpdateAccountAsync(IAccountInfoData account)
        {
            string username = account.Username?.Trim();
            string email    = account.Email?.Trim();

            // Check username duplicate
            if (!string.IsNullOrEmpty(username))
            {
                var existingAccount = await GetAccountByUsernameAsync(username);

                // if this account is not ours
                if (existingAccount != null && existingAccount.Id != account.Id)
                {
                    throw new Exception("You are trying to update your username but it is already taken by another user");
                }
            }

            // Check email duplicate
            if (!string.IsNullOrEmpty(email))
            {
                var existingAccount = await GetAccountByEmailAsync(email);

                // if this account is not ours
                if (existingAccount != null && existingAccount.Id != account.Id)
                {
                    throw new Exception("There is another user with this email");
                }
            }

            return(await Task.Run(() => accountsCollection.Update(account as AccountInfoLiteDb)));
        }
Exemplo n.º 2
0
        public async Task <string> InsertNewAccountAsync(IAccountInfoData account)
        {
            string username = account.Username.Trim();
            string email    = account.Email.Trim();

            // Check username duplicate
            if (!string.IsNullOrEmpty(username))
            {
                var existingAccount = await GetAccountByUsernameAsync(username);

                // if this account is not ours
                if (existingAccount != null && existingAccount.Id != account.Id)
                {
                    throw new Exception($"User with username \"{username}\" already exists");
                }
            }

            // Check email duplicate
            if (!string.IsNullOrEmpty(email))
            {
                var existingAccount = await GetAccountByEmailAsync(email);

                // if this account is not ours
                if (existingAccount != null && existingAccount.Id != account.Id)
                {
                    throw new Exception($"User with email \"{email}\" already exists");
                }
            }

            return(await Task.Run(() => accountsCollection.Insert(account as AccountInfoLiteDb).AsString));
        }
Exemplo n.º 3
0
 public async Task InsertTokenAsync(IAccountInfoData account, string token)
 {
     await Task.Run(() => {
         account.Token = token;
         accounts.Update(account as AccountInfoLiteDb);
     });
 }
Exemplo n.º 4
0
 public async Task <bool> InsertTokenAsync(IAccountInfoData account, string token)
 {
     return(await Task.Run(() =>
     {
         account.Token = token;
         return accountsCollection.Update(account as AccountInfoLiteDb);
     }));
 }
 public void SavePasswordResetCode(IAccountInfoData account, string code)
 {
     resetCodes.DeleteMany(i => i.Email == account.Email.ToLower());
     resetCodes.Insert(new PasswordResetData()
     {
         Email = account.Email,
         Code  = code
     });
 }
Exemplo n.º 6
0
        public async Task <string> InsertNewAccountAsync(IAccountInfoData account)
        {
            var acc = account as AccountInfoMongoDB;
            await Task.Run(() => {
                _accountsCollection.InsertOne(acc);
            });

            return(acc.Id);
        }
Exemplo n.º 7
0
 public AccountInfoPacket(IAccountInfoData account)
 {
     Username         = account.Username;
     Email            = account.Email;
     IsAdmin          = account.IsAdmin;
     IsGuest          = account.IsGuest;
     IsEmailConfirmed = account.IsEmailConfirmed;
     Properties       = account.Properties;
 }
Exemplo n.º 8
0
        public async Task <bool> UpdateAccountAsync(IAccountInfoData account)
        {
            var filter = Builders <AccountInfoMongoDB> .Filter.Eq(e => e.Id, account.Id);

            return(await Task.Run(() =>
            {
                _accountsCollection.ReplaceOne(filter, account as AccountInfoMongoDB);
                return true;
            }));
        }
Exemplo n.º 9
0
 public UpdateAccountInfoPacket(IAccountInfoData account)
 {
     Id          = account.Id;
     Username    = account.Username ?? string.Empty;
     Password    = account.Password ?? string.Empty;
     Email       = account.Email ?? string.Empty;
     PhoneNumber = account.PhoneNumber ?? string.Empty;
     Facebook    = account.Facebook ?? string.Empty;
     Properties  = new MstProperties(account.Properties);
 }
Exemplo n.º 10
0
        public async Task <IAccountInfoData> GetAccountByTokenAsync(string token)
        {
            IAccountInfoData account = default;

            await Task.Run(() =>
            {
                account = accountsCollection.FindOne(a => a.Token == token);
            });

            return(account);
        }
Exemplo n.º 11
0
        public async Task <IAccountInfoData> GetAccountByUsernameAsync(string username)
        {
            IAccountInfoData account = default;

            await Task.Run(() =>
            {
                account = accountsCollection.FindOne(a => a.Username == username);
            });

            return(account);
        }
        public void SavePasswordResetCode(IAccountInfoData account, string code)
        {
            resetCodes.Delete(Query.EQ("Email", account.Email.ToLower()));

            resetCodes.Insert(new PasswordResetData()
            {
                Id    = ObjectId.NewObjectId(),
                Email = account.Email,
                Code  = code
            });
        }
Exemplo n.º 13
0
 public async Task SavePasswordResetCodeAsync(IAccountInfoData account, string code)
 {
     await Task.Run(() => {
         resetCodes.DeleteMany(i => i.Email == account.Email.ToLower());
         resetCodes.Insert(new PasswordResetData()
         {
             Email = account.Email,
             Code  = code
         });
     });
 }
Exemplo n.º 14
0
        public async Task <IAccountInfoData> GetAccountByEmailAsync(string email)
        {
            IAccountInfoData account = default;

            await Task.Run(() =>
            {
                account = accountsCollection.FindOne(i => i.Email == email.ToLower());
            });

            return(account);
        }
Exemplo n.º 15
0
 public async Task SavePasswordResetCodeAsync(IAccountInfoData account, string code)
 {
     await Task.Run(() =>
     {
         _resetCodesCollection.DeleteMany(i => i.Email == account.Email.ToLower());
         _resetCodesCollection.InsertOne(new PasswordResetDataMongoDB()
         {
             Email = account.Email,
             Code  = code
         });
     });
 }
        public async void SavePasswordResetCodeAsync(IAccountInfoData account, string code, Action <string> callback)
        {
            try
            {
                await Task.Run(() => SavePasswordResetCode(account, code));

                callback?.Invoke(string.Empty);
            }
            catch (Exception e)
            {
                callback?.Invoke(e.Message);
            }
        }
        public async void UpdateAccountAsync(IAccountInfoData account, Action <string> callback)
        {
            try
            {
                await Task.Run(() => UpdateAccount(account));

                callback?.Invoke(string.Empty);
            }
            catch (Exception e)
            {
                callback?.Invoke(e.Message);
            }
        }
        public async void InsertTokenAsync(IAccountInfoData account, string token, Action <string> callback)
        {
            try
            {
                await Task.Run(() => InsertToken(account, token));

                callback?.Invoke(string.Empty);
            }
            catch (Exception e)
            {
                callback?.Invoke(e.Message);
            }
        }
Exemplo n.º 19
0
        public async Task <bool> InsertTokenAsync(IAccountInfoData account, string token)
        {
            var filter = Builders <AccountInfoMongoDB> .Filter.Eq(e => e.Id, account.Id);

            var update = Builders <AccountInfoMongoDB> .Update.Set(e => e.Token, token);

            return(await Task.Run(() =>
            {
                account.Token = token;
                _accountsCollection.UpdateOne(filter, update);
                return true;
            }));
        }
Exemplo n.º 20
0
 public AccountInfoPacket(IAccountInfoData account)
 {
     Id               = account.Id ?? string.Empty;
     Username         = account.Username ?? string.Empty;
     Email            = account.Email ?? string.Empty;
     PhoneNumber      = account.PhoneNumber ?? string.Empty;
     Facebook         = account.Facebook ?? string.Empty;
     Token            = account.Token ?? string.Empty;
     IsAdmin          = account.IsAdmin;
     IsGuest          = account.IsGuest;
     IsEmailConfirmed = account.IsEmailConfirmed;
     Properties       = new MstProperties(account.Properties);
 }
        public async void GetAccountByEmailAsync(string email, GetAccountCallback callback)
        {
            IAccountInfoData account = default;

            try
            {
                await Task.Run(() =>
                {
                    account = GetAccountByEmail(email);
                });

                callback?.Invoke(account, string.Empty);
            }
            catch (Exception e)
            {
                callback?.Invoke(null, e.Message);
            }
        }
Exemplo n.º 22
0
 public void InsertNewAccount(IAccountInfoData account)
 {
     accounts.Insert(account as AccountInfoLiteDb);
 }
Exemplo n.º 23
0
 public async Task UpdateAccountAsync(IAccountInfoData account)
 {
     await Task.Run(() => accounts.Update(account as AccountInfoLiteDb));
 }
Exemplo n.º 24
0
 public void InsertToken(IAccountInfoData account, string token)
 {
     account.Token = token;
     accounts.Update(account as AccountInfoLiteDb);
 }
Exemplo n.º 25
0
 public void UpdateAccount(IAccountInfoData account)
 {
     accounts.Update(account as AccountInfoLiteDb);
 }
Exemplo n.º 26
0
 public async Task InsertNewAccountAsync(IAccountInfoData account)
 {
     await Task.Run(() => accounts.Insert(account as AccountInfoLiteDb));
 }