/// <summary> /// Create an administrator. /// </summary> private void CreateAdministrator() { ISession session = SnCore.Data.Hibernate.Session.Current; Account a = (Account)session.CreateCriteria(typeof(Account)) .SetMaxResults(1) .UniqueResult(); if (a != null) { return; } a = new Account(); a.Name = "Administrator"; a.Password = ManagedAccount.GetPasswordHash("password"); a.IsAdministrator = true; a.IsPasswordExpired = true; a.Created = a.Modified = a.LastLogin = DateTime.UtcNow; a.Birthday = DateTime.UtcNow; a.TimeZone = -1; session.Save(a); AccountEmail ae = new AccountEmail(); ae.Account = a; ae.Address = "*****@*****.**"; ae.Created = ae.Modified = a.Created; ae.Principal = true; ae.Verified = true; session.Save(ae); session.Flush(); ManagedAccount ma = new ManagedAccount(session, a); ma.CreateAccountSystemMessageFolders(ManagedAccount.GetAdminSecurityContext(session)); }
public void TestCrud() { Account acct = new Account(); acct.Created = acct.LastLogin = acct.Modified = DateTime.UtcNow; acct.Name = "Test User"; acct.Password = "******"; acct.Birthday = new DateTime(1976, 9, 7); AccountEmail email = new AccountEmail(); email.Account = acct; email.Address = "*****@*****.**"; email.Verified = false; email.Failed = false; email.Created = email.Modified = DateTime.UtcNow; if (acct.AccountEmails == null) { acct.AccountEmails = new List <AccountEmail>(); } acct.AccountEmails.Add(email); Session.Save(acct); Session.Save(email); Session.Flush(); Assert.IsTrue(email.Id > 0); Assert.IsTrue(acct.Id > 0); Session.Delete(acct); Session.Flush(); }
public void TestCrud() { Account acct = new Account(); acct.Created = acct.LastLogin = acct.Modified = DateTime.UtcNow; acct.Name = "Test User"; acct.Password = "******"; acct.Birthday = new DateTime(1976, 9, 7); AccountEmail email = new AccountEmail(); email.Account = acct; email.Address = "*****@*****.**"; email.Verified = false; email.Failed = false; email.Created = email.Modified = DateTime.UtcNow; if (acct.AccountEmails == null) acct.AccountEmails = new List<AccountEmail>(); acct.AccountEmails.Add(email); Session.Save(acct); Session.Save(email); Session.Flush(); Assert.IsTrue(email.Id > 0); Assert.IsTrue(acct.Id > 0); Session.Delete(acct); Session.Flush(); }
public void TestCleanupStaleAccounts_1() { ManagedSecurityContext sec = ManagedAccount.GetAdminSecurityContext(Session); string email = string.Format("{0}@sncore.com", Guid.NewGuid().ToString()); // create an account with an unverified e-mail, make sure the e-mail is sent ManagedAccount ma = new ManagedAccount(Session); int id = ma.Create("TestCleanupStaleAccounts", "password", email, DateTime.UtcNow, sec); bool fDeleted = false; try { Session.Flush(); // get the account as is, update the login date/time to four months behind Account a = Session.Load <Account>(id); a.LastLogin = DateTime.UtcNow.AddMonths(-4); Session.Save(a); Session.Flush(); // update the e-mail as if it was added 3 months ago AccountEmail e = (AccountEmail)a.AccountEmails[0]; Assert.AreEqual(e.Created, e.Modified); e.Created = e.Modified = a.LastLogin; Session.Save(e); // check that the account has a single confirmation e-mail pending Console.WriteLine("Email dates: {0}/{1}", e.Created, e.Modified); service.RunCleanupStaleAccounts(Session, ManagedAccount.GetAdminSecurityContext(Session)); Session.Refresh(e); Console.WriteLine("Email dates: {0}/{1}", e.Created, e.Modified); Assert.AreNotEqual(e.Created, e.Modified); // move e-mail modified date in the past -> account should be deleted e.Modified = e.Modified.AddMonths(-3); Session.Save(e); Session.Flush(); service.RunCleanupStaleAccounts(Session, ManagedAccount.GetAdminSecurityContext(Session)); a = (Account)Session.CreateCriteria(typeof(Account)) .Add(Expression.Eq("Id", id)) .UniqueResult(); Assert.IsNull(a); fDeleted = true; } finally { if (!fDeleted) { ma.Delete(sec); } } }
public async Task When_AddingEmailToAccount_Then_TheEmailIsIncludedInTheAccount() { // arrange var email = new AccountEmail { AccountId = AccountId, Email = "*****@*****.**" }; // act await Client.AddEmailToAccount(email, RequestOptions); // assert var result = await Client.GetEmailsForAccount(AccountId, RequestOptions); Assert.That(result.Any(e => e.Email == "*****@*****.**"), Is.True); }
public async Task RemoveEmailFromAccount(AccountEmail email, RequestOptions inputOptions) { if (email == null) { throw new ArgumentNullException(nameof(email)); } if (email.AccountId.Equals(Guid.Empty)) { throw new ArgumentException("AccountEmail#accountId cannot be empty"); } var uri = Configuration.ACCOUNTS_PATH + "/" + email.AccountId + "/" + Configuration.EMAILS + "/" + HttpUtility.UrlEncode(email.Email); await _client.Delete(uri, inputOptions); }
public async Task AddEmailToAccount(AccountEmail email, RequestOptions inputOptions) { if (email == null) { throw new ArgumentNullException(nameof(email)); } if (email.AccountId.Equals(Guid.Empty)) { throw new ArgumentException("AccountEmail#accountId cannot be empty"); } var uri = Configuration.ACCOUNTS_PATH + "/" + email.AccountId + "/" + Configuration.EMAILS; await _client.Post(uri, email, inputOptions); }
public async Task When_RemovingEmailToAccount_Then_TheEmailIsRemovedFromTheAccount() { // arrange var email = new AccountEmail { AccountId = AccountId, Email = "*****@*****.**" }; await Client.AddEmailToAccount(email, RequestOptions); var emails = await Client.GetEmailsForAccount(AccountId, RequestOptions); Assume.That(emails.Any(e => e.Email == "*****@*****.**"), Is.True); // act await Client.RemoveEmailFromAccount(email, RequestOptions); // assert var result = await Client.GetEmailsForAccount(AccountId, RequestOptions); Assert.That(result.Any(e => e.Email == "*****@*****.**"), Is.False); }
public override int GetHashCode() { return(Titel.GetHashCode() ^ StartDate.GetHashCode() ^ EndDate.GetHashCode() ^ Notes.GetHashCode() ^ GameName.GetHashCode() ^ AccountEmail.GetHashCode()); }
public override int GetHashCode() { return(Titel.GetHashCode() ^ StartDate.GetHashCode() ^ EndDate.GetHashCode() ^ Notes.GetHashCode() ^ Subject.GetHashCode() ^ Assignment.GetHashCode() ^ AccountEmail.GetHashCode()); }
public IAccountConfirmedSetter SetEmail(string email) { Email = new AccountEmail(email); return(this); }
public async Task RemoveEmailFromAccount(AccountEmail email, RequestOptions inputOptions) { await _accountManager.RemoveEmailFromAccount(email, inputOptions); }
public async Task AddEmailToAccount(AccountEmail email, RequestOptions inputOptions) { await _accountManager.AddEmailToAccount(email, inputOptions); }