public void UpdateUser() { var source = new DomainSource(); var user = User(); source.Insert(user); var saved = source.GetUserById(user.ApplicationId, user.Id); Assert.IsNotNull(saved); Assert.AreEqual <DateTime>(saved.CreatedOn, user.CreatedOn); Assert.AreEqual <DateTime>(saved.LastLoggedInOn, user.LastLoggedInOn); Assert.AreEqual <DateTime>(saved.LastActivityOn, user.LastActivityOn); Assert.AreEqual <DateTime>(saved.PasswordLastChangedOn, user.PasswordLastChangedOn); Assert.AreEqual <string>(saved.Email, user.Email); Assert.AreEqual <string>(saved.OpenId, user.OpenId); Assert.AreEqual <string>(saved.UserName, user.UserName); Assert.AreEqual <int>(saved.RoleValue, user.RoleValue); Assert.AreEqual <bool>(saved.IsApproved, user.IsApproved); Assert.AreEqual <bool>(saved.IsLockedOut, user.IsLockedOut); Assert.AreEqual <DateTime>(saved.LastLockedOutOn, user.LastLockedOutOn); var preUpdate = user; preUpdate.LastLoggedInOn = DateTime.UtcNow.AddHours(-34); preUpdate.IsLockedOut = true; preUpdate.IsApproved = false; preUpdate.LastActivityOn = DateTime.UtcNow.AddHours(-88); preUpdate.Email = StringHelper.ValidString(); preUpdate.OpenId = StringHelper.ValidString(); preUpdate.PasswordLastChangedOn = DateTime.UtcNow.AddHours(-22); source.Update(preUpdate); var updated = source.GetUserById(user.ApplicationId, user.Id); Assert.IsNotNull(preUpdate); Assert.AreEqual <DateTime>(preUpdate.CreatedOn, updated.CreatedOn); Assert.AreEqual <DateTime>(preUpdate.LastLoggedInOn.Date, updated.LastLoggedInOn.Date); Assert.AreEqual <DateTime>(preUpdate.LastActivityOn.Date, updated.LastActivityOn.Date); Assert.AreEqual <DateTime>(preUpdate.PasswordLastChangedOn.Date, updated.PasswordLastChangedOn.Date); Assert.AreEqual <string>(preUpdate.Email, updated.Email); Assert.AreEqual <string>(preUpdate.OpenId, updated.OpenId); Assert.AreEqual <string>(preUpdate.UserName, updated.UserName); Assert.AreEqual <int>(preUpdate.RoleValue, updated.RoleValue); Assert.AreEqual <bool>(preUpdate.IsApproved, updated.IsApproved); Assert.AreEqual <bool>(preUpdate.IsLockedOut, updated.IsLockedOut); Assert.AreEqual <DateTime>(preUpdate.LastLockedOutOn, updated.LastLockedOutOn); }
public bool PermitApplicationCreation(Abc.Services.Contracts.Application application, User user) { Contract.Requires <ArgumentNullException>(null != user); Contract.Requires <ArgumentNullException>(null != application); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != application.Identifier); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != user.Identifier); var source = new DomainSource(); var editorData = source.GetUserById(application.Identifier, user.Identifier); if (editorData.RoleValue == (int)RoleType.Manager) { return(true); } else { var editorPreference = new UserPreference() { User = user, Application = application, }; var userCore = new UserCore(); editorPreference = userCore.Get(editorPreference); return(editorPreference.MaximumAllowedApplications.HasValue && editorPreference.MaximumAllowedApplications.Value > this.ApplicationCount(user)); } }
public bool UserIsAssociated(UserApplication editor, Abc.Services.Contracts.Application application) { Contract.Requires <ArgumentNullException>(null != editor); Contract.Requires <ArgumentNullException>(null != application); Contract.Requires <ArgumentNullException>(null != editor.User); Contract.Requires <ArgumentNullException>(null != editor.Application); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != editor.User.Identifier); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != editor.Application.Identifier); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != application.Identifier); using (new PerformanceMonitor()) { var source = new DomainSource(); var user = source.GetUserById(editor.Application.Identifier, editor.User.Identifier); if (null != user) { if (user.RoleValue == (int)RoleType.Manager) { return(true); } } var table = new AzureTable <ApplicationInfoData>(ServerConfiguration.Default); var data = table.QueryBy(string.Empty, application.Identifier.ToString()); if (null != data) { if (data.Owner == editor.User.Identifier) { return(true); } } return(this.Get(editor) != null); } }
public User GetByIdentifier(UserApplication userApp) { Contract.Requires <ArgumentNullException>(null != userApp); Contract.Requires <ArgumentNullException>(null != userApp.Application); Contract.Requires <ArgumentNullException>(null != userApp.User); Contract.Requires <ArgumentException>(Guid.Empty != userApp.Application.Identifier); Contract.Requires <ArgumentException>(Guid.Empty != userApp.User.Identifier); var source = new DomainSource(); var userData = source.GetUserById(userApp.Application.Identifier, userApp.User.Identifier); return(userData == null ? (User)null : userData.Convert()); }
public void GetUserById() { var source = new DomainSource(); var user = User(); source.Insert(user); var saved = source.GetUserById(user.ApplicationId, user.Id); Assert.IsNotNull(saved); Assert.AreEqual <DateTime>(saved.CreatedOn, user.CreatedOn); Assert.AreEqual <DateTime>(saved.LastLoggedInOn, user.LastLoggedInOn); Assert.AreEqual <DateTime>(saved.LastActivityOn, user.LastActivityOn); Assert.AreEqual <DateTime>(saved.PasswordLastChangedOn, user.PasswordLastChangedOn); Assert.AreEqual <string>(saved.Email, user.Email); Assert.AreEqual <string>(saved.OpenId, user.OpenId); Assert.AreEqual <string>(saved.UserName, user.UserName); Assert.AreEqual <int>(saved.RoleValue, user.RoleValue); Assert.AreEqual <bool>(saved.IsApproved, user.IsApproved); Assert.AreEqual <bool>(saved.IsLockedOut, user.IsLockedOut); Assert.AreEqual <DateTime>(saved.LastLockedOutOn, user.LastLockedOutOn); }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool approved, object providerUserKey, out MembershipCreateStatus status) { using (new PerformanceMonitor()) { MembershipUser membership = null; status = MembershipCreateStatus.UserRejected; UserData userValidation = null; if (!string.IsNullOrWhiteSpace(email)) { userValidation = source.GetUserByEmail(Application.Default.Identifier, email); if (null != userValidation) { status = MembershipCreateStatus.DuplicateEmail; } } if (!string.IsNullOrWhiteSpace(username)) { userValidation = source.GetUserByEmail(Application.Default.Identifier, username); if (null != userValidation) { status = MembershipCreateStatus.DuplicateUserName; } } if (null == userValidation) { userValidation = source.GetUserByNameIdentifier(Application.Default.Identifier, providerUserKey.ToString()); if (null != userValidation) { status = MembershipCreateStatus.DuplicateProviderUserKey; } else { var user = new UserData(email, providerUserKey.ToString(), username) { RoleValue = (int)TableMembershipProvider.DetermineRoleType(email), }; source.Insert(user); var returnedUser = source.GetUserById(Application.Default.Identifier, user.Id); if (null == returnedUser) { status = MembershipCreateStatus.ProviderError; } else if (!returnedUser.IsApproved) { status = MembershipCreateStatus.UserRejected; } else if (returnedUser.IsLockedOut) { status = MembershipCreateStatus.UserRejected; } else { status = MembershipCreateStatus.Success; membership = new MembershipUser(ProviderName, returnedUser.UserName, returnedUser.NameIdentifier, returnedUser.Email, passwordQuestion, string.Empty, returnedUser.IsApproved, returnedUser.IsLockedOut, returnedUser.CreatedOn, returnedUser.LastLoggedInOn, returnedUser.LastActivityOn, returnedUser.PasswordLastChangedOn, returnedUser.LastLockedOutOn); logger.Log("New user signed up."); } } } return(membership); } }
public ApplicationInformation Save(ApplicationInformation data, UserApplication editor, Abc.Services.Contracts.Application application) { Contract.Requires <ArgumentNullException>(null != data); Contract.Requires <ArgumentNullException>(null != editor); Contract.Requires <ArgumentNullException>(null != editor.Application); Contract.Requires <ArgumentNullException>(null != editor.User); Contract.Requires <ArgumentNullException>(null != application); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != data.Identifier); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != editor.Application.Identifier); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != editor.User.Identifier); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != application.Identifier); Contract.Ensures(Contract.Result <ApplicationInformation>() != null); using (new PerformanceMonitor()) { var source = new DomainSource(); var editorData = source.GetUserById(application.Identifier, editor.User.Identifier); var serverDetails = ((IConvert <Details>)data).Convert(); if (data.IsNew) { if (this.PermitApplicationCreation(application, editor.User)) { if (data.IsNew) { serverDetails.IsValid = true; app.Create(serverDetails); if (userApplicationCache.ContainsKey(editor.User.Identifier)) { userApplicationCache.Remove(editor.User.Identifier); } } } else { Logging.Log("User tried to create an application without authorization."); } } else { if (editorData.RoleValue == (int)RoleType.Manager) { app.Update(serverDetails); if (userApplicationCache.ContainsKey(editor.User.Identifier)) { userApplicationCache.Remove(editor.User.Identifier); } } else { Logging.Log("User tried to update an application without authorization."); } } var appInfoData = ((IConvert <ApplicationInfoData>)data).Convert(); appInfoData.Load(editorData); var table = new AzureTable <ApplicationInfoData>(ServerConfiguration.Default, new ApplicationInfoValidator()); var existing = this.Get(appInfoData); if (null != existing) { existing.Environment = appInfoData.Environment; existing.Name = appInfoData.Name; existing.Description = appInfoData.Description; existing.Deleted = appInfoData.Deleted; existing.Active = appInfoData.Active; appInfoData = existing; } else { appInfoData.CreatedBy = editor.User.Identifier; appInfoData.Owner = editor.User.Identifier; appInfoData.CreatedOn = DateTime.UtcNow; } appInfoData.LastUpdatedBy = editor.User.Identifier; appInfoData.LastUpdatedOn = DateTime.UtcNow; table.AddOrUpdateEntity(appInfoData); if (data.IsNew && editorData.RoleValue == (int)RoleType.Client) { var save = new Abc.Services.Contracts.Application() { Identifier = serverDetails.ApplicationId, }; var ua = new UserApplication() { Application = save, User = editor.User, Deleted = false, Active = true, }; this.Save(ua, editor); } return(data); } }
public IList <ApplicationInformation> Get(User user, Guid applicationId) { Contract.Requires <ArgumentNullException>(null != user); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != user.Identifier); Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != applicationId); using (new PerformanceMonitor()) { if (userApplicationCache.ContainsKey(user.Identifier)) { return(userApplicationCache[user.Identifier]); } else { var source = new DomainSource(); var webUser = source.GetUserById(applicationId, user.Identifier); var allAppDetails = app.Search(); if (null != allAppDetails) { IList <Details> usersAppDetails = null; var role = (RoleType)webUser.RoleValue; switch (role) { case RoleType.Client: var appTable = new AzureTable <ApplicationInfoData>(ServerConfiguration.Default); var userApplications = (from data in appTable.QueryByPartition(ApplicationInfoData.Key) where data.Owner == webUser.Id select data).ToList(); var table = new AzureTable <UserApplicationData>(ServerConfiguration.Default); var assignedUsers = table.QueryByPartition(webUser.Id.ToString()).ToList(); usersAppDetails = (from all in allAppDetails where userApplications.Any(ua => ua.ApplicationId == all.ApplicationId) || assignedUsers.Any(ua => ua.ApplicationId == all.ApplicationId) select all).ToList(); break; case RoleType.Manager: usersAppDetails = allAppDetails.ToList(); break; default: Logging.Log("Unknown Role Type."); break; } if (null != usersAppDetails) { var infos = new List <ApplicationInformation>(usersAppDetails.Count); foreach (var usersApp in usersAppDetails) { var info = this.Get(new ApplicationInfoData(usersApp.ApplicationId)); ApplicationInformation appInfo; if (null == info) { appInfo = new ApplicationInformation() { Identifier = usersApp.ApplicationId, }; } else { appInfo = info.Convert(); } appInfo.Load(usersApp); infos.Add(appInfo); } if (!userApplicationCache.ContainsKey(user.Identifier) && null != infos && 0 < infos.Count) { userApplicationCache.Add(user.Identifier, infos); } return(infos); } } return(null); } } }
public void GetUserByIdInvalidApplicationId() { var source = new DomainSource(); source.GetUserById(Guid.NewGuid(), Guid.Empty); }
public void GetUserByIdInvalidId() { var source = new DomainSource(); source.GetUserById(Guid.Empty, Guid.NewGuid()); }