mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Authenticate admin user during setup phase
This is so that we don't need code all over the place to set the Owner of the CommonPart. The CommonPart will have direct access to the user. --HG-- branch : dev
This commit is contained in:
@@ -170,6 +170,10 @@ namespace Orchard.Setup.Services {
|
||||
String.Empty, String.Empty, String.Empty,
|
||||
true));
|
||||
|
||||
|
||||
var authenticationService = environment.Resolve<IAuthenticationService>();
|
||||
authenticationService.SetAuthenticatedUserForRequest(user);
|
||||
|
||||
// set site name and settings
|
||||
var siteService = environment.Resolve<ISiteService>();
|
||||
var siteSettings = siteService.GetSiteSettings().As<SiteSettingsPart>();
|
||||
@@ -265,9 +269,8 @@ namespace Orchard.Setup.Services {
|
||||
menuItem.As<MenuPart>().OnMainMenu = true;
|
||||
menuItem.As<MenuItemPart>().Url = "";
|
||||
|
||||
//Temporary fix for running setup on command line
|
||||
//null check: temporary fix for running setup in command line
|
||||
if (HttpContext.Current != null) {
|
||||
var authenticationService = environment.Resolve<IAuthenticationService>();
|
||||
authenticationService.SignIn(user, true);
|
||||
}
|
||||
}
|
||||
|
@@ -163,6 +163,4 @@ namespace Orchard.Environment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
public interface IAuthenticationService : IDependency {
|
||||
void SignIn(IUser user, bool createPersistentCookie);
|
||||
void SignOut();
|
||||
void SetAuthenticatedUserForRequest(IUser user);
|
||||
IUser GetAuthenticatedUser();
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ namespace Orchard.Security.Providers {
|
||||
private readonly IClock _clock;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private IUser _signedInUser;
|
||||
|
||||
public FormsAuthenticationService(IClock clock, IContentManager contentManager, IHttpContextAccessor httpContextAccessor) {
|
||||
_clock = clock;
|
||||
@@ -52,13 +53,22 @@ namespace Orchard.Security.Providers {
|
||||
|
||||
var httpContext = _httpContextAccessor.Current();
|
||||
httpContext.Response.Cookies.Add(cookie);
|
||||
_signedInUser = user;
|
||||
}
|
||||
|
||||
public void SignOut() {
|
||||
_signedInUser = null;
|
||||
FormsAuthentication.SignOut();
|
||||
}
|
||||
|
||||
public void SetAuthenticatedUserForRequest(IUser user) {
|
||||
_signedInUser = user;
|
||||
}
|
||||
|
||||
public IUser GetAuthenticatedUser() {
|
||||
if (_signedInUser != null)
|
||||
return _signedInUser;
|
||||
|
||||
var httpContext = _httpContextAccessor.Current();
|
||||
if (!httpContext.Request.IsAuthenticated || !(httpContext.User.Identity is FormsIdentity)) {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user