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))); }
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)); }
public async Task InsertTokenAsync(IAccountInfoData account, string token) { await Task.Run(() => { account.Token = token; accounts.Update(account as AccountInfoLiteDb); }); }
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 }); }
public async Task <string> InsertNewAccountAsync(IAccountInfoData account) { var acc = account as AccountInfoMongoDB; await Task.Run(() => { _accountsCollection.InsertOne(acc); }); return(acc.Id); }
public AccountInfoPacket(IAccountInfoData account) { Username = account.Username; Email = account.Email; IsAdmin = account.IsAdmin; IsGuest = account.IsGuest; IsEmailConfirmed = account.IsEmailConfirmed; Properties = account.Properties; }
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; })); }
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); }
public async Task <IAccountInfoData> GetAccountByTokenAsync(string token) { IAccountInfoData account = default; await Task.Run(() => { account = accountsCollection.FindOne(a => a.Token == token); }); return(account); }
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 }); }
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 }); }); }
public async Task <IAccountInfoData> GetAccountByEmailAsync(string email) { IAccountInfoData account = default; await Task.Run(() => { account = accountsCollection.FindOne(i => i.Email == email.ToLower()); }); return(account); }
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); } }
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; })); }
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); } }
public void InsertNewAccount(IAccountInfoData account) { accounts.Insert(account as AccountInfoLiteDb); }
public async Task UpdateAccountAsync(IAccountInfoData account) { await Task.Run(() => accounts.Update(account as AccountInfoLiteDb)); }
public void InsertToken(IAccountInfoData account, string token) { account.Token = token; accounts.Update(account as AccountInfoLiteDb); }
public void UpdateAccount(IAccountInfoData account) { accounts.Update(account as AccountInfoLiteDb); }
public async Task InsertNewAccountAsync(IAccountInfoData account) { await Task.Run(() => accounts.Insert(account as AccountInfoLiteDb)); }