- Timestamp:
- 11/05/20 06:57:35 (4 years ago)
- Branches:
- master
- Children:
- afc9a9a
- Parents:
- 1f4846d
- Location:
- Farmatiko
- Files:
-
- 2 added
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/ClientApp/src/app/login/login.component.html
r1f4846d rd23bf72 6 6 <div class="example-container"> 7 7 <mat-form-field> 8 <input matInput placeholder="Email" [(ngModel)]="this.username" formControlName=" email">8 <input matInput placeholder="Email" [(ngModel)]="this.username" formControlName="username"> 9 9 </mat-form-field> 10 10 -
Farmatiko/ClientApp/src/app/shared/interfaces.ts
r1f4846d rd23bf72 55 55 Passwd: string; 56 56 Name: string; 57 originalUserName?: string; 57 58 Role?: string; 58 59 } -
Farmatiko/ClientApp/src/app/shared/services/auth.service.ts
r1f4846d rd23bf72 11 11 username: string; 12 12 role: string; 13 originalUserName?: string; 13 14 accessToken: string; 14 15 refreshToken: string; 15 head : IPharmacyHead;16 head?: IPharmacyHead; 16 17 } 17 18 … … 35 36 this.http.get<LoginResult>(`${this.apiUrl}/user`).subscribe((x) => { 36 37 this._user.next({ 37 Email: x.username, 38 Role: x.role, 38 Email: x.head.Email, 39 Role: x.head.Role, 40 originalUserName: x.head.originalUserName, 39 41 Passwd: x.head.Passwd, 40 Name: x.head.Name 42 Name: x.head.Name, 43 PharmacyMedicines: x.head.PharmacyMedicines, 44 Pharmacy: x.head.Pharmacy 41 45 }); 42 46 }); … … 60 64 map((x) => { 61 65 this._user.next({ 62 Email: x.username, 63 Role: x.role, 66 Email: x.head.Email, 67 Role: x.head.Role, 68 originalUserName: x.head.originalUserName, 64 69 Passwd: x.head.Passwd, 65 Name: x.head.Name 70 Name: x.head.Name, 71 PharmacyMedicines: x.head.PharmacyMedicines, 72 Pharmacy: x.head.Pharmacy 66 73 }); 67 74 this.setLocalStorage(x); … … 98 105 map((x) => { 99 106 this._user.next({ 100 Email: x.username, 101 Role: x.role, 107 Email: x.head.Email, 108 Role: x.head.Role, 109 originalUserName: x.head.originalUserName, 102 110 Passwd: x.head.Passwd, 103 Name: x.head.Name 111 Name: x.head.Name, 112 PharmacyMedicines: x.head.PharmacyMedicines, 113 Pharmacy: x.head.Pharmacy 104 114 }); 105 115 this.setLocalStorage(x); -
Farmatiko/ClientApp/src/environments/environment.ts
r1f4846d rd23bf72 5 5 export const environment = { 6 6 production: false, 7 baseApiUrl: 'https://localhost: 44342/',7 baseApiUrl: 'https://localhost:5001/', 8 8 }; 9 9 -
Farmatiko/Controllers/AdminController.cs
r1f4846d rd23bf72 5 5 using FarmatikoData.Models; 6 6 using FarmatikoServices.FarmatikoServiceInterfaces; 7 using Microsoft.AspNetCore.Authorization; 7 8 using Microsoft.AspNetCore.Mvc; 8 9 9 10 namespace Farmatiko.Controllers 10 11 { 12 [ApiController] 13 [Authorize(Roles = "PharmacyHead")] 11 14 public class AdminController : Controller 12 15 { … … 40 43 [HttpPost] 41 44 [Route("api/pharmacyhead/add")] 42 public async Task<IActionResult> AddPharmacyHead( PharmacyHead pharmacyHead)45 public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead) 43 46 { 44 47 await _service.AddPharmacyHead(pharmacyHead); … … 46 49 } 47 50 48 [Http Post]51 [HttpDelete] 49 52 [Route("api/pharmacyhead/delete/{Id}")] 50 public async Task<IActionResult> RemovePharmacyHead([From Query]int Id)53 public async Task<IActionResult> RemovePharmacyHead([FromRoute] int Id) 51 54 { 52 55 await _service.RemovePharmacyHead(Id); 53 56 return Ok(); 54 57 } 55 [HttpPost] 56 public IActionResult RejectRequset(RequestPharmacyHead req) 58 [HttpDelete] 59 [Route("api/pharmacyhead/requests/{Id}")] 60 public IActionResult RejectRequest([FromRoute] int Id) 57 61 { 58 bool Success = _adminService.RejectRequest( req);62 bool Success = _adminService.RejectRequest(Id); 59 63 return Ok(Success); 60 64 } 61 65 [HttpPost] 62 public async Task<IActionResult> ApproveRequest(PharmacyHead pharmacyHead) 66 [Route("api/pharmacyhead/{Id}")] 67 public async Task<IActionResult> ApproveRequest([FromRoute]int Id, [FromBody]PharmacyHead pharmacyHead) 63 68 { 69 int id = Id; 64 70 await _phservice.UpdatePharmacyHead(pharmacyHead); 65 71 return Ok(); -
Farmatiko/Controllers/ErrorController.cs
r1f4846d rd23bf72 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 1 using System.Net; 2 using Microsoft.AspNetCore.Diagnostics; 5 3 using Microsoft.AspNetCore.Mvc; 4 using Microsoft.Extensions.Logging; 6 5 7 6 namespace Farmatiko.Controllers 8 7 { 8 [ApiController] 9 9 public class ErrorController : Controller 10 10 { 11 public IActionResult Index() 11 private readonly ILogger<ErrorController> _logger; 12 13 public ErrorController(ILogger<ErrorController> logger) 12 14 { 13 return View(); 15 _logger = logger; 16 } 17 [Route("/Error")] 18 public IActionResult Error() 19 { 20 var exception = HttpContext.Features.Get<IExceptionHandlerFeature>(); 21 var statusCode = exception.Error.GetType().Name switch 22 { 23 "ArgumentException" => HttpStatusCode.BadRequest, 24 "Exception" => HttpStatusCode.InternalServerError, 25 /*"NotFoundResult" => HttpStatusCode.NotFound,*/ 26 _ => HttpStatusCode.ServiceUnavailable 27 }; 28 _logger.LogInformation(statusCode.ToString() + " " + exception.ToString()); 29 return Problem(detail: exception.Error.Message, statusCode: (int)statusCode); 14 30 } 15 31 } -
Farmatiko/Controllers/FarmatikoController.cs
r1f4846d rd23bf72 11 11 { 12 12 private readonly IService _service; 13 public FarmatikoController(IService service) 13 private readonly IProcessJSONService _JSONservice; 14 public FarmatikoController(IService service, IProcessJSONService JSONservice) 14 15 { 15 16 _service = service; 17 _JSONservice = JSONservice; 16 18 } 17 19 // Workers 18 20 //Get 21 [HttpGet] 22 [Route("api/getData")] 23 public void InsertData() 24 { 25 //_JSONservice.DownloadPharmaciesExcel(); 26 //_JSONservice.GetProcessedHealthcareWorkersFromJSON(); 27 //_JSONservice.GetProcessedHealthFacilitiesFromJSON(); 28 //_JSONservice.GetProcessedMedicinesFromJSON(); 29 //_JSONservice.GetProcessedPandemicsFromJSONApi(); 30 } 19 31 [HttpGet] 20 32 [Route("api/workers")] … … 25 37 } 26 38 [HttpGet] 27 [Route("api/workers/search/{ Query}")]28 public async Task<IEnumerable<HealthcareWorker>> SearchWorkers( string Query)39 [Route("api/workers/search/{query}")] 40 public async Task<IEnumerable<HealthcareWorker>> SearchWorkers([FromRoute]string query) 29 41 { 30 return await _service.SearchWorkers( Query);42 return await _service.SearchWorkers(query); 31 43 } 32 44 [HttpGet] 33 45 [Route("api/workers/{id}")] 34 public async Task<HealthcareWorker> GetWorker( int Id)46 public async Task<HealthcareWorker> GetWorker([FromRoute] int Id) 35 47 { 36 48 return await _service.GetWorker(Id); … … 48 60 } 49 61 [HttpGet] 50 [Route("api/facilities/search/{ Query}")]51 public async Task<IEnumerable<HealthFacility>> SearchFacilities( string Query)62 [Route("api/facilities/search/{query}")] 63 public async Task<IEnumerable<HealthFacility>> SearchFacilities([FromRoute] string query) 52 64 { 53 return await _service.SearchFacilities( Query);65 return await _service.SearchFacilities(query); 54 66 } 55 67 [HttpGet] 56 [Route("api/facilities/{ Id}")]57 public async Task<HealthFacility> GetFacility( int Id)68 [Route("api/facilities/{id}")] 69 public async Task<HealthFacility> GetFacility([FromRoute] int id) 58 70 { 59 return await _service.GetFacility( Id);71 return await _service.GetFacility(id); 60 72 } 61 73 //Post … … 70 82 } 71 83 [HttpGet] 72 [Route("api/medicines/search/{ Query}")]73 public async Task<IEnumerable<Medicine>> SearchMedicines( string Query)84 [Route("api/medicines/search/{query}")] 85 public async Task<IEnumerable<Medicine>> SearchMedicines([FromRoute] string query) 74 86 { 75 return await _service.SearchMedicines( Query);87 return await _service.SearchMedicines(query); 76 88 } 77 89 [HttpGet] 78 90 [Route("api/medicines/{Id}")] 79 public async Task<Medicine> GetMedicine( int Id)91 public async Task<Medicine> GetMedicine([FromRoute] int Id) 80 92 { 81 93 return await _service.GetMedicine(Id); … … 98 110 [HttpGet] 99 111 [Route("api/pharmacy/search/{Query}")] 100 public async Task<IEnumerable<Pharmacy>> SearchPharmacies( string Query)112 public async Task<IEnumerable<Pharmacy>> SearchPharmacies([FromRoute] string Query) 101 113 { 102 114 return await _service.SearchPharmacies(Query); … … 104 116 [HttpGet] 105 117 [Route("api/pharmacy/{Id}")] 106 public async Task<Pharmacy> GetPharmacy( int Id)118 public async Task<Pharmacy> GetPharmacy([FromRoute] int Id) 107 119 { 108 120 return await _service.GetPharmacy(Id); -
Farmatiko/Controllers/PharmacyHeadController.cs
r1f4846d rd23bf72 1 using System.Collections; 2 using System.Collections.Generic; 3 using System.Linq; 1 using System.Collections.Generic; 4 2 using System.Threading.Tasks; 5 using FarmatikoData.FarmatikoRepoInterfaces;6 3 using FarmatikoData.Models; 7 4 using FarmatikoServices.FarmatikoServiceInterfaces; 5 using Microsoft.AspNetCore.Authorization; 8 6 using Microsoft.AspNetCore.Mvc; 9 7 … … 11 9 { 12 10 [ApiController] 11 [Authorize(Roles = "PharmacyHead")] 13 12 public class PharmacyHeadController : Controller 14 13 { … … 20 19 21 20 //GET 22 //Mi trebaat rutite 23 [HttpGet] 21 /*[HttpGet] 24 22 [Route("api/pharmacyhead")] 25 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo( string Token)23 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo() 26 24 { 27 var PHeads = await _PHService.GetPharmacyHeadInfo( Token);25 var PHeads = await _PHService.GetPharmacyHeadInfo(); 28 26 return PHeads; 29 } 27 }*/ 30 28 [HttpGet] 31 29 [Route("api/pharmacyhead/{Id}")] 32 public async Task<PharmacyHead> GetPharmacyHeadById( int Id)30 public async Task<PharmacyHead> GetPharmacyHeadById([FromRoute]int Id) 33 31 { 34 32 var Phead = await _PHService.GetPharmacyHeadByIdAsync(Id); … … 38 36 [HttpPost] 39 37 [Route("api/pharmacyhead/add")] 40 public async Task<IActionResult> AddPharmacyHead( PharmacyHead pharmacyHead)38 public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead) 41 39 { 42 40 bool Success = await _PHService.Add(pharmacyHead); … … 44 42 } 45 43 46 [HttpPost]44 /*[HttpPost] 47 45 [Route("api/pharmacyhead/login")] 48 46 public async Task<int> Login([FromBody]PharmacyHead pharmacyHead) 49 47 { 50 48 return await _PHService.Login(pharmacyHead); 51 } 49 }*/ 52 50 [HttpPut] 53 51 [Route("api/pharmacyhead/{Id}")] … … 58 56 [HttpPost] 59 57 [Route("api/pharmacyhead/requests")] 60 public async Task<IActionResult> ClaimPharmacy( RequestPharmacyHead pharmacy)58 public async Task<IActionResult> ClaimPharmacy([FromBody]RequestPharmacyHead pharmacy) 61 59 { 62 60 bool Success = await _PHService.ClaimPharmacy(pharmacy); … … 65 63 [HttpDelete] 66 64 [Route("api/pharmacyhead/delete/{Id}")] 67 public async Task<IActionResult> Remove([From Query] int Id)65 public async Task<IActionResult> Remove([FromRoute] int Id) 68 66 { 69 67 bool Success = await _PHService.Remove(Id); … … 72 70 [HttpPost] 73 71 [Route("api/pharmacyhead/requests/{Id}")] 74 public async Task<IActionResult> RemoveClaimingRequest([From Query] int Id)72 public async Task<IActionResult> RemoveClaimingRequest([FromRoute] int Id) 75 73 { 76 74 bool Success = await _PHService.RemoveClaimingRequest(Id); -
Farmatiko/Farmatiko.csproj
r1f4846d rd23bf72 14 14 15 15 <ItemGroup> 16 <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" /> 16 17 <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.6" /> 17 18 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" /> -
Farmatiko/Startup.cs
r1f4846d rd23bf72 7 7 using FarmatikoData; 8 8 using Microsoft.EntityFrameworkCore; 9 using FarmatikoServices;10 9 using FarmatikoData.FarmatikoRepoInterfaces; 11 10 using FarmatikoData.FarmatikoRepo; … … 13 12 using FarmatikoServices.Services; 14 13 using Microsoft.Extensions.Logging; 14 using Microsoft.AspNetCore.Authentication.JwtBearer; 15 using Microsoft.IdentityModel.Tokens; 16 using System.Text; 17 using FarmatikoServices.Auth; 18 using FarmatikoServices.Infrastructure; 19 using System; 15 20 16 21 namespace Farmatiko … … 59 64 60 65 services.AddTransient<ILogger, Logger<ProcessJSONService>>(); 66 67 // services.AddTransient<ISystemService, SystemService>(); 68 69 70 var jwtTokenConfig = Configuration.GetSection("jwtTokenConfig").Get<JwtTokenConfig>(); 71 services.AddSingleton(jwtTokenConfig); 72 73 services.AddAuthentication(o => 74 { 75 o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 76 o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 77 o.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme; 78 }).AddJwtBearer(x => 79 { 80 x.RequireHttpsMetadata = true; 81 x.SaveToken = true; 82 x.TokenValidationParameters = new TokenValidationParameters 83 { 84 ValidateIssuer = true, 85 ValidIssuer = jwtTokenConfig.Issuer, 86 ValidateIssuerSigningKey = true, 87 IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtTokenConfig.Secret)), 88 ValidAudience = jwtTokenConfig.Audience, 89 ValidateAudience = true, 90 ValidateLifetime = true, 91 ClockSkew = TimeSpan.FromMinutes(1) 92 }; 93 }); 94 95 /*.AddJwtBearer(cfg => 96 { 97 cfg.RequireHttpsMetadata = false; 98 cfg.SaveToken = true; 99 cfg.IncludeErrorDetails = true; 100 cfg.TokenValidationParameters = new TokenValidationParameters() 101 { 102 ValidIssuer = Configuration.GetSection("TokenIssuer").Value, 103 ValidAudience = Configuration.GetSection("TokenIssuer").Value, 104 IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.GetSection("SecretKey").Value)) 105 }; 106 107 }); 108 */ 109 services.AddSingleton<IJwtAuthManager, JwtAuthManager>(); 110 services.AddHostedService<JwtRefreshTokenCache>(); 111 services.AddScoped<IAuthService, AuthService>(); 112 //If we add imgs 113 /*services.Configure<FormOptions>(o => { 114 o.ValueLengthLimit = int.MaxValue; 115 o.MultipartBodyLengthLimit = int.MaxValue; 116 o.MemoryBufferThreshold = int.MaxValue; 117 });*/ 118 61 119 } 62 120 … … 74 132 app.UseHsts(); 75 133 } 76 134 app.UseExceptionHandler("/Error"); 77 135 app.UseHttpsRedirection(); 78 136 app.UseStaticFiles(); 137 138 // if we add imgs 139 /*app.UseStaticFiles(new StaticFileOptions() 140 { 141 FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot")), 142 RequestPath = new PathString("/wwwroot") 143 });*/ 144 79 145 if (!env.IsDevelopment()) 80 146 { … … 84 150 app.UseRouting(); 85 151 152 app.UseAuthentication(); 153 app.UseAuthorization(); 154 86 155 app.UseCors(MyAllowSpecificOrigins); 87 156 … … 90 159 endpoints.MapControllerRoute( 91 160 name: "default", 92 pattern: " {controller}/{action=Index}/{id?}");161 pattern: "api/{controller}/{action=Index}/{id?}"); 93 162 }); 94 163 -
Farmatiko/appsettings.json
r1f4846d rd23bf72 12 12 "EPPlus": { 13 13 "ExcelPackage": { 14 "LicenseContext": "NonCommercial" 14 "LicenseContext": "NonCommercial" 15 15 } 16 16 }, 17 "AllowedHosts": "*" 17 "AllowedHosts": "*", 18 "jwtTokenConfig": { 19 "secret": "1234567890123456789", 20 "issuer": "FARMATIKO", 21 "audience": "FARMATIKO", 22 "accessTokenExpiration": 20, 23 "refreshTokenExpiration": 60 24 }, 25 "SecretKey": "PEJcK2bD4E2BKdNmAlUl", 26 "TokenIssuer": "FARMATIKOISSUER" 18 27 }
Note:
See TracChangeset
for help on using the changeset viewer.