forked from nopSolutions/nopCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
192 changed files
with
12,706 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Plugins/Nop.Plugin.ExternalAuth.QQ/Components/QQAuthenticationViewComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Nop.Plugin.ExternalAuth.QQ; | ||
using Nop.Web.Framework.Components; | ||
|
||
namespace Nop.Plugin.ExternalAuth.Facebook.Components | ||
{ | ||
[ViewComponent(Name = QQAuthenticationDefaults.ViewComponentName)] | ||
public class QQAuthenticationViewComponent : NopViewComponent | ||
{ | ||
public IViewComponentResult Invoke() | ||
{ | ||
return View("~/Plugins/ExternalAuth.QQ/Views/PublicInfo.cshtml"); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions
62
src/Plugins/Nop.Plugin.ExternalAuth.QQ/Content/qqstyles.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.qq-btn { | ||
display: inline-block; | ||
width: 150px; | ||
height: 23px; | ||
background-image: url('images/qq.png'); | ||
background-repeat: no-repeat; | ||
} | ||
.qq-btn:hover { | ||
background-position: 0px -24px; | ||
} | ||
.qq-btn:active { | ||
background-position: 0px -48px; | ||
} | ||
|
||
/* */ | ||
.fl { float: left; } | ||
.select-login-type { margin-top: 43px;} | ||
.select-login-type a { | ||
display: inline-block; | ||
border-radius: 50%; | ||
width: 165px; | ||
height: 165px; | ||
border: 1px solid #dfdfdf; | ||
font-size: 18px; | ||
text-align: center; | ||
} | ||
.select-login-type a em { | ||
margin: 38px auto 13px; | ||
display: block; | ||
background-image: url('images/login-type.png'); | ||
background-repeat: no-repeat; | ||
} | ||
.select-login-type .qq { | ||
color: #2a9ce3; | ||
margin-left: 97px; | ||
margin-right: 40px; | ||
} | ||
.select-login-type .qq em { | ||
width: 52px; | ||
height: 57px; | ||
background-position: -11px -6px; | ||
} | ||
.select-login-type .qq:hover { | ||
background: #2a9ce3; | ||
color: #fff; | ||
border: 1px solid #2a9ce3; | ||
} | ||
.select-login-type .wechat { | ||
color: #40af37; | ||
margin-left: 40px; | ||
} | ||
.select-login-type .wechat:hover { | ||
background: #40af37; | ||
color: #fff; | ||
border: 1px solid #40af37; | ||
} | ||
|
||
.select-login-type .wechat em { | ||
width: 57px; | ||
height: 57px; | ||
background-position: -124px -6px; | ||
} |
71 changes: 71 additions & 0 deletions
71
src/Plugins/Nop.Plugin.ExternalAuth.QQ/Controllers/QQAuthenticationController.authen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authentication; | ||
//using Microsoft.AspNetCore.Authentication.Facebook; | ||
using Microsoft.AspNetCore.Authentication.QQ; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using Nop.Core; | ||
using Nop.Plugin.ExternalAuth.QQ.Models; | ||
using Nop.Services.Authentication.External; | ||
using Nop.Services.Configuration; | ||
using Nop.Services.Localization; | ||
using Nop.Services.Security; | ||
using Nop.Web.Framework; | ||
using Nop.Web.Framework.Controllers; | ||
using Nop.Web.Framework.Mvc.Filters; | ||
|
||
namespace Nop.Plugin.ExternalAuth.QQ.Controllers | ||
{ | ||
public partial class QQAuthenticationController : BasePluginController | ||
{ | ||
#region Methods | ||
|
||
public IActionResult Login(string returnUrl) | ||
{ | ||
|
||
/***!! | ||
if (!_externalAuthenticationService.ExternalAuthenticationMethodIsAvailable(QQAuthenticationDefaults.ProviderSystemName)) | ||
throw new NopException("QQ authentication module cannot be loaded"); | ||
***/ | ||
|
||
if (string.IsNullOrEmpty(_qqExternalAuthSettings.ClientKeyIdentifier) || string.IsNullOrEmpty(_qqExternalAuthSettings.ClientSecret)) | ||
throw new NopException("QQ authentication module not configured"); | ||
|
||
//configure login callback action | ||
var authenticationProperties = new AuthenticationProperties | ||
{ | ||
RedirectUri = Url.Action("LoginCallback", "QQAuthentication", new { returnUrl = returnUrl }) | ||
}; | ||
authenticationProperties.SetString("ErrorCallback", Url.RouteUrl("Login", new { returnUrl })); | ||
|
||
return Challenge(authenticationProperties, QQDefaults.AuthenticationScheme); | ||
} | ||
|
||
public async Task<IActionResult> LoginCallback(string returnUrl) | ||
{ | ||
//authenticate QQ user | ||
var authenticateResult = await HttpContext.AuthenticateAsync(QQDefaults.AuthenticationScheme); | ||
if (!authenticateResult.Succeeded || !authenticateResult.Principal.Claims.Any()) | ||
return RedirectToRoute("Login"); | ||
|
||
//create external authentication parameters | ||
var authenticationParameters = new ExternalAuthenticationParameters | ||
{ | ||
ProviderSystemName = QQAuthenticationDefaults.ProviderSystemName, | ||
AccessToken = await HttpContext.GetTokenAsync(QQDefaults.AuthenticationScheme, "access_token"), | ||
Email = authenticateResult.Principal.FindFirst(claim => claim.Type == ClaimTypes.Email)?.Value, | ||
ExternalIdentifier = authenticateResult.Principal.FindFirst(claim => claim.Type == ClaimTypes.NameIdentifier)?.Value, | ||
ExternalDisplayIdentifier = authenticateResult.Principal.FindFirst(claim => claim.Type == ClaimTypes.Name)?.Value, | ||
Claims = authenticateResult.Principal.Claims.Select(claim => new ExternalAuthenticationClaim(claim.Type, claim.Value)).ToList() | ||
}; | ||
|
||
//authenticate Nop user | ||
return _externalAuthenticationService.Authenticate(authenticationParameters, returnUrl); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/Plugins/Nop.Plugin.ExternalAuth.QQ/Controllers/QQAuthenticationController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using Microsoft.AspNetCore.Authentication.QQ; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using Nop.Plugin.ExternalAuth.QQ.Models; | ||
using Nop.Services.Authentication.External; | ||
using Nop.Services.Configuration; | ||
using Nop.Services.Localization; | ||
using Nop.Services.Messages; | ||
using Nop.Services.Security; | ||
using Nop.Web.Framework; | ||
using Nop.Web.Framework.Controllers; | ||
using Nop.Web.Framework.Mvc.Filters; | ||
|
||
namespace Nop.Plugin.ExternalAuth.QQ.Controllers | ||
{ | ||
public partial class QQAuthenticationController : BasePluginController | ||
{ | ||
#region Fields | ||
|
||
private readonly QQExternalAuthSettings _qqExternalAuthSettings; | ||
private readonly IExternalAuthenticationService _externalAuthenticationService; | ||
private readonly ILocalizationService _localizationService; | ||
private readonly IOptionsMonitorCache<QQOptions> _optionsCache; | ||
private readonly IPermissionService _permissionService; | ||
private readonly ISettingService _settingService; | ||
private readonly INotificationService _notificationService; | ||
|
||
#endregion | ||
|
||
#region Ctor | ||
|
||
public QQAuthenticationController(QQExternalAuthSettings qqExternalAuthSettings, | ||
IExternalAuthenticationService externalAuthenticationService, | ||
ILocalizationService localizationService, | ||
INotificationService notificationService, | ||
IOptionsMonitorCache<QQOptions> optionsCache, | ||
IPermissionService permissionService, | ||
ISettingService settingService) | ||
{ | ||
this._qqExternalAuthSettings = qqExternalAuthSettings; | ||
this._externalAuthenticationService = externalAuthenticationService; | ||
this._localizationService = localizationService; | ||
this._optionsCache = optionsCache; | ||
this._permissionService = permissionService; | ||
this._settingService = settingService; | ||
_notificationService = notificationService; | ||
} | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
[AuthorizeAdmin] | ||
[Area(AreaNames.Admin)] | ||
public IActionResult Configure() | ||
{ | ||
if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) | ||
return AccessDeniedView(); | ||
|
||
var model = new ConfigurationModel | ||
{ | ||
ClientId = _qqExternalAuthSettings.ClientKeyIdentifier, | ||
ClientSecret = _qqExternalAuthSettings.ClientSecret | ||
}; | ||
|
||
return View("~/Plugins/ExternalAuth.QQ/Views/Configure.cshtml", model); | ||
} | ||
|
||
[HttpPost] | ||
//[AdminAntiForgery] | ||
[AuthorizeAdmin] | ||
[Area(AreaNames.Admin)] | ||
public IActionResult Configure(ConfigurationModel model) | ||
{ | ||
if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) | ||
return AccessDeniedView(); | ||
|
||
if (!ModelState.IsValid) | ||
return Configure(); | ||
|
||
//save settings | ||
_qqExternalAuthSettings.ClientKeyIdentifier = model.ClientId; | ||
_qqExternalAuthSettings.ClientSecret = model.ClientSecret; | ||
_settingService.SaveSetting(_qqExternalAuthSettings); | ||
|
||
//clear QQ authentication options cache | ||
_optionsCache.TryRemove(QQDefaults.AuthenticationScheme); | ||
|
||
_notificationService.SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved")); | ||
|
||
return Configure(); | ||
} | ||
|
||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.