Пример #1
0
        public static string AddUser(AddOptions opts)
        {
            var errorMessage = string.Empty;
            MembershipCreateStatus status;

            var username = opts.Username;
            var password = opts.Password ?? Membership.GeneratePassword(8, 2);
            var email    = opts.Email ?? "*****@*****.**";

            var provider = GetProvider();
            var saved    = provider.GetUser(username, false);

            if (saved != null)
            {
                errorMessage = $"User '{username}' already exists";
                return(errorMessage);
            }

            var user = provider.CreateUser(
                username: username,
                password: password,
                email: email,
                passwordQuestion: null,
                passwordAnswer: null,
                isApproved: true,
                providerUserKey: null,
                status: out status);

            if (user == null || status != MembershipCreateStatus.Success)
            {
                errorMessage = $"Error creating user '{username}'";
                return(errorMessage);
            }
            saved = provider.GetUser(username, false);

            if (saved == null || !provider.ValidateUser(username, password))
            {
                errorMessage = $"Error validating user '{username}'";
                return(errorMessage);
            }
            Console.WriteLine("email:     {0}", email);
            Console.WriteLine("username:  {0}", username);
            Console.WriteLine("password:  {0}", password);
            return(errorMessage);
        }
Пример #2
0
 public static int AddUser(AddOptions opts)
 {
     return(string.IsNullOrEmpty(UserAdmin.AddUser(opts)) ? Success : Error);
 }