This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from RFGRONA/Beta
RF, Login, sessions and azure
- Loading branch information
Showing
130 changed files
with
44,130 additions
and
181 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
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,60 @@ | ||
using BioKudi.dto; | ||
using BioKudi.Models; | ||
using BioKudi.Services; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using BioKudi.Utilities; | ||
|
||
namespace BioKudi.Controllers | ||
{ | ||
[ValidateAuthentication] | ||
[Authorize(Roles = "Admin")] | ||
public class AdminController : Controller | ||
{ | ||
private readonly ILogger<AdminController> _logger; | ||
private readonly UserService userService; | ||
private readonly ActivityService activityService; | ||
|
||
public AdminController(ILogger<AdminController> logger, UserService userService, ActivityService activityService) | ||
{ | ||
_logger = logger; | ||
this.userService = userService; | ||
this.activityService = activityService; | ||
} | ||
|
||
public IActionResult IndexAdmin(UserDto user) | ||
{ | ||
user = userService.GetUser(user.UserId); | ||
return View(user); | ||
} | ||
public IActionResult ListUsers() | ||
{ | ||
var users = userService.GetAllUsers(); | ||
return View(users); | ||
} | ||
public IActionResult ListPlaces() | ||
{ | ||
return View(); | ||
} | ||
public IActionResult ListActivities() | ||
{ | ||
var activities = activityService.GetAllActivities(); | ||
return View(activities); | ||
} | ||
public IActionResult ListPictures() | ||
{ | ||
return View(); | ||
} | ||
public IActionResult ListTickets(UserDto user) | ||
{ | ||
user = userService.GetUser(user.UserId); | ||
return View(user); | ||
} | ||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = System.Diagnostics.Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,32 +1,91 @@ | ||
using BioKudi.dto; | ||
using BioKudi.Models; | ||
using BioKudi.Repository; | ||
using BioKudi.Services; | ||
using Microsoft.AspNetCore.Authentication.Cookies; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using BioKudi.Utilities; | ||
using System.Security.Claims; | ||
|
||
namespace BioKudi.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
private readonly ILogger<HomeController> _logger; | ||
private readonly UserService userService; | ||
|
||
public HomeController(ILogger<HomeController> logger) | ||
public HomeController(ILogger<HomeController> logger, UserService userService) | ||
{ | ||
_logger = logger; | ||
this.userService = userService; | ||
} | ||
|
||
public IActionResult Index() | ||
[ValidateLogin] | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
public IActionResult Privacy() | ||
public IActionResult AccessDenied() | ||
{ | ||
return View(); | ||
} | ||
|
||
[ValidateLogin] | ||
public IActionResult Login() | ||
{ | ||
UserDto user = new UserDto(); | ||
return View(user); | ||
|
||
} | ||
|
||
public IActionResult Register() | ||
{ | ||
UserDto user = new UserDto(); | ||
return View(user); | ||
} | ||
|
||
public IActionResult Logout() | ||
{ | ||
HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult Login(UserDto user) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
var result = userService.LoginUser(user, ModelState); | ||
if (result == null) | ||
return View(user); | ||
UserService.AuthUser(HttpContext, user); | ||
if (result.RoleName == "User") // User | ||
return RedirectToAction("IndexUser", "User", new { userId = user.UserId }); | ||
if (result.RoleName == "Admin") // Admin | ||
return RedirectToAction("IndexAdmin", "Admin", new { userId = user.UserId }); | ||
} | ||
return View(user); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult Register(UserDto user) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
var result = userService.RegisterUser(user, ModelState); | ||
if (result != null) | ||
return RedirectToAction("Login", "Home"); | ||
} | ||
return View(user); | ||
} | ||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
return View(new ErrorViewModel { RequestId = System.Diagnostics.Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} | ||
} |
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,38 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using BioKudi.Models; | ||
using System.Diagnostics; | ||
using BioKudi.dto; | ||
using BioKudi.Repository; | ||
using Microsoft.AspNetCore.Authorization; | ||
using BioKudi.Services; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using BioKudi.Utilities; | ||
|
||
namespace BioKudi.Controllers | ||
{ | ||
[ValidateAuthentication] | ||
[Authorize(Roles = "User")] | ||
public class UserController : Controller | ||
{ | ||
private readonly ILogger<UserController> _logger; | ||
private readonly UserService userService; | ||
|
||
public UserController(ILogger<UserController> logger, UserService userService) | ||
{ | ||
_logger = logger; | ||
this.userService = userService; | ||
} | ||
|
||
public IActionResult IndexUser(UserDto user) | ||
{ | ||
user = userService.GetUser(user.UserId); | ||
return View(user); | ||
} | ||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = System.Diagnostics.Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.