@@ -100,7 +100,7 @@ public class UmbracoAppAuthenticator : ITwoFactorProvider
100100 /// <returns >The required data to setup the authenticator app</returns >
101101 public Task <ISetupTwoFactorModel > GetSetupDataAsync (Guid userOrMemberKey , string secret )
102102 {
103- var member = _memberService .GetByKey (userOrMemberKey );
103+ var member = _memberService .GetById (userOrMemberKey );
104104
105105 var applicationName = " testingOn15" ;
106106 var twoFactorAuthenticator = new TwoFactorAuthenticator ();
@@ -173,47 +173,61 @@ If you already have a members-only page with the edit profile options, you can s
173173``` csharp
174174@using Umbraco .Cms .Core .Services ;
175175@using Umbraco .Cms .Web .Website .Controllers ;
176+ @using Umbraco .Cms .Core .Models ;
176177@using Umbraco .Cms .Web .Website .Models ;
177178@using My .Website ;
178- @inject MemberModelBuilderFactory memberModelBuilderFactory
179- @inject ITwoFactorLoginService twoFactorLoginService
179+ @inject MemberModelBuilderFactory MemberModelBuilderFactory
180+ @inject IMemberTwoFactorLoginService MemberTwoFactorLoginService
180181@{
181182 // Build a profile model to edit
182- var profileModel = await memberModelBuilderFactory
183- .CreateProfileModel ()
184- .BuildForCurrentMemberAsync ();
183+ var profileModel = await MemberModelBuilderFactory
184+ .CreateProfileModel ()
185+ .BuildForCurrentMemberAsync ();
186+
187+ List < UserTwoFactorProviderModel > ? providerNameList = null ;
188+ if (profileModel != null )
189+ {
190+ var providerNamesAttempt = await MemberTwoFactorLoginService .GetProviderNamesAsync (profileModel .Key );
191+
192+ if (providerNamesAttempt .Success )
193+ {
194+ providerNameList = providerNamesAttempt .Result .ToList ();
195+ }
196+ }
185197
186198 // Show all two factor providers
187- var providerNames = twoFactorLoginService .GetAllProviderNames ();
188- if (providerNames .Any ())
199+ if (providerNameList != null && providerNameList .Any ())
189200 {
190201 < div asp - validation - summary = " All" class = " text-danger" >< / div >
191- foreach (var providerName in providerNames )
202+ foreach (var provider in providerNameList )
192203 {
193- var setupData = await twoFactorLoginService .GetSetupInfoAsync (profileModel .Key , providerName );
204+ var setupData = await MemberTwoFactorLoginService .GetSetupInfoAsync (profileModel .Key , provider . ProviderName );
194205
195- // If the `setupData` is `null` for the specified `providerName` it means the provider is already set up.
196- // In this case, a button to disable the authentication is shown.
197- if (setupData is null )
206+ // If the `setupData.Success` is `true` for the specified `providerName` it means the provider is not set up.
207+ if (setupData .Success )
198208 {
199- @using ( Html . BeginUmbracoForm < UmbTwoFactorLoginController >( nameof ( UmbTwoFactorLoginController . Disable )) )
209+ if ( setupData . Result is QrCodeSetupData qrCodeSetupData )
200210 {
201- < input type = " hidden" name = " providerName" value = " @providerName" / >
202- < button type = " submit" > Disable @providerName < / button >
211+ @using (Html .BeginUmbracoForm <UmbTwoFactorLoginController >(nameof (UmbTwoFactorLoginController .ValidateAndSaveSetup )))
212+ {
213+ < h3 > Setup @provider .ProviderName < / h3 >
214+ < img src = " @qrCodeSetupData.SetupCode.QrCodeSetupImageUrl" / >
215+ < p > Scan the code above with your authenticator app < br / > and enter the resulting code here to validate : < / p >
216+ < input type = " hidden" name = " providerName" value = " @provider.ProviderName" / >
217+ < input type = " hidden" name = " secret" value = " @qrCodeSetupData.Secret" / >
218+ < input type = " text" name = " code" / >
219+ < button type = " submit" > Validate & save < / button >
220+ }
203221 }
204222 }
205- // If `setupData` is not `null` the type is checked and the UI for how to set up the App Authenticator is shown.
206- else if (setupData is QrCodeSetupData qrCodeSetupData )
223+ // If `setupData.Success` is `false` the provider is already setup.
224+ // In this case, a button to disable the authentication is shown.
225+ else
207226 {
208- @using (Html .BeginUmbracoForm <UmbTwoFactorLoginController >(nameof (UmbTwoFactorLoginController .ValidateAndSaveSetup )))
227+ @using (Html .BeginUmbracoForm <UmbTwoFactorLoginController >(nameof (UmbTwoFactorLoginController .Disable )))
209228 {
210- < h3 > Setup @providerName < / h3 >
211- < img src = " @qrCodeSetupData.SetupCode.QrCodeSetupImageUrl" / >
212- < p > Scan the code above with your authenticator app < br / > and enter the resulting code here to validate : < / p >
213- < input type = " hidden" name = " providerName" value = " @providerName" / >
214- < input type = " hidden" name = " secret" value = " @qrCodeSetupData.Secret" / >
215- < input type = " text" name = " code" / >
216- < button type = " submit" > Validate & save < / button >
229+ < input type = " hidden" name = " providerName" value = " @provider.ProviderName" / >
230+ < button type = " submit" > Disable @provider .ProviderName < / button >
217231 }
218232 }
219233 }
0 commit comments