예제 #1
0
        public void CreateUser(RegistrationData user,
                               [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ValidationErrorResources))]
                               string password)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            // NOTE: ASP.NET by default uses SQL Server Express to create the user database.
            // CreateUser will fail if you do not have SQL Server Express installed.
            Membership.CreateUser(user.UserName, password);

            // Assign the user to the default role if the given role does not exist
            // This will fail if role management is disabled.
            if (Roles.RoleExists(user.Role))
            {
                Roles.AddUserToRole(user.UserName, user.Role);
            }
            else
            {
                Roles.AddUserToRole(user.UserName, UserRegistrationService.DefaultRole);
            }

            // Set the friendly name (profile setting).
            // This will fail if the web.config is configured incorrectly.
            ProfileBase profile = ProfileBase.Create(user.UserName, false);

            profile.SetPropertyValue("FriendlyName", user.FriendlyName);
            profile.SetPropertyValue("Foundry", user.Foundry);
            profile.SetPropertyValue("CustomerCompany", user.CustomerCompany);
            profile.Save();
        }
예제 #2
0
        public void CreateUser(RegistrationData user,
            [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ValidationErrorResources))]
            string password)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            // NOTE: ASP.NET by default uses SQL Server Express to create the user database.
            // CreateUser will fail if you do not have SQL Server Express installed.
            Membership.CreateUser(user.UserName, password);

            // Assign the user to the default role if the given role does not exist
            // This will fail if role management is disabled.
            if (Roles.RoleExists(user.Role))
                Roles.AddUserToRole(user.UserName, user.Role);
            else
                Roles.AddUserToRole(user.UserName, UserRegistrationService.DefaultRole);

            // Set the friendly name (profile setting).
            // This will fail if the web.config is configured incorrectly.
            ProfileBase profile = ProfileBase.Create(user.UserName, false);
            profile.SetPropertyValue("FriendlyName", user.FriendlyName);
            profile.SetPropertyValue("Foundry", user.Foundry);
            profile.SetPropertyValue("CustomerCompany", user.CustomerCompany);
            profile.Save();
        }
예제 #3
0
        public void EditUser(RegistrationData user, string password = "")
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            MembershipUser membershipUser = Membership.GetUser(user.UserName);

            if (password != "")
            {
                String resetPwd = membershipUser.ResetPassword();
                membershipUser.ChangePassword(resetPwd, password);
            }

            if (Roles.RoleExists(user.Role))
            {
                foreach (var role in Roles.GetRolesForUser(user.UserName))
                {
                    Roles.RemoveUserFromRole(user.UserName, role);
                }
                Roles.AddUserToRole(user.UserName, user.Role);
            }

            // Set the friendly name (profile setting).
            // This will fail if the web.config is configured incorrectly.
            ProfileBase profile = ProfileBase.Create(user.UserName, false);

            profile.SetPropertyValue("FriendlyName", user.FriendlyName);
            profile.SetPropertyValue("Foundry", user.Foundry);
            profile.SetPropertyValue("CustomerCompany", user.CustomerCompany);
            profile.Save();
        }
예제 #4
0
        public IEnumerable <RegistrationData> GetUsers()
        {
            var users = Membership.GetAllUsers();
            List <RegistrationData> registeredUsers = new List <RegistrationData>();

            foreach (MembershipUser mUser in users)
            {
                var user = mUser.GetUser();
                RegistrationData data = new RegistrationData()
                {
                    UserName        = user.Name,
                    Role            = Roles.GetRolesForUser(user.Name).FirstOrDefault(),
                    Foundry         = user.Foundry,
                    FriendlyName    = user.FriendlyName,
                    CustomerCompany = user.CustomerCompany
                };
                registeredUsers.Add(data);
            }
            return(registeredUsers);
        }
예제 #5
0
 public IEnumerable<RegistrationData> GetUsers()
 {
     var users = Membership.GetAllUsers();
     List<RegistrationData> registeredUsers = new List<RegistrationData>();
     foreach (MembershipUser mUser in users)
     {
         var user = mUser.GetUser();
         RegistrationData data = new RegistrationData()
                                 {
                                     UserName = user.Name,
                                     Role = Roles.GetRolesForUser(user.Name).FirstOrDefault(),
                                     Foundry = user.Foundry,
                                     FriendlyName = user.FriendlyName,
                                     CustomerCompany=user.CustomerCompany
                                 };
         registeredUsers.Add(data);
     }
     return registeredUsers;
 }
예제 #6
0
        public void EditUser(RegistrationData user, string password = "")
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            MembershipUser membershipUser = Membership.GetUser(user.UserName);

            if (password != "")
            {
                String resetPwd = membershipUser.ResetPassword();
                membershipUser.ChangePassword(resetPwd, password);
            }

            if (Roles.RoleExists(user.Role))
            {
                foreach (var role in Roles.GetRolesForUser(user.UserName))
                {
                    Roles.RemoveUserFromRole(user.UserName, role);
                }
                Roles.AddUserToRole(user.UserName, user.Role);
            }

            // Set the friendly name (profile setting).
            // This will fail if the web.config is configured incorrectly.
            ProfileBase profile = ProfileBase.Create(user.UserName, false);
            profile.SetPropertyValue("FriendlyName", user.FriendlyName);
            profile.SetPropertyValue("Foundry", user.Foundry);
            profile.SetPropertyValue("CustomerCompany", user.CustomerCompany);
            profile.Save();
        }
예제 #7
0
 /// <summary>
 /// Asynchronously invokes the 'EditUser' method of the DomainService.
 /// </summary>
 /// <param name="user">The value for the 'user' parameter of this action.</param>
 /// <param name="password">The value for the 'password' parameter of this action.</param>
 /// <returns>An operation instance that can be used to manage the asynchronous request.</returns>
 public InvokeOperation EditUser(RegistrationData user, string password)
 {
     Dictionary<string, object> parameters = new Dictionary<string, object>();
     parameters.Add("user", user);
     parameters.Add("password", password);
     this.ValidateMethod("EditUser", parameters);
     return this.InvokeOperation("EditUser", typeof(void), parameters, true, null, null);
 }
예제 #8
0
 /// <summary>
 /// Asynchronously invokes the 'CreateUser' method of the DomainService.
 /// </summary>
 /// <param name="user">The value for the 'user' parameter of this action.</param>
 /// <param name="password">The value for the 'password' parameter of this action.</param>
 /// <returns>An operation instance that can be used to manage the asynchronous request.</returns>
 public InvokeOperation CreateUser(RegistrationData user, [Required(ErrorMessageResourceName="ValidationErrorRequiredField", ErrorMessageResourceType=typeof(ValidationErrorResources))] string password)
 {
     Dictionary<string, object> parameters = new Dictionary<string, object>();
     parameters.Add("user", user);
     parameters.Add("password", password);
     this.ValidateMethod("CreateUser", parameters);
     return this.InvokeOperation("CreateUser", typeof(void), parameters, true, null, null);
 }
예제 #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="regData"></param>
 private void OpenRegistrationWindow(RegistrationData regData)
 {
     RegistrationFormWindow registerWindow = new RegistrationFormWindow();
     var form = registerWindow.RegistrationForm;
     form.DataContext = regData;
     form.IsEditing = regData.isEditing;
     form.Foundries = this.Foundries;
     form.Roles = this.Roles;
     registerWindow.Closed += new EventHandler(registerWindow_Closed);
     registerWindow.Show();
 }