示例#1
0
        private async Task EnsureLetsEncryptAccountExists(Data.Models.AcmeAccount acmeAccount, bool staging)
        {
            var accountExists = await _certesAcmeProvider.AccountExists(acmeAccount.Key.RawData, staging);

            if (accountExists)
            {
                _logger.LogDebug("ACME account already exists.");
            }
            else
            {
                _logger.LogDebug("ACME account does not exists, creating account using existing key.");

                // Create account with existing key
                await _certesAcmeProvider.CreateAccount(acmeAccount.AcmeContactEmail,
                                                        acmeAccount.Key.RawData, staging);
            }
        }
示例#2
0
        private async Task <Data.Models.AcmeAccount> CreateOrUpdateAcmeAccount(ApplicationUser user, Key key, bool staging)
        {
            // Setup.AcmeContactEmail explicitly specified.
            // Check for existing account, create new if not exists, use key if one specified or
            // create and store new key.
            Data.Models.AcmeAccount acmeAccount = null;

            if (!string.IsNullOrWhiteSpace(Setup.AcmeContactEmail))
            {
                acmeAccount = await _dataContext.AcmeAccounts
                              .FirstOrDefaultAsync(x => x.AcmeContactEmail == Setup.AcmeContactEmail &&
                                                   x.IsAcmeStaging == staging);
            }

            // Try to locate using user's email
            if (acmeAccount == null)
            {
                acmeAccount = await _dataContext.AcmeAccounts
                              .FirstOrDefaultAsync(x => x.AcmeContactEmail == user.Email &&
                                                   x.IsAcmeStaging == staging);
            }

            // No account exists for user, create new ACME account
            if (acmeAccount == null)
            {
                var emailToUse = Setup.AcmeContactEmail ?? user.Email;
                acmeAccount = new Data.Models.AcmeAccount
                {
                    AcmeAcceptTos    = true,
                    AcmeContactEmail = emailToUse,
                    Key             = key,
                    ApplicationUser = user,
                    IsAcmeStaging   = staging
                };
                _dataContext.AcmeAccounts.Add(acmeAccount);
                await _dataContext.SaveChangesAsync();
            }
            return(acmeAccount);
        }