예제 #1
0
        public async Task <Account> RegisterUsername(string userMailto, string password, string globalId = null)
        {
            var registration = new UsernameRegistration(userMailto);

            Data.Account account = await Register(
                registration.Username,
                registration.DisplayName,
                AccountTokenType.Credential,
                registration.IsAffiliate,
                globalId ?? Guid.NewGuid().ToString()
                );

            if (_options.Registration.StoreEmail && registration.Username.IsEmailAddress())
            {
                UpdateProperty(account, ClaimTypes.Email, registration.Username);
                await _store.Update(account);
            }

            if (password.HasValue())
            {
                await UpdatePasswordAsync(account, password);
            }

            return(Mapper.Map <Account>(account, opts => {
                opts.Items["serviceUrl"] = _serviceUrl;
                opts.Items["profileOptions"] = _options.Profile;
            }));
        }
예제 #2
0
        /// <summary>
        /// Send a request to create a new user with a username/password pair
        /// </summary>
        /// <param name="service"></param>
        /// <param name="user">The user to create</param>
        /// <param name="usernameCredentials">The user's username credentials</param>
        /// <returns>An authentication token and user information, or <code>null</code> if the request failed</returns>
        public static async Task <AuthResponse?> Register(this HttpService service, User user, UsernameCredentials usernameCredentials)
        {
            var registration = new UsernameRegistration(usernameCredentials, user);

            try
            {
                return(await service.Session.Send <AuthResponse>(() => HttpRequestMessageExtensions.Create(service.Session, "v1/register/username", HttpMethod.Post, registration)));
            }
            catch (Session.BadRequestException e)
            {
                switch (e.Error)
                {
                case "existing_username":
                    throw new ExistingUsernameException();

                case "existing_email":
                    throw new ExistingEmailException();

                case "malformed_email":
                    throw new InvalidEmailException();

                case "bad_password":
                    throw new BadPasswordException();

                case "short_password":
                    throw new BadPasswordException();
                }
            }
            return(null);
        }
예제 #3
0
        public async Task <UsernameRegistration[]> RegisterUsernames(UsernameRegistrationModel model)
        {
            var results = new List <UsernameRegistration>();

            foreach (string userMailto in model.Usernames)
            {
                if (string.IsNullOrWhiteSpace(userMailto))
                {
                    continue;
                }

                var result = new UsernameRegistration(userMailto);
                try
                {
                    await RegisterUsername(userMailto, model.Password);
                }
                catch (Exception ex)
                {
                    result.Message = ex.GetType().Name.Split(".").Last().Replace("Exception", "");
                }
                results.Add(result);
            }
            return(results.ToArray());
        }