Beispiel #1
0
        public MembershipCreateStatus CreateUser(string email, string password, string userName, string locale, int timezone)
        {
            if (!IsUserEmailValid(ref email))
            {
                return(MembershipCreateStatus.InvalidEmail);
            }

            if (!IsUserNameValid(ref userName))
            {
                return(MembershipCreateStatus.InvalidUserName);
            }

            var userCheck = _userService.GetUserByEmail(email);

            if (userCheck != null)
            {
                return(MembershipCreateStatus.DuplicateEmail);
            }

            if (!IsUserPasswordValid(ref password))
            {
                return(MembershipCreateStatus.InvalidPassword);
            }

            User user = new User
            {
                Email    = email,
                Name     = userName,
                Password = _passwordHasher.EncryptPassword(password),
                Locale   = _localeProvider.GetCultureByNameOrDefault(locale).ShortName,
                TimeZone = _timeZonesProvider.GetTimeZoneByIdOrDefault(timezone).Id
            };

            try
            {
                _userService.Insert(user);
                _userService.CreateRoleForUser(user, Constants.RoleUser);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(CultureInfo.InvariantCulture, "Error creating user with email {0}", ex, user.Email);
                return(MembershipCreateStatus.ProviderError);
            }
            return(MembershipCreateStatus.Success);
        }