Skip to content

Commit de29bb9

Browse files
authored
Merge pull request #100 from DiyorMarket/integration
Integration
2 parents 0322c08 + efee2f6 commit de29bb9

File tree

131 files changed

+8752
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+8752
-84
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
4+
name: Build and deploy ASP.Net Core app to Azure Web App - CheckDriver
5+
6+
on:
7+
push:
8+
branches:
9+
- integration
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: windows-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up .NET Core
20+
uses: actions/setup-dotnet@v1
21+
with:
22+
dotnet-version: '8.x'
23+
include-prerelease: true
24+
25+
- name: Build with dotnet
26+
run: dotnet build --configuration Release
27+
28+
- name: dotnet publish
29+
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
30+
31+
- name: Upload artifact for deployment job
32+
uses: actions/upload-artifact@v3
33+
with:
34+
name: .net-app
35+
path: ${{env.DOTNET_ROOT}}/myapp
36+
37+
deploy:
38+
runs-on: windows-latest
39+
needs: build
40+
environment:
41+
name: 'Production'
42+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
43+
permissions:
44+
id-token: write #This is required for requesting the JWT
45+
46+
steps:
47+
- name: Download artifact from build job
48+
uses: actions/download-artifact@v3
49+
with:
50+
name: .net-app
51+
52+
- name: Login to Azure
53+
uses: azure/login@v1
54+
with:
55+
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_E9AF348E5C5C43AA8D4DC6D5D7832550 }}
56+
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_C81C36AF407F47E0841F8C513B2E4689 }}
57+
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_548C4B80BB1545B19DFB28DE2B816ED6 }}
58+
59+
- name: Deploy to Azure Web App
60+
id: deploy-to-webapp
61+
uses: azure/webapps-deploy@v2
62+
with:
63+
app-name: 'CheckDriver'
64+
slot-name: 'Production'
65+
package: .
66+

