-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
5,965 additions
and
3,331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using EntityLayer.Concrete; | ||
using EntityLayer.Dtos; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlogWeb.Areas.Admin.Controllers | ||
{ | ||
[Area("Admin")] | ||
public class AuthController : Controller | ||
{ | ||
private readonly UserManager<User> _userManager; | ||
private readonly SignInManager<User> _signInManager; | ||
|
||
public AuthController(UserManager<User> userManager, SignInManager<User> signInManager) | ||
{ | ||
_userManager = userManager; | ||
_signInManager = signInManager; | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult Login() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> Login(UserLoginDto userLoginDto) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var user = await _userManager.FindByEmailAsync(userLoginDto.Email); | ||
if (user != null) | ||
{ | ||
var result = await _signInManager.PasswordSignInAsync(user, userLoginDto.Password, | ||
userLoginDto.RememberMe, false);// bu islem sonucunda bize bir result dönüyor. | ||
if (result.Succeeded) // eger bir islem sonucunda result dönülüyorsa, basarili olup olmadigi her zaman kontrol edilir | ||
{ | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
else | ||
{ | ||
ModelState.AddModelError("", "E-posta adresiniz veya şifreniz yanlıştır."); | ||
return View(); | ||
} | ||
} | ||
else | ||
{ | ||
ModelState.AddModelError("", "E-posta adresiniz veya şifreniz yanlıştır."); | ||
return View(); | ||
} | ||
} | ||
else | ||
{ | ||
return View(); | ||
} | ||
} | ||
|
||
|
||
|
||
[Authorize] | ||
[HttpGet] | ||
public async Task<IActionResult> Logut() | ||
{ | ||
await _signInManager.SignOutAsync(); | ||
return RedirectToAction("Index", "Home", new {Area = ""}); | ||
} | ||
|
||
[Authorize] | ||
[HttpGet] | ||
public ViewResult AccessDenied() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using AutoMapper; | ||
using BlogWeb.Areas.Admin.Models; | ||
using BlogWeb.Helpers.Abstract; | ||
using BusinessLayer.Abstract; | ||
using CoreLayer.Utilities.Extensions; | ||
using CoreLayer.Utilities.Results.ComplexTypes; | ||
using EntityLayer.Concrete; | ||
using EntityLayer.Dtos; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace BlogWeb.Areas.Admin.Controllers | ||
{ | ||
[Area("Admin")] | ||
public class CommentController : BaseController | ||
{ | ||
private readonly ICommentService _commentService; | ||
public CommentController(UserManager<User> userManager, IMapper mapper, IImageHelper imageHelper, ICommentService commentService) : base(userManager, mapper, imageHelper) | ||
{ | ||
_commentService = commentService; | ||
} | ||
|
||
[Authorize(Roles = "SuperAdmin,Comment.Read")] | ||
[HttpGet] | ||
public async Task<IActionResult> Index() | ||
{ | ||
var result = await _commentService.GetAllByNonDeletedAsync(); | ||
return View(result.Data); | ||
} | ||
|
||
[Authorize(Roles = "SuperAdmin,Comment.Read")] | ||
[HttpGet] | ||
public async Task<IActionResult> GetAllComments() | ||
{ | ||
var result = await _commentService.GetAllByNonDeletedAsync(); | ||
var commentsResult = JsonSerializer.Serialize(result, new JsonSerializerOptions | ||
{ | ||
ReferenceHandler = ReferenceHandler.Preserve, | ||
}); | ||
return Json(commentsResult); | ||
} | ||
|
||
[Authorize(Roles = "SuperAdmin,Comment.Read")] | ||
[HttpGet] | ||
public async Task<IActionResult> GetDetail(int commentId) | ||
{ | ||
var result = await _commentService.GetAsync(commentId); | ||
if (result.ResultStatus==ResultStatus.Success) | ||
{ | ||
return PartialView("_CommentDetailPartial", result.Data); | ||
} | ||
else | ||
{ | ||
return NotFound(); | ||
} | ||
} | ||
|
||
[Authorize(Roles = "SuperAdmin,Comment.Delete")] | ||
[HttpPost] | ||
public async Task<IActionResult> Delete(int commentId) | ||
{ | ||
var result = await _commentService.DeleteAsync(commentId, LoggedInUser.UserName); | ||
var commentResult = JsonSerializer.Serialize(result); | ||
return Json(commentResult); | ||
} | ||
|
||
[Authorize(Roles = "SuperAdmin,Comment.Update")] | ||
[HttpPost] | ||
public async Task<IActionResult> Approve(int commentId) | ||
{ | ||
var result = await _commentService.ApproveAsync(commentId, LoggedInUser.UserName); | ||
var commentResult = JsonSerializer.Serialize(result,new JsonSerializerOptions | ||
{ | ||
ReferenceHandler = ReferenceHandler.Preserve | ||
}); | ||
return Json(commentResult); | ||
} | ||
|
||
[Authorize(Roles = "SuperAdmin,Comment.Update")] | ||
[HttpGet] | ||
public async Task<IActionResult> Update(int commentId) | ||
{ | ||
var result = await _commentService.GetCommentUpdateDtoAsync(commentId); | ||
if (result.ResultStatus == ResultStatus.Success) | ||
{ | ||
return PartialView("_CommentUpdatePartial", result.Data); | ||
} | ||
else | ||
{ | ||
return NotFound(); | ||
} | ||
} | ||
|
||
[Authorize(Roles = "SuperAdmin,Comment.Update")] | ||
[HttpPost] | ||
public async Task<IActionResult> Update(CommentUpdateDto commentUpdateDto) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var result = await _commentService.UpdateAsync(commentUpdateDto, LoggedInUser.UserName); | ||
if (result.ResultStatus == ResultStatus.Success) | ||
{ | ||
var commentUpdateAjaxModel = JsonSerializer.Serialize(new CommentUpdateAjaxViewModel | ||
{ | ||
CommentDto = result.Data, | ||
CommentUpdatePartial = await this.RenderViewToStringAsync("_CommentUpdatePartial", commentUpdateDto) | ||
},new JsonSerializerOptions | ||
{ | ||
ReferenceHandler = ReferenceHandler.Preserve | ||
}); | ||
return Json(commentUpdateAjaxModel); | ||
} | ||
} | ||
var commentUpdateAjaxErrorModel = JsonSerializer.Serialize(new CommentUpdateAjaxViewModel | ||
{ | ||
CommentUpdatePartial = await this.RenderViewToStringAsync("_CommentUpdatePartial", commentUpdateDto) | ||
}); | ||
return Json(commentUpdateAjaxErrorModel); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using EntityLayer.Concrete; | ||
using EntityLayer.Dtos; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace BlogWeb.Areas.Admin.Controllers | ||
{ | ||
[Area("Admin")] | ||
public class RoleController : Controller | ||
{ | ||
private readonly RoleManager<Role> _roleManager; | ||
|
||
public RoleController(RoleManager<Role> roleManager) | ||
{ | ||
_roleManager = roleManager; | ||
} | ||
|
||
|
||
[Authorize(Roles = "SuperAdmin,Role.Read")] | ||
[HttpGet] | ||
public async Task<IActionResult> Index() | ||
{ | ||
var roles = await _roleManager.Roles.ToListAsync(); | ||
return View(new RoleListDto | ||
{ | ||
Roles = roles | ||
}); | ||
} | ||
|
||
[Authorize(Roles = "SuperAdmin,Role.Read")] | ||
[HttpGet] | ||
public async Task<IActionResult> GetAllRoles() | ||
{ | ||
var roles = await _roleManager.Roles.ToListAsync(); | ||
var roleListDto = JsonSerializer.Serialize(new RoleListDto | ||
{ | ||
Roles = roles | ||
}); | ||
return Json(roleListDto); | ||
} | ||
} | ||
} |
Oops, something went wrong.