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:
Renaud Paquay
2010-10-15 14:33:02 -07:00
parent 3b33fa9edf
commit 94fee29d1a
4 changed files with 16 additions and 4 deletions

View File

@@ -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);
}
}

View File

@@ -163,6 +163,4 @@ namespace Orchard.Environment {
}
}
}
}

View File

@@ -2,6 +2,7 @@
public interface IAuthenticationService : IDependency {
void SignIn(IUser user, bool createPersistentCookie);
void SignOut();
void SetAuthenticatedUserForRequest(IUser user);
IUser GetAuthenticatedUser();
}
}

View File

@@ -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;