mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -6,13 +6,13 @@
|
||||
clear:right;
|
||||
float:right;
|
||||
}
|
||||
.content-localization .content-localizations {
|
||||
font-size:.9em;
|
||||
}
|
||||
.content-localization .content-localizations li,
|
||||
.content-localization .add-localization {
|
||||
font-size:1.2em;
|
||||
}
|
||||
.content-localization .content-localizations {
|
||||
font-size:.9em;
|
||||
}
|
||||
.content-localization .content-localizations>* {
|
||||
display:inline-block;
|
||||
}
|
||||
|
@@ -55,10 +55,6 @@ namespace Orchard.Packaging.Controllers {
|
||||
return View(new PackagingAddSourceViewModel());
|
||||
}
|
||||
|
||||
public ActionResult AddSourceViewResult(PackagingAddSourceViewModel model) {
|
||||
return View("AddSource", model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult AddSource(string url) {
|
||||
try {
|
||||
@@ -90,7 +86,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
}
|
||||
|
||||
if ( !ModelState.IsValid )
|
||||
return AddSourceViewResult(new PackagingAddSourceViewModel(){ Url = url });
|
||||
return View(new PackagingAddSourceViewModel { Url = url });
|
||||
|
||||
_packagingSourceManager.AddSource(new PackagingSource { Id = Guid.NewGuid(), FeedUrl = url, FeedTitle = title });
|
||||
_notifier.Information(T("The feed has been added successfully."));
|
||||
@@ -99,14 +95,14 @@ namespace Orchard.Packaging.Controllers {
|
||||
}
|
||||
catch ( Exception exception ) {
|
||||
_notifier.Error(T("Adding feed failed: {0}", exception.Message));
|
||||
return AddSourceViewResult(new PackagingAddSourceViewModel() { Url = url });
|
||||
return View(new PackagingAddSourceViewModel { Url = url });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ActionResult Modules(Guid? sourceId) {
|
||||
var selectedSource = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
|
||||
|
||||
|
||||
return View("Modules", new PackagingModulesViewModel {
|
||||
Modules = _packagingSourceManager.GetModuleList(selectedSource),
|
||||
Sources = _packagingSourceManager.GetSources().OrderBy(s => s.FeedTitle),
|
||||
|
@@ -9,7 +9,6 @@ using Orchard.Settings;
|
||||
using Orchard.Tags.Models;
|
||||
using Orchard.Tags.ViewModels;
|
||||
using Orchard.Tags.Services;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Tags.Controllers {
|
||||
[ValidateInput(false)]
|
||||
@@ -22,52 +21,41 @@ namespace Orchard.Tags.Controllers {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
|
||||
public IOrchardServices Services { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
IEnumerable<Tag> tags = _tagService.GetTags();
|
||||
var entries = tags.Select(tag => CreateTagEntry(tag)).ToList();
|
||||
var model = new TagsAdminIndexViewModel { Tags = entries };
|
||||
return View(model);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Listing tags failed: " + exception.Message));
|
||||
return Index();
|
||||
}
|
||||
IEnumerable<Tag> tags = _tagService.GetTags();
|
||||
var entries = tags.Select(CreateTagEntry).ToList();
|
||||
var model = new TagsAdminIndexViewModel { Tags = entries };
|
||||
return View(model);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Index(FormCollection input) {
|
||||
var viewModel = new TagsAdminIndexViewModel { Tags = new List<TagEntry>(), BulkAction = new TagAdminIndexBulkAction() };
|
||||
UpdateModel(viewModel);
|
||||
|
||||
try {
|
||||
IEnumerable<TagEntry> checkedEntries = viewModel.Tags.Where(t => t.IsChecked);
|
||||
switch (viewModel.BulkAction) {
|
||||
case TagAdminIndexBulkAction.None:
|
||||
break;
|
||||
case TagAdminIndexBulkAction.Delete:
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTags, T("Couldn't delete tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
foreach (TagEntry entry in checkedEntries) {
|
||||
_tagService.DeleteTag(entry.Tag.Id);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
var viewModel = new TagsAdminIndexViewModel {Tags = new List<TagEntry>(), BulkAction = new TagAdminIndexBulkAction()};
|
||||
|
||||
if ( !TryUpdateModel(viewModel) ) {
|
||||
return View(viewModel);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Editing tags failed: " + exception.Message));
|
||||
return Index();
|
||||
|
||||
IEnumerable<TagEntry> checkedEntries = viewModel.Tags.Where(t => t.IsChecked);
|
||||
switch (viewModel.BulkAction) {
|
||||
case TagAdminIndexBulkAction.None:
|
||||
break;
|
||||
case TagAdminIndexBulkAction.Delete:
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTags, T("Couldn't delete tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
foreach (TagEntry entry in checkedEntries) {
|
||||
_tagService.DeleteTag(entry.Tag.Id);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
@@ -80,67 +68,62 @@ namespace Orchard.Tags.Controllers {
|
||||
[HttpPost]
|
||||
public ActionResult Create(FormCollection input) {
|
||||
var viewModel = new TagsAdminCreateViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel);
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_tagService.CreateTag(viewModel.TagName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Creating tag failed: " + exception.Message));
|
||||
|
||||
if (!TryUpdateModel(viewModel)) {
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
_tagService.CreateTag(viewModel.TagName);
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult Edit(int id) {
|
||||
try {
|
||||
Tag tag = _tagService.GetTag(id);
|
||||
var viewModel = new TagsAdminEditViewModel {
|
||||
Id = tag.Id,
|
||||
TagName = tag.TagName,
|
||||
};
|
||||
return View(viewModel);
|
||||
Tag tag = _tagService.GetTag(id);
|
||||
|
||||
if(tag == null) {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Retrieving tag information failed: " + exception.Message));
|
||||
return Index();
|
||||
}
|
||||
|
||||
var viewModel = new TagsAdminEditViewModel {
|
||||
Id = tag.Id,
|
||||
TagName = tag.TagName,
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Edit(FormCollection input) {
|
||||
var viewModel = new TagsAdminEditViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel);
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTags, T("Couldn't edit tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
_tagService.UpdateTag(viewModel.Id, viewModel.TagName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Editing tag failed: " + exception.Message));
|
||||
if ( !TryUpdateModel(viewModel) ) {
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTags, T("Couldn't edit tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
_tagService.UpdateTag(viewModel.Id, viewModel.TagName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult Search(int id) {
|
||||
try {
|
||||
Tag tag = _tagService.GetTag(id);
|
||||
IEnumerable<IContent> contents = _tagService.GetTaggedContentItems(id).ToList();
|
||||
var viewModel = new TagsAdminSearchViewModel {
|
||||
TagName = tag.TagName,
|
||||
Contents = contents,
|
||||
};
|
||||
return View(viewModel);
|
||||
Tag tag = _tagService.GetTag(id);
|
||||
|
||||
if (tag == null) {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Retrieving tagged items failed: " + exception.Message));
|
||||
return Index();
|
||||
}
|
||||
|
||||
IEnumerable<IContent> contents = _tagService.GetTaggedContentItems(id).ToList();
|
||||
var viewModel = new TagsAdminSearchViewModel {
|
||||
TagName = tag.TagName,
|
||||
Contents = contents,
|
||||
};
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
private static TagEntry CreateTagEntry(Tag tag) {
|
||||
|
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
@@ -8,23 +6,17 @@ using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tags.Helpers;
|
||||
using Orchard.Tags.Services;
|
||||
using Orchard.Tags.ViewModels;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Tags.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class HomeController : Controller {
|
||||
private readonly ITagService _tagService;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IAuthorizer _authorizer;
|
||||
|
||||
public HomeController(ITagService tagService, IAuthorizer authorizer, INotifier notifier, IContentManager contentManager) {
|
||||
public HomeController(ITagService tagService, IContentManager contentManager) {
|
||||
_tagService = tagService;
|
||||
_authorizer = authorizer;
|
||||
_notifier = notifier;
|
||||
_contentManager = contentManager;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
@@ -35,82 +27,28 @@ namespace Orchard.Tags.Controllers {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
var tags = _tagService.GetTags();
|
||||
var model = new TagsIndexViewModel { Tags = tags.ToList() };
|
||||
return View(model);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Listing tags failed: " + exception.Message));
|
||||
return Index();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Edit(FormCollection input, int taggedContentId, string returnUrl, string newTagName) {
|
||||
try {
|
||||
if (!_authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
if (!String.IsNullOrEmpty(newTagName)) {
|
||||
foreach (var tagName in TagHelpers.ParseCommaSeparatedTagNames(newTagName)) {
|
||||
if (_tagService.GetTagByName(tagName) == null) {
|
||||
_tagService.CreateTag(tagName);
|
||||
}
|
||||
_tagService.TagContentItem(taggedContentId, tagName);
|
||||
}
|
||||
}
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Editing tags failed: " + exception.Message));
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Update(string tags, int taggedContentId, string returnUrl) {
|
||||
try {
|
||||
if (!_authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
List<string> tagNames = TagHelpers.ParseCommaSeparatedTagNames(tags);
|
||||
_tagService.UpdateTagsForContentItem(taggedContentId, tagNames);
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Updating tags failed: " + exception.Message));
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
var tags = _tagService.GetTags();
|
||||
var model = new TagsIndexViewModel { Tags = tags.ToList() };
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public ActionResult Search(string tagName) {
|
||||
try {
|
||||
var tag = _tagService.GetTagByName(tagName);
|
||||
var items =
|
||||
_tagService.GetTaggedContentItems(tag.Id).Select(
|
||||
ic => _contentManager.BuildDisplayModel(ic, "SummaryForSearch"));
|
||||
var tag = _tagService.GetTagByName(tagName);
|
||||
|
||||
var viewModel = new TagsSearchViewModel {
|
||||
TagName = tag.TagName,
|
||||
Items = items.ToList()
|
||||
};
|
||||
return View(viewModel);
|
||||
|
||||
}
|
||||
catch (Exception exception) {
|
||||
if (tag == null) {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var items =
|
||||
_tagService.GetTaggedContentItems(tag.Id).Select(
|
||||
ic => _contentManager.BuildDisplayModel(ic, "SummaryForSearch"));
|
||||
|
||||
var viewModel = new TagsSearchViewModel {
|
||||
TagName = tag.TagName,
|
||||
Items = items.ToList()
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ namespace Orchard.Tags.Services {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public IEnumerable<Tag> GetTags() {
|
||||
return from tags in _tagRepository.Table.ToList() select tags;
|
||||
return _tagRepository.Table.ToList();
|
||||
}
|
||||
|
||||
public Tag GetTag(int id) {
|
||||
@@ -59,7 +59,7 @@ namespace Orchard.Tags.Services {
|
||||
_tagRepository.Create(tag);
|
||||
}
|
||||
else {
|
||||
_notifier.Warning(T("Couldn't create tag: " + tagName + "it already exixts"));
|
||||
_notifier.Warning(T("The tag {0} already exists", tagName));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Tags.ViewModels {
|
||||
public class TagsAdminCreateViewModel : BaseViewModel {
|
||||
[Required, DisplayName("Name:")]
|
||||
[Required, DisplayName("Name")]
|
||||
public string TagName { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ using Orchard.Mvc.ViewModels;
|
||||
namespace Orchard.Tags.ViewModels {
|
||||
public class TagsAdminEditViewModel : BaseViewModel {
|
||||
public int Id { get; set; }
|
||||
[Required, DisplayName("Name:")]
|
||||
[Required, DisplayName("Name")]
|
||||
public string TagName { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -4,8 +4,10 @@
|
||||
<% using(Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%: Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
<label for="TagName"><%: T("Name:")%></label>
|
||||
<input id="TagName" class="text" name="TagName" type="text" value="<%: Model.TagName %>" />
|
||||
<input type="submit" class="button" value="<%: T("Save") %>" />
|
||||
<%: Html.LabelFor(m => m.TagName) %>
|
||||
<%: Html.TextBoxFor(m => m.TagName, new { @class = "text" })%>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<input class="button primaryAction" type="submit" value="<%:T("Save") %>" />
|
||||
</fieldset>
|
||||
<% } %>
|
@@ -4,9 +4,11 @@
|
||||
<% using(Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%: Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
<label for="Name"><%: T("Name:") %></label>
|
||||
<input id="Id" name="Id" type="hidden" value="<%=Model.Id %>" />
|
||||
<input id="TagName" class="text" name="TagName" type="text" value="<%: Model.TagName %>" />
|
||||
<input type="submit" class="button" value="<%: T("Save") %>" />
|
||||
</fieldset>
|
||||
<%: Html.HiddenFor(m => m.Id) %>
|
||||
<%: Html.LabelFor(m => m.TagName) %>
|
||||
<%: Html.TextBoxFor(m => m.TagName, new { @class = "text" })%>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<input class="button primaryAction" type="submit" value="<%:T("Save") %>" />
|
||||
</fieldset>
|
||||
<% } %>
|
@@ -315,29 +315,25 @@ span.message {
|
||||
|
||||
/* Localization
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
.content-localization .content-localizations h4 {
|
||||
margin:0;
|
||||
vertical-align:top;
|
||||
}
|
||||
.content-localization .content-localizations ul {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
|
||||
.content-localization .content-localizations li {
|
||||
border-bottom: 1px;
|
||||
float: left;
|
||||
margin-left:.5em;
|
||||
padding: 3px;
|
||||
margin:0 0 0 .4em;
|
||||
padding: .2em .4em;
|
||||
border: 1px solid #CCC;
|
||||
}
|
||||
|
||||
.content-localization .content-localizations li:hover {
|
||||
background-color: #ebebeb;
|
||||
}
|
||||
|
||||
|
||||
.content-localization .content-localizations li a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.content-localization .content-localizations li a:hover, .content-localization .content-localizations li a:visited {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
@@ -363,29 +363,26 @@ span.message {
|
||||
|
||||
/* Localization
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
.content-localization .content-localizations h4 {
|
||||
margin: 0;
|
||||
vertical-align: top;
|
||||
}
|
||||
.content-localization .content-localizations ul {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
|
||||
.content-localization .content-localizations li {
|
||||
font-size: 1.0em !important;
|
||||
border-bottom: 1px;
|
||||
float: left;
|
||||
margin-left:.5em;
|
||||
padding: 3px;
|
||||
margin: 0 0 0 4px;
|
||||
padding: 2px 6px;
|
||||
border: 1px solid #CCC;
|
||||
}
|
||||
|
||||
.content-localization .content-localizations li:hover {
|
||||
background-color: #ebebeb;
|
||||
background-color: #000;
|
||||
}
|
||||
|
||||
|
||||
.content-localization .content-localizations li a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.content-localization .content-localizations li a:hover, .content-localization .content-localizations li a:visited {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
@@ -417,6 +417,12 @@ html, body {background-color: #FFFFFF; background-image: url(../Content/Images/b
|
||||
/* Localization
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
.content-localization .content-localizations h4 {
|
||||
margin:0;
|
||||
padding:3px 0 0 0;
|
||||
vertical-align:top;
|
||||
}
|
||||
|
||||
.content-localization .content-localizations ul {
|
||||
overflow: auto;
|
||||
}
|
||||
@@ -426,7 +432,7 @@ html, body {background-color: #FFFFFF; background-image: url(../Content/Images/b
|
||||
border-bottom: 1px;
|
||||
float: left;
|
||||
margin-left:.5em;
|
||||
padding: 3px;
|
||||
padding: 3px 6px;
|
||||
border: 1px solid #CCC;
|
||||
}
|
||||
|
||||
|
@@ -382,32 +382,28 @@ span.message {
|
||||
|
||||
/* Localization
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
.content-localization .content-localizations h4 {
|
||||
margin:0;
|
||||
vertical-align:top;
|
||||
}
|
||||
.content-localization .content-localizations ul {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
|
||||
.content-localization .content-localizations li {
|
||||
border-bottom: 1px;
|
||||
float: left;
|
||||
margin-left:.5em;
|
||||
padding: 3px;
|
||||
margin:0 0 0 4px;
|
||||
padding: 2px 6px;
|
||||
border: 1px solid #CCC;
|
||||
}
|
||||
|
||||
.content-localization .content-localizations li:hover {
|
||||
background-color: #ebebeb;
|
||||
}
|
||||
|
||||
|
||||
.content-localization .content-localizations li a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.content-localization .content-localizations li a:hover, .content-localization .content-localizations li a:visited {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Edit mode
|
||||
|
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using System.Web.Security;
|
||||
@@ -15,11 +10,9 @@ namespace PackageIndexReferenceImplementation.Controllers {
|
||||
public class AccountController : Controller {
|
||||
|
||||
public IFormsAuthenticationService FormsService { get; set; }
|
||||
public IMembershipService MembershipService { get; set; }
|
||||
|
||||
protected override void Initialize(RequestContext requestContext) {
|
||||
if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
|
||||
if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
|
||||
|
||||
base.Initialize(requestContext);
|
||||
}
|
||||
@@ -35,7 +28,7 @@ namespace PackageIndexReferenceImplementation.Controllers {
|
||||
[HttpPost]
|
||||
public ActionResult LogOn(LogOnModel model, string returnUrl) {
|
||||
if (ModelState.IsValid) {
|
||||
if (MembershipService.ValidateUser(model.UserName, model.Password)) {
|
||||
if ( FormsAuthentication.Authenticate(model.UserName, model.Password) ) {
|
||||
FormsService.SignIn(model.UserName, model.RememberMe);
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
@@ -63,69 +56,8 @@ namespace PackageIndexReferenceImplementation.Controllers {
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
// **************************************
|
||||
// URL: /Account/Register
|
||||
// **************************************
|
||||
|
||||
public ActionResult Register() {
|
||||
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
|
||||
return View();
|
||||
public ActionResult SHA1(string password) {
|
||||
return new ContentResult { Content = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1") };
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Register(RegisterModel model) {
|
||||
if (ModelState.IsValid) {
|
||||
// Attempt to register the user
|
||||
MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
|
||||
|
||||
if (createStatus == MembershipCreateStatus.Success) {
|
||||
FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else {
|
||||
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
|
||||
return View(model);
|
||||
}
|
||||
|
||||
// **************************************
|
||||
// URL: /Account/ChangePassword
|
||||
// **************************************
|
||||
|
||||
[Authorize]
|
||||
public ActionResult ChangePassword() {
|
||||
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult ChangePassword(ChangePasswordModel model) {
|
||||
if (ModelState.IsValid) {
|
||||
if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword)) {
|
||||
return RedirectToAction("ChangePasswordSuccess");
|
||||
}
|
||||
else {
|
||||
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
|
||||
return View(model);
|
||||
}
|
||||
|
||||
// **************************************
|
||||
// URL: /Account/ChangePasswordSuccess
|
||||
// **************************************
|
||||
|
||||
public ActionResult ChangePasswordSuccess() {
|
||||
return View();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ namespace PackageIndexReferenceImplementation.Controllers {
|
||||
var user = Encoding.UTF8.GetString(Convert.FromBase64String(HttpContext.Request.Headers["User"]));
|
||||
var password = Encoding.UTF8.GetString(Convert.FromBase64String(HttpContext.Request.Headers["Password"]));
|
||||
|
||||
if ( !MembershipService.ValidateUser(user, password) ) {
|
||||
if ( !FormsAuthentication.Authenticate(user, password) ) {
|
||||
throw new AuthenticationException("This credentials are not valid fo this action.");
|
||||
}
|
||||
|
||||
|
@@ -112,10 +112,7 @@
|
||||
<Content Include="Scripts\MicrosoftMvcAjax.debug.js" />
|
||||
<Content Include="Scripts\MicrosoftMvcValidation.js" />
|
||||
<Content Include="Scripts\MicrosoftMvcValidation.debug.js" />
|
||||
<Content Include="Views\Account\ChangePassword.aspx" />
|
||||
<Content Include="Views\Account\ChangePasswordSuccess.aspx" />
|
||||
<Content Include="Views\Account\LogOn.aspx" />
|
||||
<Content Include="Views\Account\Register.aspx" />
|
||||
<Content Include="Views\Home\About.aspx" />
|
||||
<Content Include="Views\Home\Index.aspx" />
|
||||
<Content Include="Views\Shared\Error.aspx" />
|
||||
|
@@ -1,52 +0,0 @@
|
||||
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PackageIndexReferenceImplementation.Models.ChangePasswordModel>" %>
|
||||
|
||||
<asp:Content ID="changePasswordTitle" ContentPlaceHolderID="TitleContent" runat="server">
|
||||
Change Password
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="changePasswordContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||
<h2>Change Password</h2>
|
||||
<p>
|
||||
Use the form below to change your password.
|
||||
</p>
|
||||
<p>
|
||||
New passwords are required to be a minimum of <%: ViewData["PasswordLength"] %> characters in length.
|
||||
</p>
|
||||
|
||||
<% using (Html.BeginForm()) { %>
|
||||
<%: Html.ValidationSummary(true, "Password change was unsuccessful. Please correct the errors and try again.") %>
|
||||
<div>
|
||||
<fieldset>
|
||||
<legend>Account Information</legend>
|
||||
|
||||
<div class="editor-label">
|
||||
<%: Html.LabelFor(m => m.OldPassword) %>
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<%: Html.PasswordFor(m => m.OldPassword) %>
|
||||
<%: Html.ValidationMessageFor(m => m.OldPassword) %>
|
||||
</div>
|
||||
|
||||
<div class="editor-label">
|
||||
<%: Html.LabelFor(m => m.NewPassword) %>
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<%: Html.PasswordFor(m => m.NewPassword) %>
|
||||
<%: Html.ValidationMessageFor(m => m.NewPassword) %>
|
||||
</div>
|
||||
|
||||
<div class="editor-label">
|
||||
<%: Html.LabelFor(m => m.ConfirmPassword) %>
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<%: Html.PasswordFor(m => m.ConfirmPassword) %>
|
||||
<%: Html.ValidationMessageFor(m => m.ConfirmPassword) %>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<input type="submit" value="Change Password" />
|
||||
</p>
|
||||
</fieldset>
|
||||
</div>
|
||||
<% } %>
|
||||
</asp:Content>
|
@@ -1,12 +0,0 @@
|
||||
<%@Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
|
||||
|
||||
<asp:Content ID="changePasswordTitle" ContentPlaceHolderID="TitleContent" runat="server">
|
||||
Change Password
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="changePasswordSuccessContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||
<h2>Change Password</h2>
|
||||
<p>
|
||||
Your password has been changed successfully.
|
||||
</p>
|
||||
</asp:Content>
|
@@ -1,60 +0,0 @@
|
||||
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PackageIndexReferenceImplementation.Models.RegisterModel>" %>
|
||||
|
||||
<asp:Content ID="registerTitle" ContentPlaceHolderID="TitleContent" runat="server">
|
||||
Register
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="registerContent" ContentPlaceHolderID="MainContent" runat="server">
|
||||
<h2>Create a New Account</h2>
|
||||
<p>
|
||||
Use the form below to create a new account.
|
||||
</p>
|
||||
<p>
|
||||
Passwords are required to be a minimum of <%: ViewData["PasswordLength"] %> characters in length.
|
||||
</p>
|
||||
|
||||
<% using (Html.BeginForm()) { %>
|
||||
<%: Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.") %>
|
||||
<div>
|
||||
<fieldset>
|
||||
<legend>Account Information</legend>
|
||||
|
||||
<div class="editor-label">
|
||||
<%: Html.LabelFor(m => m.UserName) %>
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<%: Html.TextBoxFor(m => m.UserName) %>
|
||||
<%: Html.ValidationMessageFor(m => m.UserName) %>
|
||||
</div>
|
||||
|
||||
<div class="editor-label">
|
||||
<%: Html.LabelFor(m => m.Email) %>
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<%: Html.TextBoxFor(m => m.Email) %>
|
||||
<%: Html.ValidationMessageFor(m => m.Email) %>
|
||||
</div>
|
||||
|
||||
<div class="editor-label">
|
||||
<%: Html.LabelFor(m => m.Password) %>
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<%: Html.PasswordFor(m => m.Password) %>
|
||||
<%: Html.ValidationMessageFor(m => m.Password) %>
|
||||
</div>
|
||||
|
||||
<div class="editor-label">
|
||||
<%: Html.LabelFor(m => m.ConfirmPassword) %>
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<%: Html.PasswordFor(m => m.ConfirmPassword) %>
|
||||
<%: Html.ValidationMessageFor(m => m.ConfirmPassword) %>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<input type="submit" value="Register" />
|
||||
</p>
|
||||
</fieldset>
|
||||
</div>
|
||||
<% } %>
|
||||
</asp:Content>
|
@@ -6,15 +6,10 @@
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<connectionStrings>
|
||||
<add name="ApplicationServices"
|
||||
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
|
||||
providerName="System.Data.SqlClient" />
|
||||
</connectionStrings>
|
||||
|
||||
<appSettings>
|
||||
<add key="Title" value="Orchard Modules Gallery"/>
|
||||
</appSettings>
|
||||
|
||||
<system.web>
|
||||
|
||||
<compilation debug="true" targetFramework="4.0">
|
||||
@@ -26,34 +21,15 @@
|
||||
</compilation>
|
||||
|
||||
<authentication mode="Forms">
|
||||
<forms loginUrl="~/Account/LogOn" timeout="2880" />
|
||||
<forms loginUrl="~/Account/LogOn" timeout="2880">
|
||||
<credentials passwordFormat="SHA1">
|
||||
<user name="UserName1" password="SHA1EncryptedPassword1"/>
|
||||
<user name="UserName2" password="SHA1EncryptedPassword2"/>
|
||||
<user name="UserName3" password="SHA1EncryptedPassword3"/>
|
||||
</credentials>
|
||||
</forms>
|
||||
</authentication>
|
||||
|
||||
<membership>
|
||||
<providers>
|
||||
<clear/>
|
||||
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
|
||||
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
|
||||
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
|
||||
applicationName="/" />
|
||||
</providers>
|
||||
</membership>
|
||||
|
||||
<profile>
|
||||
<providers>
|
||||
<clear/>
|
||||
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
|
||||
</providers>
|
||||
</profile>
|
||||
|
||||
<roleManager enabled="false">
|
||||
<providers>
|
||||
<clear/>
|
||||
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
|
||||
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
|
||||
</providers>
|
||||
</roleManager>
|
||||
|
||||
<pages>
|
||||
<namespaces>
|
||||
<add namespace="System.Web.Mvc" />
|
||||
@@ -77,5 +53,6 @@
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
|
||||
</configuration>
|
||||
|
||||
|
Reference in New Issue
Block a user