Beispiel #1
0
        private async Task <IEmailAddress> GetEmailAddress(CoreSettings settings,
                                                           IEmailAddressFactory emailAddressFactory,
                                                           IEmailAddressSaver emailAddressSaver,
                                                           string address)
        {
            IEmailAddress result = await emailAddressFactory.GetByAddress(settings, address);

            if (result == null)
            {
                result = emailAddressFactory.Create(address);
                await emailAddressSaver.Create(settings, result);
            }
            return(result);
        }
Beispiel #2
0
        private async Task <IUser> GetUser()
        {
            IUser         user;
            IEmailAddress emailAddress = null;

            using (ILifetimeScope scope = _container.BeginLifetimeScope())
            {
                string               subscriber          = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
                IUserFactory         userFactory         = scope.Resolve <IUserFactory>();
                IEmailAddressFactory emailAddressFactory = scope.Resolve <IEmailAddressFactory>();
                SettingsFactory      settingsFactory     = scope.Resolve <SettingsFactory>();
                user = await userFactory.GetByReferenceId(settingsFactory.CreateAccount(_settings.Value), subscriber);

                if (user == null)
                {
                    string email = User.Claims.First(c => c.Type == ClaimTypes.Email).Value;
                    emailAddress = await emailAddressFactory.GetByAddress(settingsFactory.CreateAccount(_settings.Value), email);

                    if (emailAddress == null)
                    {
                        emailAddress = emailAddressFactory.Create(email);
                        IEmailAddressSaver emailAddressSaver = scope.Resolve <IEmailAddressSaver>();
                        await emailAddressSaver.Create(settingsFactory.CreateAccount(_settings.Value), emailAddress);
                    }
                    user      = userFactory.Create(subscriber, emailAddress);
                    user.Name = User.Claims.First(c => string.Equals(c.Type, "name", StringComparison.OrdinalIgnoreCase)).Value;
                    SetSuperUser(user);
                    IUserSaver userSaver = scope.Resolve <IUserSaver>();
                    await userSaver.Create(settingsFactory.CreateAccount(_settings.Value), user);
                }
                else
                {
                    user.Name = User.Claims.First(c => string.Equals(c.Type, "name", StringComparison.OrdinalIgnoreCase)).Value;
                    SetSuperUser(user);
                    IUserSaver userSaver = scope.Resolve <IUserSaver>();
                    await userSaver.Update(settingsFactory.CreateAccount(_settings.Value), user);
                }
            }
            return(user);
        }