Esempio n. 1
0
        //GET
        protected override DriverResult Editor(TwoFactorAuthenticationPart part, dynamic shapeHelper)
        {
            return(ContentShape("Parts_TwoFactorAuthentication_Edit",
                                () => {
                //Get settings
                var siteTFASettings = _services.WorkContext.CurrentSite.As <TwoFactorAuthenticationSettingsPart>();
                //Build the identifier
                var identifier = _services.WorkContext.CurrentSite.SiteName + ":" + _services.WorkContext.CurrentUser.UserName;

                //Build the TFA Model
                var model = new TwoFactorAuthenticationViewModel()
                {
                    //Helpers
                    PinToVerifyKey = null,
                    QRCode = _twoFactorAuthenticator.GenerateProvisioningImage(identifier, part.SecretKey, 250, 250),

                    //TFA - Site Settings
                    RequireTFA = siteTFASettings.RequireTFA,
                    SiteEnableBackupSMS = siteTFASettings.EnableBackupSMS,
                    RequireBackupSMS = siteTFASettings.RequireBackupSMS,

                    //TFA - Part
                    EnableTFA = part.EnableTFA,
                    SecretKey = _twoFactorAuthenticator.EncodeKey(part.SecretKey),
                    HasVerifiedKey = part.HasVerifiedKey,
                    CanLoginWithoutTFA = part.CanLoginWithoutTFA,
                    EnableBackupSMS = siteTFASettings.RequireBackupSMS ? siteTFASettings.RequireBackupSMS : part.EnableBackupSMS,
                    BackupSMSNum = part.BackupSMSNum
                };

                return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
            }));
        }
        public ActionResult GenerateNewKey()
        {
            var userTFA = _orchardServices.WorkContext.CurrentUser.As <TwoFactorAuthenticationPart>();

            //Key
            var newKey = _twoFactorAuthenticator.GenerateKey();

            userTFA.Record.SecretKey      = newKey;
            userTFA.Record.HasVerifiedKey = false;

            var newKeyString = _twoFactorAuthenticator.EncodeKey(newKey);

            //QR_Code
            var identifier = _orchardServices.WorkContext.CurrentSite.SiteName + ":" + _orchardServices.WorkContext.CurrentUser.UserName;

            var newQRCode     = _twoFactorAuthenticator.GenerateProvisioningImage(identifier, userTFA.SecretKey, 250, 250);
            var newQRCodeData = System.Convert.ToBase64String(newQRCode);

            return(Json(new { newKey = newKeyString, newQRCode = newQRCodeData }));
        }