forked from grandnode/grandnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopicController.cs
More file actions
111 lines (94 loc) · 4.09 KB
/
Copy pathTopicController.cs
File metadata and controls
111 lines (94 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using Grand.Core;
using Grand.Services.Localization;
using Grand.Services.Security;
using Grand.Services.Stores;
using Grand.Services.Topics;
using Grand.Web.Interfaces;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
namespace Grand.Web.Controllers
{
public partial class TopicController : BasePublicController
{
#region Fields
private readonly ITopicViewModelService _topicViewModelService;
private readonly ITopicService _topicService;
private readonly ILocalizationService _localizationService;
private readonly IStoreMappingService _storeMappingService;
private readonly IAclService _aclService;
private readonly IPermissionService _permissionService;
private readonly IWorkContext _workContext;
#endregion
#region Constructors
public TopicController(ITopicService topicService,
ITopicViewModelService topicViewModelService,
ILocalizationService localizationService,
IStoreMappingService storeMappingService,
IAclService aclService,
IPermissionService permissionService,
IWorkContext workContext)
{
this._topicService = topicService;
this._topicViewModelService = topicViewModelService;
this._localizationService = localizationService;
this._storeMappingService = storeMappingService;
this._aclService = aclService;
this._permissionService = permissionService;
this._workContext = workContext;
}
#endregion
#region Methods
public virtual async Task<IActionResult> TopicDetails(string topicId)
{
var model = await _topicViewModelService.TopicDetails(topicId);
if (model == null)
return RedirectToRoute("HomePage");
//template
var templateViewPath = await _topicViewModelService.PrepareTopicTemplateViewPath(model.TopicTemplateId);
//display "edit" (manage) link
if (await _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && await _permissionService.Authorize(StandardPermissionProvider.ManageTopics))
DisplayEditLink(Url.Action("Edit", "Topic", new { id = model.Id, area = "Admin" }));
return View(templateViewPath, model);
}
public virtual async Task<IActionResult> TopicDetailsPopup(string systemName)
{
var model = await _topicViewModelService.TopicDetailsPopup(systemName);
if (model == null)
return RedirectToRoute("HomePage");
//template
var templateViewPath = await _topicViewModelService.PrepareTopicTemplateViewPath(model.TopicTemplateId);
ViewBag.IsPopup = true;
return View(templateViewPath, model);
}
[HttpPost]
public virtual async Task<IActionResult> Authenticate(string id, string password)
{
var authResult = false;
var title = string.Empty;
var body = string.Empty;
var error = string.Empty;
var topic = await _topicService.GetTopicById(id);
if (topic != null &&
//password protected?
topic.IsPasswordProtected &&
//store mapping
_storeMappingService.Authorize(topic) &&
//ACL (access control list)
_aclService.Authorize(topic))
{
if (topic.Password != null && topic.Password.Equals(password))
{
authResult = true;
title = topic.GetLocalized(x => x.Title, _workContext.WorkingLanguage.Id);
body = topic.GetLocalized(x => x.Body, _workContext.WorkingLanguage.Id);
}
else
{
error = _localizationService.GetResource("Topic.WrongPassword");
}
}
return Json(new { Authenticated = authResult, Title = title, Body = body, Error = error });
}
#endregion
}
}