コード例 #1
0
        public async Task <IActionResult> Create(SecretInputModel model)
        {
            if (ModelState.IsValid)
            {
                var email = User.FindFirstValue(ClaimTypes.Email);

                string secretId = null;
                using (var encryptContext = _secretContextService.CreateEncryptionContext(User))
                {
                    encryptContext.Secret.CreatedBy         = email;
                    encryptContext.Secret.CreatedByProvider = "Google";
                    encryptContext.InputData.Add(UserInputConstants.Secret, model.Secret);
                    encryptContext.InputData.Add(UserInputConstants.Passphrase, model.Passphrase);
                    encryptContext.InputData.Add(UserInputConstants.CustomMessage, model.CustomMessage);
                    if (!string.IsNullOrEmpty(model.Email))
                    {
                        encryptContext.InputData.Add(UserInputConstants.EmailAddress, model.Email);
                    }
                    if (!string.IsNullOrEmpty(model.IpRegex))
                    {
                        encryptContext.InputData.Add(UserInputConstants.IpRegex, model.IpRegex);
                    }
                    if (!model.SendEmail)
                    {
                        encryptContext.InputData.Add(UserInputConstants.DoNotSendEmail, true);
                    }
                    if (model.UserEmailMustMatch)
                    {
                        encryptContext.InputData.Add(UserInputConstants.ForceAuthentication, true);
                    }
                    encryptContext.InputData.Add(UserInputConstants.Expiry, model.Expiry);
                    encryptContext.SecretProperties.Add(new SecretProperty(SecretProperties.OwnerEmail)
                    {
                        Data = email
                    });

                    secretId = await encryptContext.EncryptSecretAsync();
                }

                return(RedirectToAction("Index", new { created = true }));
            }
            return(View(model));
        }
コード例 #2
0
        public IActionResult Create()
        {
            var model = new SecretInputModel();

            return(View(model));
        }