webdav portal Dependency resolver added
This commit is contained in:
parent
6e6b2abd8a
commit
2244ce5add
16 changed files with 210 additions and 35 deletions
|
@ -28,13 +28,21 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
{
|
||||
public class AccountController : Controller
|
||||
{
|
||||
private readonly IKernel _kernel = new StandardKernel(new NinjectSettings {AllowNullInjection = true}, new WebDavExplorerAppModule());
|
||||
private readonly AccountModel _accountModel;
|
||||
private readonly IWebDavManager _webdavManager;
|
||||
private readonly ICryptography _cryptography;
|
||||
|
||||
public AccountController(AccountModel accountModel, IWebDavManager webdavManager, ICryptography cryptography)
|
||||
{
|
||||
_accountModel = accountModel;
|
||||
_webdavManager = webdavManager;
|
||||
_cryptography = cryptography;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Login()
|
||||
{
|
||||
object isAuthentication = _kernel.Get<AccountModel>();
|
||||
if (isAuthentication != null)
|
||||
if (_accountModel != null)
|
||||
return RedirectToAction("ShowContent", "FileSystem");
|
||||
return View();
|
||||
}
|
||||
|
@ -54,16 +62,22 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
|
||||
model.Groups = ES.Services.Organizations.GetSecurityGroupsByMember(exchangeAccount.ItemId, exchangeAccount.AccountId);
|
||||
|
||||
WebDavManager manager = null;
|
||||
|
||||
try
|
||||
{
|
||||
Session[WebDavAppConfigManager.Instance.SessionKeys.AccountInfo] = model;
|
||||
Session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] = new WebDavManager(new NetworkCredential(model.Login, model.Password, WebDavAppConfigManager.Instance.UserDomain), exchangeAccount.ItemId);
|
||||
|
||||
manager = new WebDavManager(new NetworkCredential(model.Login, model.Password, WebDavAppConfigManager.Instance.UserDomain), exchangeAccount.ItemId);
|
||||
|
||||
Session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] = manager;
|
||||
}
|
||||
catch (ConnectToWebDavServerException exception)
|
||||
{
|
||||
return View(new AccountModel { LdapError = exception.Message });
|
||||
}
|
||||
return RedirectToAction("ShowContent", "FileSystem", new { org = _kernel.Get<IWebDavManager>().OrganizationName });
|
||||
|
||||
return RedirectToAction("ShowContent", "FileSystem", new { org = manager.OrganizationName });
|
||||
}
|
||||
return View(new AccountModel { LdapError = "The user name or password is incorrect" });
|
||||
}
|
||||
|
@ -78,15 +92,19 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
|
||||
private void AutheticationToServicesUsingWebsitePanelUser()
|
||||
{
|
||||
var crypto = _kernel.Get<ICryptography>();
|
||||
var websitePanelLogin = WebDavAppConfigManager.Instance.WebsitePanelConstantUserParameters.Login;
|
||||
var websitePanelPassword = crypto.Decrypt(WebDavAppConfigManager.Instance.WebsitePanelConstantUserParameters.Password);
|
||||
var websitePanelPassword = _cryptography.Decrypt(WebDavAppConfigManager.Instance.WebsitePanelConstantUserParameters.Password);
|
||||
|
||||
var authTicket = new FormsAuthenticationTicket(1, websitePanelLogin, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout),
|
||||
FormsAuthentication.SlidingExpiration, websitePanelPassword + Environment.NewLine);
|
||||
var encryptedTicket = FormsAuthentication.Encrypt(authTicket);
|
||||
var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
|
||||
|
||||
if (FormsAuthentication.SlidingExpiration)
|
||||
{
|
||||
authCookie.Expires = authTicket.Expiration;
|
||||
}
|
||||
|
||||
Response.Cookies.Add(authCookie);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,26 +22,30 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
[LdapAuthorization]
|
||||
public class FileSystemController : Controller
|
||||
{
|
||||
private readonly IKernel _kernel = new StandardKernel(new WebDavExplorerAppModule());
|
||||
private readonly IWebDavManager _webdavManager;
|
||||
|
||||
public FileSystemController(IWebDavManager webdavManager)
|
||||
{
|
||||
_webdavManager = webdavManager;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult ShowContent(string org, string pathPart = "")
|
||||
{
|
||||
var webDavManager = new StandardKernel(new WebDavExplorerAppModule()).Get<IWebDavManager>();
|
||||
if (org != webDavManager.OrganizationName)
|
||||
if (org != _webdavManager.OrganizationName)
|
||||
return new HttpStatusCodeResult(HttpStatusCode.NoContent);
|
||||
|
||||
string fileName = pathPart.Split('/').Last();
|
||||
if (webDavManager.IsFile(fileName))
|
||||
if (_webdavManager.IsFile(fileName))
|
||||
{
|
||||
var fileBytes = webDavManager.GetFileBytes(fileName);
|
||||
var fileBytes = _webdavManager.GetFileBytes(fileName);
|
||||
return File(fileBytes, MediaTypeNames.Application.Octet, fileName);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
webDavManager.OpenFolder(pathPart);
|
||||
IEnumerable<IHierarchyItem> children = webDavManager.GetChildren().Where(x => !WebDavAppConfigManager.Instance.ElementsRendering.ElementsToIgnore.Contains(x.DisplayName.Trim('/')));
|
||||
_webdavManager.OpenFolder(pathPart);
|
||||
IEnumerable<IHierarchyItem> children = _webdavManager.GetChildren().Where(x => !WebDavAppConfigManager.Instance.ElementsRendering.ElementsToIgnore.Contains(x.DisplayName.Trim('/')));
|
||||
|
||||
var model = new ModelForWebDav { Items = children.Take(WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount), UrlSuffix = pathPart };
|
||||
Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount] = WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount;
|
||||
|
@ -56,8 +60,7 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
|
||||
public ActionResult ShowOfficeDocument(string org, string pathPart = "")
|
||||
{
|
||||
var webDavManager = _kernel.Get<IWebDavManager>();
|
||||
string fileUrl = webDavManager.RootPath.TrimEnd('/') + "/" + pathPart.TrimStart('/');
|
||||
string fileUrl = _webdavManager.RootPath.TrimEnd('/') + "/" + pathPart.TrimStart('/');
|
||||
var uri = new Uri(WebDavAppConfigManager.Instance.OfficeOnline.Url).AddParameter("src", fileUrl).ToString();
|
||||
|
||||
return View(new OfficeOnlineModel(uri, new Uri(fileUrl).Segments.Last()));
|
||||
|
@ -69,9 +72,11 @@ namespace WebsitePanel.WebDavPortal.Controllers
|
|||
if (Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount] != null)
|
||||
{
|
||||
var renderedElementsCount = (int)Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount];
|
||||
var webDavManager = _kernel.Get<IWebDavManager>();
|
||||
IEnumerable<IHierarchyItem> children = webDavManager.GetChildren();
|
||||
|
||||
IEnumerable<IHierarchyItem> children = _webdavManager.GetChildren();
|
||||
|
||||
var result = children.Skip(renderedElementsCount).Take(WebDavAppConfigManager.Instance.ElementsRendering.AddElementsCount);
|
||||
|
||||
Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount] = renderedElementsCount + WebDavAppConfigManager.Instance.ElementsRendering.AddElementsCount;
|
||||
|
||||
return PartialView("_ResourseCollectionPartial", result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue