Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

ExternalAuthenticationModelFactory.cs

using Nop.Core;
using Nop.Services.Authentication.External;
using Nop.Web.Models.Customer;

namespace Nop.Web.Factories;

/// 
/// Represents the external authentication model factory
/// 
public partial class ExternalAuthenticationModelFactory : IExternalAuthenticationModelFactory
{
    #region Fields

    protected readonly IAuthenticationPluginManager _authenticationPluginManager;
    protected readonly IStoreContext _storeContext;
    protected readonly IWorkContext _workContext;

    #endregion

    #region Ctor

    public ExternalAuthenticationModelFactory(IAuthenticationPluginManager authenticationPluginManager,
        IStoreContext storeContext,
        IWorkContext workContext)
    {
        _authenticationPluginManager = authenticationPluginManager;
        _storeContext = storeContext;
        _workContext = workContext;
    }

    #endregion

    #region Methods

    /// 
    /// Prepare the external authentication method model
    /// 
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the list of the external authentication method model
    /// 
    public virtual async Task> PrepareExternalMethodsModelAsync()
    {
        var store = await _storeContext.GetCurrentStoreAsync();

        return (await _authenticationPluginManager
                .LoadActivePluginsAsync(await _workContext.GetCurrentCustomerAsync(), store.Id))
            .Select(authenticationMethod => new ExternalAuthenticationMethodModel
            {
                ViewComponent = authenticationMethod.GetPublicViewComponent()
            })
            .ToList();
    }

    #endregion
}