Skip to content

Commit 3b2f320

Browse files
committed
Safety check
1 parent 8b848ba commit 3b2f320

File tree

10 files changed

+97
-20
lines changed

10 files changed

+97
-20
lines changed

EPAM.MyBlog.UI.Web/Controllers/AdminController.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,7 @@ public ActionResult DeletePost(Guid id, ConfirmModel model, string name)
147147
}
148148
}
149149

150-
/// <summary>
151-
/// Доделать
152-
/// </summary>
153-
/// <param name="Id"></param>
154-
/// <param name="ReturnUrl"></param>
155-
/// <returns></returns>
156-
///
150+
157151
[Authorize(Roles = "Admin, Moder")]
158152
public ActionResult DeleteComment(Guid Id, string name)
159153
{

EPAM.MyBlog.UI.Web/Controllers/PostController.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public ActionResult Delete(Guid Id)
143143
{
144144
var post = PostModel.GetPostById(Id);
145145
ViewData["name"] = post.Title;
146+
TempData["author"] = post.Author;
146147
if (Request.IsAjaxRequest())
147148
return PartialView("Delete");
148149
return View();
@@ -155,15 +156,26 @@ public ActionResult Delete(Guid id, ConfirmModel model)
155156
{
156157
if (model.Confirm)
157158
{
158-
159-
if (PostModel.Delete(id))
159+
string Author = TempData["author"].ToString();
160+
if (Author == User.Identity.Name)
160161
{
161-
logger.Info("Удален пост id: " + id + "у пользователя: " + User.Identity.Name);
162-
return RedirectToAction("MyPosts", "Post");
162+
163+
if (PostModel.Delete(id))
164+
{
165+
logger.Info("Удален пост id: " + id + "у пользователя: " + User.Identity.Name);
166+
return RedirectToAction("MyPosts", "Post");
167+
}
168+
else
169+
{
170+
logger.Error("Ошибка при удалении поста id: " + id + "у пользователя: " + User.Identity.Name);
171+
if (Request.IsAjaxRequest())
172+
return PartialView("Delete", new { Id = id });
173+
return View();
174+
}
163175
}
164-
else
176+
else
165177
{
166-
logger.Error("Ошибка при удалении поста id: " + id + "у пользователя: " + User.Identity.Name);
178+
logger.Info(String.Format("попытка несанкционированного удаления поста: {0} у пользователя: {1} пользователем: {2}",id, Author,User.Identity.Name));
167179
if (Request.IsAjaxRequest())
168180
return PartialView("Delete", new { Id = id });
169181
return View();
@@ -182,6 +194,7 @@ public ActionResult Delete(Guid id, ConfirmModel model)
182194
public ActionResult DeleteFavorite(Guid Id)
183195
{
184196
var post = PostModel.GetPostById(Id);
197+
TempData["author"] = post.Author;
185198
ViewData["name"] = post.Title;
186199
if (Request.IsAjaxRequest())
187200
return PartialView("DeleteFavorite");
@@ -195,14 +208,25 @@ public ActionResult DeleteFavorite(Guid id, ConfirmModel model)
195208
{
196209
if (model.Confirm)
197210
{
198-
if (PostModel.DeleteFavorite(User.Identity.Name, id))
211+
string Author = TempData["author"].ToString();
212+
if (Author == User.Identity.Name)
199213
{
200-
logger.Info("Удален пост id: " + id + "из Избранного у пользователя: " + User.Identity.Name);
201-
return RedirectToAction("Favorite", "Post");
214+
if (PostModel.DeleteFavorite(User.Identity.Name, id))
215+
{
216+
logger.Info("Удален пост id: " + id + "из Избранного у пользователя: " + User.Identity.Name);
217+
return RedirectToAction("Favorite", "Post");
218+
}
219+
else
220+
{
221+
logger.Error("Ошибка при удалении поста id: " + id + "из Избранного у пользователя: " + User.Identity.Name);
222+
if (Request.IsAjaxRequest())
223+
return PartialView("DeleteFavorite", new { Id = id });
224+
return View();
225+
}
202226
}
203227
else
204228
{
205-
logger.Error("Ошибка при удалении поста id: " + id + "из Избранного у пользователя: " + User.Identity.Name);
229+
logger.Info(String.Format("попытка несанкционированного удаления поста из избранного: {0} у пользователя: {1} пользователем: {2}", id, Author, User.Identity.Name));
206230
if (Request.IsAjaxRequest())
207231
return PartialView("DeleteFavorite", new { Id = id });
208232
return View();

EPAM.MyBlog.UI.Web/Logs/Debug/2015.02.02.log

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,34 @@
7878
2015-02-02 03:09:57,308 [18] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ������ ����: ac06c564-9a7a-497c-9703-9f1cc50f6b02
7979
2015-02-02 03:09:57,309 [18] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������ ���� id: ac06c564-9a7a-497c-9703-9f1cc50f6b02� ������������: Admin2
8080
2015-02-02 03:34:17,491 [40] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ����� �� �������: Admin2
81+
2015-02-02 11:48:12,692 [7] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ����� �� �������: Admin2
82+
2015-02-02 11:50:04,417 [7] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ����������� ������ ��� ������������: sobaka
83+
2015-02-02 11:50:04,429 [7] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �� ���������� ����������� � ������ e-mail �������: [email protected]
84+
2015-02-02 11:50:04,460 [7] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����� ������������: sobaka
85+
2015-02-02 11:50:04,464 [7] INFO EPAM.MyBlog.UI.Web.Models.RegModel [(null)] - ��������������� ����� ������������: sobaka
86+
2015-02-02 11:53:47,296 [28] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����: 16a2cb37-aabf-4c11-a0c7-d350ee23c6cd ������������:
87+
2015-02-02 11:54:08,380 [24] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ����� ��������: sobaka
88+
2015-02-02 11:54:08,381 [24] INFO EPAM.MyBlog.UI.Web.Controllers.FilesController [(null)] - �������� ������ ������� �������������: sobaka
89+
2015-02-02 11:54:08,415 [26] INFO EPAM.MyBlog.UI.Web.Controllers.FilesController [(null)] - �������� ������� �� ���� ��� ������������: sobaka
90+
2015-02-02 11:54:23,354 [25] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ����� ��������: sobaka
91+
2015-02-02 11:54:23,354 [25] INFO EPAM.MyBlog.UI.Web.Controllers.FilesController [(null)] - �������� ������ ������� �������������: sobaka
92+
2015-02-02 11:55:41,230 [14] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ������������ ������: sobaka
93+
2015-02-02 11:55:43,411 [14] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ������ ���� ������� � �������: sobaka
94+
2015-02-02 11:57:07,831 [17] INFO EPAM.MyBlog.UI.Web.Models.LoginModel [(null)] - ���� � ������� ������������: Admin2
95+
2015-02-02 12:07:58,918 [12] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����: a444bec3-98fe-41d9-964f-7b0002fd0ed0 ������������:
96+
2015-02-02 12:08:47,859 [12] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] -
97+
2015-02-02 12:08:47,860 [12] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] - ������� ������, ���������� � �������, ����� ��� "<>f__AnonymousType2`1[System.Guid]", �� ��� ����� ������� ��������� ������� ������ ���� "EPAM.MyBlog.UI.Web.Models.ConfirmModel".
98+
2015-02-02 12:09:53,696 [25] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ������ ����: a444bec3-98fe-41d9-964f-7b0002fd0ed0
99+
2015-02-02 12:09:53,709 [25] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������ ���� id: a444bec3-98fe-41d9-964f-7b0002fd0ed0� ������������: Admin2
100+
2015-02-02 12:10:06,211 [19] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����: d31d9b1c-4dcb-44e2-a351-557d4efd43de ������������:
101+
2015-02-02 12:10:46,052 [25] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ������ ����: d31d9b1c-4dcb-44e2-a351-557d4efd43de
102+
2015-02-02 12:10:46,052 [25] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������ ���� id: d31d9b1c-4dcb-44e2-a351-557d4efd43de� ������������: Admin2
103+
2015-02-02 12:14:39,885 [8] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����: 1d8c061b-9ec5-4b96-9eb4-dd4f5a181293 ������������:
104+
2015-02-02 12:14:58,516 [32] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ����� �� �������: Admin2
105+
2015-02-02 12:15:09,503 [7] INFO EPAM.MyBlog.UI.Web.Models.LoginModel [(null)] - ���� � ������� ������������: JemJem
106+
2015-02-02 12:15:16,486 [8] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������� �������������������� �������� �����: 1d8c061b-9ec5-4b96-9eb4-dd4f5a181293 � ������������: Admin2 �������������: JemJem
107+
2015-02-02 12:15:16,513 [8] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] -
108+
2015-02-02 12:15:16,514 [8] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] - ������� ������, ���������� � �������, ����� ��� "<>f__AnonymousType2`1[System.Guid]", �� ��� ����� ������� ��������� ������� ������ ���� "EPAM.MyBlog.UI.Web.Models.ConfirmModel".
109+
2015-02-02 12:15:39,209 [10] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������� �������������������� �������� �����: 1d8c061b-9ec5-4b96-9eb4-dd4f5a181293 � ������������: Admin2 �������������: JemJem
110+
2015-02-02 12:15:53,369 [10] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] -
111+
2015-02-02 12:15:53,370 [10] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] - ������� ������, ���������� � �������, ����� ��� "<>f__AnonymousType2`1[System.Guid]", �� ��� ����� ������� ��������� ������� ������ ���� "EPAM.MyBlog.UI.Web.Models.ConfirmModel".

EPAM.MyBlog.UI.Web/Logs/Errors/2015.02.02.log

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,34 @@
7878
2015-02-02 03:09:57,308 [18] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ������ ����: ac06c564-9a7a-497c-9703-9f1cc50f6b02
7979
2015-02-02 03:09:57,309 [18] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������ ���� id: ac06c564-9a7a-497c-9703-9f1cc50f6b02� ������������: Admin2
8080
2015-02-02 03:34:17,491 [40] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ����� �� �������: Admin2
81+
2015-02-02 11:48:12,692 [7] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ����� �� �������: Admin2
82+
2015-02-02 11:50:04,417 [7] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ����������� ������ ��� ������������: sobaka
83+
2015-02-02 11:50:04,429 [7] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �� ���������� ����������� � ������ e-mail �������: [email protected]
84+
2015-02-02 11:50:04,460 [7] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����� ������������: sobaka
85+
2015-02-02 11:50:04,464 [7] INFO EPAM.MyBlog.UI.Web.Models.RegModel [(null)] - ��������������� ����� ������������: sobaka
86+
2015-02-02 11:53:47,296 [28] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����: 16a2cb37-aabf-4c11-a0c7-d350ee23c6cd ������������:
87+
2015-02-02 11:54:08,380 [24] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ����� ��������: sobaka
88+
2015-02-02 11:54:08,381 [24] INFO EPAM.MyBlog.UI.Web.Controllers.FilesController [(null)] - �������� ������ ������� �������������: sobaka
89+
2015-02-02 11:54:08,415 [26] INFO EPAM.MyBlog.UI.Web.Controllers.FilesController [(null)] - �������� ������� �� ���� ��� ������������: sobaka
90+
2015-02-02 11:54:23,354 [25] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ����� ��������: sobaka
91+
2015-02-02 11:54:23,354 [25] INFO EPAM.MyBlog.UI.Web.Controllers.FilesController [(null)] - �������� ������ ������� �������������: sobaka
92+
2015-02-02 11:55:41,230 [14] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ������������ ������: sobaka
93+
2015-02-02 11:55:43,411 [14] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ������ ���� ������� � �������: sobaka
94+
2015-02-02 11:57:07,831 [17] INFO EPAM.MyBlog.UI.Web.Models.LoginModel [(null)] - ���� � ������� ������������: Admin2
95+
2015-02-02 12:07:58,918 [12] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����: a444bec3-98fe-41d9-964f-7b0002fd0ed0 ������������:
96+
2015-02-02 12:08:47,859 [12] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] -
97+
2015-02-02 12:08:47,860 [12] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] - ������� ������, ���������� � �������, ����� ��� "<>f__AnonymousType2`1[System.Guid]", �� ��� ����� ������� ��������� ������� ������ ���� "EPAM.MyBlog.UI.Web.Models.ConfirmModel".
98+
2015-02-02 12:09:53,696 [25] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ������ ����: a444bec3-98fe-41d9-964f-7b0002fd0ed0
99+
2015-02-02 12:09:53,709 [25] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������ ���� id: a444bec3-98fe-41d9-964f-7b0002fd0ed0� ������������: Admin2
100+
2015-02-02 12:10:06,211 [19] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����: d31d9b1c-4dcb-44e2-a351-557d4efd43de ������������:
101+
2015-02-02 12:10:46,052 [25] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: ������ ����: d31d9b1c-4dcb-44e2-a351-557d4efd43de
102+
2015-02-02 12:10:46,052 [25] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������ ���� id: d31d9b1c-4dcb-44e2-a351-557d4efd43de� ������������: Admin2
103+
2015-02-02 12:14:39,885 [8] INFO EPAM.MyBlog.DAL.DB.DAL [(null)] - DB: �������� ����: 1d8c061b-9ec5-4b96-9eb4-dd4f5a181293 ������������:
104+
2015-02-02 12:14:58,516 [32] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ����� �� �������: Admin2
105+
2015-02-02 12:15:09,503 [7] INFO EPAM.MyBlog.UI.Web.Models.LoginModel [(null)] - ���� � ������� ������������: JemJem
106+
2015-02-02 12:15:16,486 [8] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������� �������������������� �������� �����: 1d8c061b-9ec5-4b96-9eb4-dd4f5a181293 � ������������: Admin2 �������������: JemJem
107+
2015-02-02 12:15:16,513 [8] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] -
108+
2015-02-02 12:15:16,514 [8] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] - ������� ������, ���������� � �������, ����� ��� "<>f__AnonymousType2`1[System.Guid]", �� ��� ����� ������� ��������� ������� ������ ���� "EPAM.MyBlog.UI.Web.Models.ConfirmModel".
109+
2015-02-02 12:15:39,209 [10] INFO EPAM.MyBlog.UI.Web.Controllers.AdminController [(null)] - ������� �������������������� �������� �����: 1d8c061b-9ec5-4b96-9eb4-dd4f5a181293 � ������������: Admin2 �������������: JemJem
110+
2015-02-02 12:15:53,369 [10] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] -
111+
2015-02-02 12:15:53,370 [10] ERROR EPAM.MyBlog.UI.Web.MvcApplication [(null)] - ������� ������, ���������� � �������, ����� ��� "<>f__AnonymousType2`1[System.Guid]", �� ��� ����� ������� ��������� ������� ������ ���� "EPAM.MyBlog.UI.Web.Models.ConfirmModel".

EPAM.MyBlog.UI.Web/Views/Account/Login.cshtml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ using (Html.BeginForm( "Login", "Account", FormMethod.Post, new { id = "login_fo
2727

2828
<div class="row">
2929
<div class="col-sm-2 col-md-2 col-lg-2 col-sx-2">
30-
<div>
31-
@Html.ActionLink("Забыли пароль", "Index","Home")
32-
</div>
3330
<div>
3431
@Html.ActionLink("Регистрация", "Reg")
3532
</div>
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
512 Bytes
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.v11.suo

49.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)