public ActionResult Add()
        {
            var acct = userAccountService.GetByID(this.User.GetUserID());

            if (Request.Files.Count == 0)
            {
                ModelState.AddModelError("", "No file uploaded");
            }
            else
            {
                try
                {
                    using (var ms = new MemoryStream())
                    {
                        Request.Files[0].InputStream.CopyTo(ms);
                        var bytes = ms.ToArray();

                        var cert = new X509Certificate2(bytes);
                        userAccountService.AddCertificate(User.GetUserID(), cert);

                        return(RedirectToAction("Index"));
                    }
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", "Error processing certificate");
                }
            }

            return(View("Index", acct));
        }
Esempio n. 2
0
        public void Add(Thinktecture.IdentityServer.Models.ClientCertificate certificate)
        {
            var user = userSvc.GetByUsername(certificate.UserName);

            if (user != null)
            {
                userSvc.AddCertificate(user.ID, certificate.Thumbprint, certificate.Description);
            }
        }