public LoginResults Login(string username, string password) { LoginResults loginResults = this.MembershipApi.Login(username, password); if (loginResults != LoginResults.Successful) return loginResults; this.userObject = this.MembershipApi.Get(username); this.identity = new GenericIdentity(username); return LoginResults.Successful; }
private UserObject CreateUser(string userName, string displayName) { IPlatformConfiguration platformConfiguration = SpringContext.Current.GetObject<IPlatformConfiguration>(); UserObject userObject = new UserObject { UserName = userName, DisplayName = displayName, OrganizationId = platformConfiguration.Organization.OrganizationId, IsApproved = true, }; membershipApi.Save(userObject, "password1", null); this.createdUserIds.Add(userObject.UserId); return userObject; }
private Guid CreateUser(IMembershipApi membershipApi) { IPlatformConfiguration platformConfiguration = SpringContext.Current.GetObject<IPlatformConfiguration>(); UserObject userObject = new UserObject { OrganizationId = platformConfiguration.Organization.OrganizationId, Comment = "IT specialist", DisplayName = string.Format("DisplayName {0}", Guid.NewGuid()), Email = "*****@*****.**", IsApproved = true, MobilePin = "137641855XX", UserName = string.Format("UserName {0}", Guid.NewGuid()) }; membershipApi.Save(userObject, "password1", null); createdUserIds.Add(userObject.UserId); return userObject.UserId; }
public void TestQuery() { UserManagement page = new UserManagement(); DynamicPageProxy proxy = new DynamicPageProxy(page); IMembershipApi membershipApi = SpringContext.Current.GetObject<IMembershipApi>(); IPlatformConfiguration platformConfiguration = SpringContext.Current.GetObject<IPlatformConfiguration>(); using (var httpEnv = new HttpEnvironment()) { httpEnv.SetRequestUrl(@"/UserManagement/DynamicPage.svc?Domain=Department"); #region Create Data Guid guid = Guid.NewGuid(); string surfix = guid.ToString().Substring(0, 5); UserObject obj = new UserObject() { OrganizationId = platformConfiguration.Organization.OrganizationId, Comment = "IT specialist", DisplayName = "Eunge Liu" + surfix, Email = "*****@*****.**", IsApproved = true, MobilePin = "137641855XX", UserName = "******"+surfix }; membershipApi.Save(obj, "password1", null); createdObjectIds.Add(obj.UserId); #endregion #region query QueryParameterExpression expression = new QueryParameterExpression("UserName", QueryFieldOperators.Equal, "Eunge" + surfix); SortExpression sort = new SortExpression("UserName"); QueryParameter parameters = new QueryParameter() { //Expressions = express, PageIndex = 0, PageSize = 10, SortExpression = sort }; parameters.Expressions.Add(expression); QueryResults results = proxy.Query(parameters); foreach (var result in results.Results) { Assert.AreEqual(DataBinder.Eval(result, "UserName"), "Eunge" + surfix); } #endregion } }
public void TestUpdate() { UserDetailPanel page = new UserDetailPanel(); DetailPanelPageProxy proxy = new DetailPanelPageProxy(page); IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>(); IMembershipApi membershipApi = SpringContext.Current.GetObject<IMembershipApi>(); IPlatformConfiguration platformConfiguration = SpringContext.Current.GetObject<IPlatformConfiguration>(); using (var httpEnv = new HttpEnvironment()) { httpEnv.SetRequestUrl(@"/UserDetailPanel/DynamicPage.svc?Domain=Department"); Guid guid = Guid.NewGuid(); string surfix = guid.ToString().Substring(0, 5); UserObject obj = new UserObject() { OrganizationId = platformConfiguration.Organization.OrganizationId, Comment = "IT specialist", DisplayName = "Eunge Liu" + surfix, Email = "*****@*****.**", IsApproved = true, MobilePin = "137641855XX", UserName = "******" + surfix }; membershipApi.Save(obj, "password1", null); createdObjectIds.Add(obj.UserId); OrganizationSelector OrganizationSelector = new OrganizationSelector(); //IList<OrganizationObject> ds = new List<OrganizationObject>(); OrganizationObject organization = new OrganizationObject() { OrganizationCode = "123456" + surfix, OrganizationName = "org" + surfix, Status = OrganizationStatus.Enabled, OrganizationTypeId = organizationApi.FindOrganizationTypes(new List<string>() { "Department" }).Select(x => x.OrganizationTypeId).FirstOrDefault(), Description = "organ" }; organizationApi.Save(organization); //ds.Add(organization); createdOrganizationIds.Add(organization.OrganizationId); OrganizationSelector.SelectedOrganization = organization; proxy.Set("OrganizationSelector", OrganizationSelector); TextBox TextBoxUserName = new TextBox(); TextBoxUserName.Text = "Eunge" + surfix; proxy.Set("TextBoxUserName", TextBoxUserName); TextBox TextBoxPassword = new TextBox(); TextBoxPassword.Text = "Password" + surfix; proxy.Set("TextBoxPassword", TextBoxPassword); TextBox TextBoxConfirmPassword = new TextBox(); TextBoxConfirmPassword.Text = "Password" + surfix; proxy.Set("TextBoxConfirmPassword", TextBoxConfirmPassword); TextBox TextBoxDisplayName = new TextBox(); TextBoxDisplayName.Text = "Eunge" + surfix; proxy.Set("TextBoxDisplayName", TextBoxConfirmPassword); TextBox TextBoxEmail = new TextBox(); TextBoxEmail.Text = "*****@*****.**"; proxy.Set("TextBoxEmail", TextBoxEmail); TextBox TextBoxMobile = new TextBox(); TextBoxMobile.Text = "13456789009"; proxy.Set("TextBoxMobile", TextBoxMobile); ExtensionDataForm UserExtensionDataForm = null; proxy.Set("UserExtensionDataForm", UserExtensionDataForm); TextBox TextBoxComment = new TextBox(); TextBoxComment.Text = "13456789009" + surfix; proxy.Set("TextBoxComment", TextBoxComment); Array statusData = new string[] { "true", "false" }; RadioButtonList RadioButtonListStatus = new RadioButtonList(); RadioButtonListStatus.DataSource = statusData; RadioButtonListStatus.DataBind(); RadioButtonListStatus.SelectedIndex = 0; proxy.Set("RadioButtonListStatus", RadioButtonListStatus); TextBox TextBoxCreationDate = new TextBox(); TextBoxCreationDate.Text = System.DateTime.UtcNow.ToShortTimeString(); proxy.Set("TextBoxCreationDate", TextBoxCreationDate); TextBox TextBoxLastLoginDate = new TextBox(); TextBoxLastLoginDate.Text = System.DateTime.UtcNow.ToShortTimeString(); proxy.Set("TextBoxLastLoginDate", TextBoxLastLoginDate); TextBox TextBoxLastActivityDate = new TextBox(); TextBoxLastActivityDate.Text = System.DateTime.UtcNow.ToShortTimeString(); proxy.Set("TextBoxLastActivityDate", TextBoxLastActivityDate); TextBox TextBoxLockedOutDate = new TextBox(); TextBoxLockedOutDate.Text = System.DateTime.UtcNow.ToShortTimeString(); proxy.Set("TextBoxLockedOutDate", TextBoxLockedOutDate); TextBox TextBoxLastPasswordChangedDate = new TextBox(); TextBoxLastPasswordChangedDate.Text = System.DateTime.UtcNow.ToShortTimeString(); proxy.Set("TextBoxLastPasswordChangedDate", TextBoxLastPasswordChangedDate); TextBox TextBoxLastUpdatedDate = new TextBox(); TextBoxLastUpdatedDate.Text = System.DateTime.UtcNow.ToShortTimeString(); proxy.Set("TextBoxLastUpdatedDate", TextBoxLastUpdatedDate); PermissionTreeView @PermissionTreeView = null; proxy.Set("PermissionTreeView", @PermissionTreeView); proxy.Update(obj.UserId.ToString()); } }
/// <summary> /// Get the copy of current object. /// </summary> /// <returns></returns> public UserObject Clone() { UserObject copy = new UserObject { UserId = this.UserId, UserName = this.UserName, ApplicationId = this.ApplicationId, Comment = this.Comment, DisplayName = this.DisplayName, OrganizationId = this.OrganizationId, Email = this.Email, IsApproved = this.IsApproved, CreationDate = this.CreationDate, IsLockedOut = this.IsLockedOut, IsOnline = this.IsOnline, LastActivityDate = this.LastActivityDate, LastLockoutDate = this.LastLockoutDate, LastLoginDate = this.LastLoginDate, LastPasswordChangedDate = this.LastPasswordChangedDate, MobilePin = this.MobilePin, PasswordQuestion = this.PasswordQuestion, LastUpdatedDate = this.LastUpdatedDate, ExtensionDataTypeId = this.ExtensionDataTypeId }; this.ClonePropertiesTo(copy); return copy; }
private static Guid CreateUserWithExtensionProperties(IMembershipApi membershipApi) { IPlatformConfiguration platformConfiguration = SpringContext.Current.GetObject<IPlatformConfiguration>(); UserObject userObject = new UserObject { OrganizationId = platformConfiguration.Organization.OrganizationId, Comment = "IT specialist", DisplayName = "Eunge Liu", Email = "*****@*****.**", IsApproved = true, MobilePin = "137641855XX", UserName = "******" }; userObject["Birthday"] = new DateTime(1982, 2, 7); userObject["Sex"] = "Male"; userObject["IdentityNo"] = "51010419820207XXXX"; userObject["EmployeeNo"] = "200708200002"; userObject["Department"] = "Simulation"; userObject["Position"] = "Team Lead"; userObject["PhoneNo"] = "021-647660XX"; userObject["City"] = "ShangHai"; userObject["Address"] = "MeiLong 2nd Cun, MingHang District"; userObject["ZipCode"] = "210000"; membershipApi.Save(userObject, "password1", null); return userObject.UserId; }
public void SaveUserWithOutExtensionProperties() { MockRepository mockRepository = new MockRepository(); IOrganizationApi organizationApi = mockRepository.StrictMock<IOrganizationApi>(); SetupResult.For(organizationApi.GetOrganization(Guid.Empty)).IgnoreArguments().Return(new OrganizationObject()); mockRepository.ReplayAll(); UserObject userObject = new UserObject { Comment = "IT specialist", DisplayName = "Eunge Liu", Email = "*****@*****.**", IsApproved = true, MobilePin = "137641855XX", UserName = "******" }; IMembershipApi membershipApi = new MembershipApi(SpringContext.Current.GetObject<IAuthenticationContext>(), organizationApi); membershipApi.Save(userObject, "password1", null); createdObjectIds.Add(userObject.UserId); userObject = membershipApi.Get(userObject.UserId); userObject.DisplayName = "Eunge"; membershipApi.Save(userObject, null, null); userObject = membershipApi.Get(userObject.UserId); Assert.AreEqual("Eunge", userObject.DisplayName); }
public void UsersAndRolesTest() { IPlatformConfiguration platformConfiguration = SpringContext.Current.GetObject<IPlatformConfiguration>(); IMembershipApi membershipApi = SpringContext.Current.GetObject<IMembershipApi>(); IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>(); IRoleApi roleApi = SpringContext.Current.GetObject<IRoleApi>(); UserObject eunge = new UserObject { OrganizationId = platformConfiguration.Organization.OrganizationId, UserName = "******", DisplayName = "Eunge", Email = "*****@*****.**", Comment = "The author of RapidWebDev.", IsApproved = true }; membershipApi.Save(eunge, "password1", null); createdUserIds.Add(eunge.UserId); OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" }; organizationApi.Save(department); createdOrganizationTypeIds.Add(department.OrganizationTypeId); RoleObject powerAdministrators = new RoleObject { RoleName = "powerAdministrators", Description = "powerAdministrators-desc", Domain = "Department" }; RoleObject business = new RoleObject { RoleName = "business", Description = "business-desc", Domain = "Department" }; roleApi.Save(powerAdministrators); roleApi.Save(business); createdRoleIds.AddRange(new Guid[] { powerAdministrators.RoleId, business.RoleId }); roleApi.SetUserToRoles(eunge.UserId, new Guid[] { powerAdministrators.RoleId }); Assert.AreEqual(1, roleApi.FindByUserId(eunge.UserId).Count()); Assert.IsTrue(roleApi.IsUserInRole(eunge.UserId, powerAdministrators.RoleId)); Assert.IsTrue(roleApi.IsUserInRole(eunge.UserId, "powerAdministrators")); roleApi.SetUserToRoles(eunge.UserId, new Guid[] { powerAdministrators.RoleId, business.RoleId }); Assert.AreEqual(2, roleApi.FindByUserId(eunge.UserId).Count()); Assert.IsTrue(roleApi.IsUserInRole(eunge.UserId, powerAdministrators.RoleId)); Assert.IsTrue(roleApi.IsUserInRole(eunge.UserId, "powerAdministrators")); Assert.IsTrue(roleApi.IsUserInRole(eunge.UserId, business.RoleId)); Assert.IsTrue(roleApi.IsUserInRole(eunge.UserId, "business")); }