Skip to content

Commit

Permalink
Implement login and logout link
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebwar Hosain Poori authored and Rebwar Hosain Poori committed May 16, 2019
1 parent c147a8e commit 2bddc24
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 18 deletions.
17 changes: 16 additions & 1 deletion HelpDesk.MVC/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
using MD.PersianDateTime.Standard;
using Microsoft.AspNetCore.Identity;
using HelpDesk.MVC.Models.Users;
using Microsoft.AspNetCore.Authorization;

namespace HelpDesk.MVC.Controllers
{
[Authorize]
public class AdminController : Controller
{
private readonly ICategoryRepository categoryRepository;
Expand Down Expand Up @@ -56,6 +58,7 @@ public IActionResult Index()
statistics.Categories = categoryRepository.GetStatistic();
return View(statistics);
}
[Authorize(Roles ="Admin")]
public IActionResult AddCategory()
{
return View();
Expand Down Expand Up @@ -89,6 +92,8 @@ public IActionResult AddCategory(AddNewCategory model, string imagename)
}
return RedirectToAction(nameof(ListCat));
}
[Authorize(Roles = "Admin")]

public IActionResult ListCat()
{
var cat = categoryRepository.GetAll().ToList();
Expand All @@ -100,10 +105,12 @@ public IActionResult ListArticle()
var article = articleRepository.GetAll().ToList();
return View(article);
}
[Authorize(Roles = "Admin")]
public IActionResult EditCategory(int id)
{
return View();
}
[Authorize(Roles = "Admin")]
public IActionResult Delete(int id)
{
try
Expand All @@ -117,6 +124,7 @@ public IActionResult Delete(int id)
return BadRequest();
}
}
[Authorize(Roles = "Admin")]
public IActionResult Details(int Id)
{
ViewBag.type = 1;
Expand All @@ -128,6 +136,7 @@ public IActionResult Details(int Id)
return PartialView("Details", cat);

}
[Authorize(Roles = "Admin")]
public IActionResult Edit(int Id)
{
var cat = categoryRepository.Get(Id);
Expand All @@ -138,6 +147,7 @@ public IActionResult Edit(int Id)
return View(cat);
}
[HttpPost]
[Authorize(Roles = "Admin")]
public IActionResult Edit(Category category)
{
categoryRepository.Update(category);
Expand Down Expand Up @@ -378,17 +388,22 @@ public async Task<IActionResult> Upload(IFormFile file, Article article, string
}
return RedirectToAction("Index");
}

[Authorize(Roles = "Admin")]
public IActionResult UserList()
{
var userlist = userManager.Users.Take(50).ToList();
return View(userlist);

}
[Authorize(Roles = "Admin")]
public IActionResult CreateUser()
{
return View();
}
public IActionResult AccessDenied()
{
return View();
}
public IActionResult UploadFile(IFormFile files)
{
string newFileName = uploadFileRepository.UplaodFile(files, "\\Images\\Profile\\");
Expand Down
8 changes: 2 additions & 6 deletions HelpDesk.MVC/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ public IActionResult Index()
join p in desplayCategory.Articles on c.Id equals p.CategoryId
group p by c.Name into g
select new NameCount
{

{
Name = g.Key,
ArticleTitle=g.Take(5).ToList() ,
Count=g.Count()
});
nameCount = test.ToList();

ViewBag.Tops = nameCount;


ViewBag.Tops = nameCount;
var TopArticles = articleRepository.GetTopViewedArticles(5);
return View(nameCount);
}
Expand Down
4 changes: 3 additions & 1 deletion HelpDesk.MVC/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ public void ConfigureServices(IServiceCollection services)
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;

});

services.ConfigureApplicationCookie(option => option.AccessDeniedPath = "/Admin/AccessDenied");
int minPasswordLenght = int.Parse(Configuration["MinPasswordLength"]);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddDbContext<HelpDeskContext>(c => c.UseSqlServer(Configuration.GetConnectionString("HelpDesk")));
services.AddDbContext<UserDbContext>(c => c.UseSqlServer(Configuration.GetConnectionString("UserDb")));
services.AddIdentity<ApplicationUsers, ApplicaionRoles>(c =>
{

c.User.RequireUniqueEmail = true;
c.Password.RequireDigit = false;
c.Password.RequiredLength = minPasswordLenght;
Expand Down
22 changes: 22 additions & 0 deletions HelpDesk.MVC/Views/Admin/AccessDenied.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

@{
ViewData["Title"] = "AccessDenied";
Layout = "~/Views/Admin/_Layout.cshtml";
}

<section class="content">
<div class="error-page">
<h2 class="headline text-yellow"> 401</h2>

<div class="error-content">
<h3><i class="fa fa-warning text-yellow"></i> متاسفانه شما مجوز دسترسی به این قسمت را ندارید. </h3>

<p>
برای اطلاعات بیشتر با مدیریت سیستم تماس بگیرید
</p>

</div>
<!-- /.error-content -->
</div>

</section>
2 changes: 2 additions & 0 deletions HelpDesk.MVC/Views/Admin/_RightSideBar.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@


<li><a asp-action="UserList"><i class="fa fa-user"></i> <span> مدیریت کاربران</span></a></li>
<li><a asp-action="Index" asp-controller="Home"><i class="fa fa-sitemap"></i> <span> بازگشت به صفحه اصلی</span></a></li>

</ul>
<!-- /.sidebar-menu -->
</section>
Expand Down
41 changes: 31 additions & 10 deletions HelpDesk.MVC/Views/Shared/_NavBar.cshtml
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
<nav class="navbar navbar-expand-lg navbar-light ">
@using Microsoft.AspNetCore.Identity

<nav class="navbar navbar-expand-lg navbar-light ">
<div class="container">
<a class="navbar-brand" href="#">Pars<span>Sup</span></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<form asp-action="Logout" asp-controller="Admin" method="post">

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item"><a asp-action="Index" asp-controller="Home" class="nav-link active">خانه</a></li>
<li class="nav-item"><a class="nav-link" href="#about">درباره ما</a></li>
<li class="nav-item"><a class="nav-link" href="contact.html">تماس با ما</a></li>
@{
@if (User.Identity.IsAuthenticated)
{
<li class="nav-item"><a class="nav-link" asp-action="Index" asp-controller="Admin">پنل مدیریت</a></li>

<li class="nav-item">
<button type="submit" style="text-decoration:none" class="btn btn-link">خروج</button>
</li>

}
else
{

<li class="nav-item"><a class="nav-link" asp-action="Login" asp-controller="Home">ورود</a></li>

}

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item"><a asp-action="Index" asp-controller="Home" class="nav-link active">خانه</a></li>
<li class="nav-item"><a class="nav-link" href="#about">درباره ما</a></li>
<li class="nav-item"><a class="nav-link" href="contact.html">تماس با ما</a></li>
<li class="nav-item"><a class="nav-link" asp-action="Login" asp-controller="Home">ورود</a></li>
}

@*<li class="nav-item"><a class="nav-link" data-toggle="modal" data-target="#modalQuickView" style="cursor:pointer" >ثبت نام</a></li>*@
@*<li class="nav-item"><a class="nav-link" data-toggle="modal" data-target="#modalQuickView" style="cursor:pointer" >ثبت نام</a></li>*@


</ul>
</div>
</ul>
</div>
</form>
</div>

</nav>
Expand Down

0 comments on commit 2bddc24

Please sign in to comment.