public ShopgunMembershipWebserviceGateway CreateUser(string username, string password, string email)
        {
            ShopgunMembershipWebserviceGateway response = new ShopgunMembershipWebserviceGateway();

            User newUser = new User
            {
                UserName                = username,
                Password                = password,
                Email                   = email,
                CreationDate            = DateTime.Now,
                LastActivity            = DateTime.Now,
                LastLockedOutDate       = DateTime.Now,
                LastLoginDate           = DateTime.Now,
                LastPasswordChangedDate = DateTime.Now
            };

            //TODO: Shall support language, translate from resource string.

            //Refactoring here please, extract to a method: ValidateNewUserInfo(string username, string password, string email) : bool
            if ((newUser.UserName == null) || (newUser.Password == null))
            {
                response.value   = false;
                response.message = "Enter username and password!";
                return(response);
            }
            if (_membershipProviderApplicationService.GetUser(newUser.UserName, false, ProviderName) != null)
            {
                response.value   = false;
                response.message = "Username already exists!";
                return(response);
            }
            if (_membershipProviderApplicationService.GetUserByMail(newUser.Email, ProviderName) != null)
            {
                response.value   = false;
                response.message = "Email already exists!";
                return(response);
            }
            //End of refactoring

            try
            {
                _membershipProviderApplicationService.CreateUser(newUser);
                response = ValidateMobileUser(newUser.UserName, password);
                if (response.value)
                {
                    response.message = "User created!";
                }
                return(response);
            }
            catch
            {
                response.value   = false;
                response.message = "User not created, system error!";
                return(response);
            }
        }
Exemple #2
0
        public ActionResult CreateUser(User newUser, FormCollection formCollection)
        {
            try
            {
                _membershipProviderApplicationService.CreateUser(newUser);

                var roles = formCollection["Roles"].Replace("false", "").Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var role in roles)
                {
                    _roleProviderApplicationService.AddUserToRole(newUser.UserName, role);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("CreateUser"));
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds a new membership user to the data source.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="passwordQuestion"></param>
        /// <param name="passwordAnswer"></param>
        /// <param name="isApproved"></param>
        /// <param name="providerUserKey"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            //TODO: All code shall be moved into the application service.
            User newUser = new User();

            newUser.UserName                = username;
            newUser.Password                = password;
            newUser.Email                   = email;
            newUser.CreationDate            = DateTime.Now;
            newUser.LastActivity            = DateTime.Now;
            newUser.LastLockedOutDate       = DateTime.Now;
            newUser.LastLoginDate           = DateTime.Now;
            newUser.LastPasswordChangedDate = DateTime.Now;


            if (_membershipProviderApplicationService.GetUser(newUser.UserName, false, ProviderName) != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }
            else if (_membershipProviderApplicationService.GetUserByMail(newUser.Email, ProviderName) != null)
            {
                status = MembershipCreateStatus.DuplicateEmail;
            }
            else
            {
                try
                {
                    _membershipProviderApplicationService.CreateUser(newUser);
                    status = MembershipCreateStatus.Success;
                    return(newUser.ToMembershipUser());
                }
                catch (Exception e)
                {
                    status = MembershipCreateStatus.UserRejected;
                    throw new Exception(e.Message, e);
                }
            }


            return(null);
        }