Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation to person page #74

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CheckDrive.Web/CheckDrive.Web/CheckDrive.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="25.1.42" />
<PackageReference Include="Syncfusion.Licensing" Version="25.2.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
<PackageReference Include="System.Security.Claims" Version="4.3.0" />

</ItemGroup>

Expand Down
36 changes: 27 additions & 9 deletions CheckDrive.Web/CheckDrive.Web/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using CheckDrive.Web.Constants;
using CheckDrive.Web.Models;
using CheckDrive.Web.Stores.User;
using CheckDrive.Web.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;

namespace CheckDrive.Web.Controllers
{
Expand Down Expand Up @@ -41,16 +44,31 @@ public async Task<IActionResult> Index(LoginViewModel loginViewModel)

var (success, token) = await _userDataStore.AuthenticateLoginAsync(user);

if (success)
var tokenHandler = new JwtSecurityTokenHandler();
var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken;
if (jwtToken == null)
{
HttpContext.Response.Cookies.Append("tasty-cookies", token, new CookieOptions
{
Secure = true,
SameSite = SameSiteMode.Strict,
HttpOnly = true,
IsEssential = true
});
return RedirectToAction("Index", "Dashboard");
return RedirectToAction("Login", "Account");
}
var roleId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.Role).Value;

switch (roleId)
{
case "1":
return RedirectToAction("Index", "Dashboard");
break;
case "3":
return RedirectToAction("Index", "PersonalDoctorReviews");
break;
case "4":
return RedirectToAction("Index", "PersonalOperatorReviews");
break;
case "5":
return RedirectToAction("Index", "Dashboard");
break;
case "6":
return RedirectToAction("Index", "Dashboard");
break;
}

ModelState.AddModelError(string.Empty, "Invalid login attempt.");
Expand Down
Loading