CheckDrive.Web/CheckDrive.Web.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.9.34728.123
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CheckDrive.Web", "CheckDrive.Web\CheckDrive.Web.csproj", "{7F91792F-530C-4443-AC8D-04D956B346F4}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CheckDrive.Web", "CheckDrive.Web\CheckDrive.Web.csproj", "{7F91792F-530C-4443-AC8D-04D956B346F4}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<Compile Remove="Controllers\**" />
11+
<Content Remove="Controllers\**" />
12+
<EmbeddedResource Remove="Controllers\**" />
13+
<None Remove="Controllers\**" />
14+
<Compile Include="Controllers\AccountsController.cs" />
15+
<Compile Include="Controllers\AuthController.cs" />
16+
<Compile Include="Controllers\CarsController.cs" />
17+
<Compile Include="Controllers\DashboardController.cs" />
18+
<Compile Include="Controllers\DispatcherReviewsController.cs" />
19+
<Compile Include="Controllers\DoctorReviewsController.cs" />
20+
<Compile Include="Controllers\DoctorsController.cs" />
21+
<Compile Include="Controllers\DriversController.cs" />
22+
<Compile Include="Controllers\RolesController.cs" />
23+
<Compile Include="Controllers\MechanicAcceptancesController.cs" />
24+
<Compile Include="Controllers\MechanicHandoversController.cs" />
25+
<Compile Include="Controllers\MechanicsController.cs" />
26+
<Compile Include="Controllers\OperatorReviewsController.cs" />
27+
<Compile Include="Controllers\OperatorsController.cs" />
28+
<Compile Include="Controllers\TechniciansController.cs" />
29+
<PackageReference Include="CheckDrive.ApiContracts" Version="1.3.5" />
30+
<PackageReference Include="CheckDrive.DTOs" Version="1.0.0" />
31+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
32+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
33+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="25.1.42" />
34+
<PackageReference Include="Syncfusion.Licensing" Version="25.2.3" />
35+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
36+
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
37+
38+
</ItemGroup>
39+
940
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace CheckDrive.Web.Constants
2+
{
3+
public static class Configurations
4+
{
5+
public const string JwtToken = "JwtToken";
6+
public const string SynfusionLicenseKey = "Mgo+DSMBMAY9C3t2UFhhQlJBfVldWnxLflFyVWRTelx6cF1WESFaRnZdRl1mSH1TfkBgWXhXeXdV";
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using CheckDrive.ApiContracts.Account;
2+
using CheckDrive.ApiContracts.Role;
3+
using CheckDrive.Web.Stores.Accounts;
4+
using CheckDrive.Web.Stores.Roles;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.Rendering;
7+
8+
namespace CheckDrive.Web.Controllers
9+
{
10+
public class AccountsController : Controller
11+
{
12+
private readonly IAccountDataStore _accountDataStore;
13+
private readonly IRoleDataStore _roleStore;
14+
public AccountsController(IAccountDataStore accountDataStore, IRoleDataStore roleDataStore)
15+
{
16+
_roleStore = roleDataStore;
17+
_accountDataStore = accountDataStore;
18+
}
19+
20+
public async Task<IActionResult> Index(string? searchString, int? roleId, DateTime? birthDate, int? pageNumber)
21+
{
22+
var accounts = await _accountDataStore.GetAccountsAsync(searchString, roleId, birthDate, pageNumber);
23+
24+
var roles = await GETRoles();
25+
26+
roles.Insert(0, new RoleDto
27+
{
28+
Id = 0,
29+
Name = "Barcha ishchilar",
30+
});
31+
var selectedRole = roles[0];
32+
33+
if (roleId.HasValue && roleId != 0)
34+
{
35+
selectedRole = roles.FirstOrDefault(x => x.Id == roleId);
36+
}
37+
38+
ViewBag.Accounts = accounts.Data;
39+
ViewBag.Roles = roles;
40+
41+
ViewBag.PageSize = accounts.PageSize;
42+
ViewBag.PageCount = accounts.TotalPages;
43+
ViewBag.TotalCount = accounts.TotalCount;
44+
ViewBag.CurrentPage = accounts.PageNumber;
45+
ViewBag.HasPreviousPage = accounts.HasPreviousPage;
46+
ViewBag.HasNextPage = accounts.HasNextPage;
47+
48+
ViewBag.SearchString = searchString;
49+
ViewBag.CurrentRoleId = roleId;
50+
ViewBag.SelectedRole = selectedRole;
51+
52+
return View();
53+
}
54+
public async Task<IActionResult> Details(int id)
55+
{
56+
var account = await _accountDataStore.GetAccountAsync(id);
57+
if (account == null)
58+
{
59+
return NotFound();
60+
}
61+
return View(account);
62+
}
63+
public async Task<IActionResult> Create()
64+
{
65+
var roles = await GETRoles();
66+
ViewBag.Roles = new SelectList(roles, "Id", "Name");
67+
return View();
68+
}
69+
[HttpPost]
70+
[ValidateAntiForgeryToken]
71+
public async Task<IActionResult> Create([Bind("Login,Password,PhoneNumber,FirstName,LastName,Bithdate,RoleId")]
72+
AccountForCreateDto account)
73+
{
74+
if (ModelState.IsValid)
75+
{
76+
await _accountDataStore.CreateAccountAsync(account);
77+
return RedirectToAction(nameof(Index));
78+
}
79+
var roles = await GETRoles();
80+
ViewBag.Roles = new SelectList(roles, "Id", "Name");
81+
return View(account);
82+
}
83+
84+
public async Task<IActionResult> Edit(int id)
85+
{
86+
var account = await _accountDataStore.GetAccountAsync(id);
87+
if (account == null)
88+
{
89+
return NotFound();
90+
}
91+
92+
return View(account);
93+
}
94+
95+
[HttpPost]
96+
[ValidateAntiForgeryToken]
97+
public async Task<IActionResult> Edit(int id, [Bind("Id,Login,Password,PhoneNumber,FirstName,LastName,Bithdate,RoleId")]
98+
AccountForUpdateDto account)
99+
{
100+
if (ModelState.IsValid)
101+
{
102+
await _accountDataStore.UpdateAccountAsync(id, account);
103+
return RedirectToAction(nameof(Index));
104+
}
105+
return View(account);
106+
}
107+
108+
public async Task<IActionResult> Delete(int id)
109+
{
110+
var account = await _accountDataStore.GetAccountAsync(id);
111+
if (account == null)
112+
{
113+
return NotFound();
114+
}
115+
return View(account);
116+
}
117+
118+
[HttpPost, ActionName("Delete")]
119+
[ValidateAntiForgeryToken]
120+
public async Task<IActionResult> DeleteConfirmed(int id)
121+
{
122+
await _accountDataStore.DeleteAccountAsync(id);
123+
return RedirectToAction(nameof(Index));
124+
}
125+
126+
private async Task<List<RoleDto>> GETRoles()
127+
{
128+
var roleResponse = await _roleStore.GetRoles();
129+
var roles = roleResponse.Data.ToList();
130+
return roles;
131+
}
132+
}
133+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using CheckDrive.ApiContracts.Account;
2+
using CheckDrive.Web.Stores.User;
3+
using CheckDrive.Web.ViewModels;
4+
using Microsoft.AspNetCore.Mvc;
5+
using System.IdentityModel.Tokens.Jwt;
6+
using System.Security.Claims;
7+
8+
namespace CheckDrive.Web.Controllers
9+
{
10+
public class AuthController : Controller
11+
{
12+
private readonly IUserDataStore _userDataStore;
13+
public AuthController(IUserDataStore userDataStore)
14+
{
15+
_userDataStore = userDataStore;
16+
}
17+
18+
public IActionResult Login()
19+
{
20+
HttpContext.Response.Cookies.Delete("tasty-cookies");
21+
return RedirectToAction("Index", "Auth");
22+
}
23+
24+
public IActionResult Index()
25+
{
26+
if (HttpContext.Request.Cookies.TryGetValue("tasty-cookies", out _))
27+
{
28+
string token = HttpContext.Request.Cookies["tasty-cookies"];
29+
var tokenHandler = new JwtSecurityTokenHandler();
30+
var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken;
31+
if (jwtToken == null)
32+
{
33+
return RedirectToAction("Login", "Account");
34+
}
35+
var roleId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.Role).Value;
36+
37+
switch (roleId)
38+
{
39+
case "1":
40+
return RedirectToAction("Index", "Dashboard");
41+
case "3":
42+
return RedirectToAction("PersonalIndex", "DoctorReviews");
43+
case "4":
44+
return RedirectToAction("PersonalIndex", "OperatorReviews");
45+
case "5":
46+
return RedirectToAction("PersonalIndex", "DispatcherReviews");
47+
case "6":
48+
return RedirectToAction("PersonalIndex", "MechanicHandovers");
49+
}
50+
return RedirectToAction("Index", "Auth");
51+
}
52+
return View("Index");
53+
}
54+
55+
[HttpPost]
56+
public async Task<IActionResult> Index(AccountForLoginDto loginViewModel)
57+
{
58+
if (!ModelState.IsValid)
59+
{
60+
return View(loginViewModel);
61+
}
62+
63+
var user = new AccountForLoginDto
64+
{
65+
Login = loginViewModel.Login,
66+
Password = loginViewModel.Password,
67+
};
68+
69+
var (success, token) = await _userDataStore.AuthenticateLoginAsync(user);
70+
71+
if (success)
72+
{
73+
HttpContext.Response.Cookies.Append("tasty-cookies", token, new CookieOptions
74+
{
75+
Secure = true,
76+
SameSite = SameSiteMode.Strict,
77+
HttpOnly = true,
78+
IsEssential = true
79+
});
80+
81+
var tokenHandler = new JwtSecurityTokenHandler();
82+
var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken;
83+
if (jwtToken == null)
84+
{
85+
return RedirectToAction("Login", "Account");
86+
}
87+
var roleId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.Role).Value;
88+
var accountId = jwtToken.Claims.First(claim => claim.Type == ClaimTypes.NameIdentifier).Value;
89+
90+
switch (roleId)
91+
{
92+
case "1":
93+
return RedirectToAction("Index", "Dashboard");
94+
case "3":
95+
TempData["AccountId"] = accountId;
96+
return RedirectToAction("PersonalIndex", "DoctorReviews");
97+
case "4":
98+
TempData["AccountId"] = accountId;
99+
return RedirectToAction("PersonalIndex", "OperatorReviews");
100+
case "5":
101+
TempData["AccountId"] = accountId;
102+
return RedirectToAction("PersonalIndex", "DispatcherReviews");
103+
case "6":
104+
TempData["AccountId"] = accountId;
105+
return RedirectToAction("PersonalIndex", "MechanicHandovers");
106+
default:
107+
return RedirectToAction("Index", "Auth");
108+
}
109+
}
110+
111+
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
112+
ModelState.AddModelError("Password", "Incorrect password or login");
113+
return View(loginViewModel);
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)