...
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Service">
|
<Reference Include="Service">
|
||||||
<HintPath>..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll</HintPath>
|
<HintPath>..\..\Dlls\Service.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ using Shared.DTOs;
|
|||||||
namespace Back.Controllers
|
namespace Back.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
|
[Authorize]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class UserController : ControllerBase
|
public class UserController : ControllerBase
|
||||||
{
|
{
|
||||||
@@ -19,12 +20,17 @@ namespace Back.Controllers
|
|||||||
}
|
}
|
||||||
[HttpPost("authenticate")]
|
[HttpPost("authenticate")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<ActionResult<UserAuthenticationDTO>> Login(Authentication model)
|
public async Task<ActionResult<UserAuthenticationDTO>> Login([FromBody]Authentication model)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid) return BadRequest(model);
|
|
||||||
var result = await _servUser.UserAuthentication(model.Username, model.Password);
|
var result = await _servUser.UserAuthentication(model.Username, model.Password);
|
||||||
if (result != null) return Ok(result);
|
if (result != null) return Ok(result);
|
||||||
else return NotFound("کاربری با این مشخصات یافت نشد");
|
else return NotFound("کاربری با این مشخصات یافت نشد");
|
||||||
|
}
|
||||||
|
[HttpGet("test")]
|
||||||
|
|
||||||
|
public async Task<ActionResult> test()
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
|
using Back;
|
||||||
using Back.Data.Contracts;
|
using Back.Data.Contracts;
|
||||||
using Back.Data.Infrastructure.Repository;
|
using Back.Data.Infrastructure.Repository;
|
||||||
using Back.Services;
|
using Back.Services;
|
||||||
using Back.Validations;
|
using Back.Validations;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using System.Text;
|
||||||
using TaxPayer.Infrastructure.Persistence;
|
using TaxPayer.Infrastructure.Persistence;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -46,6 +49,24 @@ builder.Services.AddCors(options =>
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#region JWT
|
||||||
|
builder.Services.AddAuthentication("Bearer")
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new()
|
||||||
|
{
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = Fixedvalues.Issuer,
|
||||||
|
ValidAudience = Fixedvalues.Audience,
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(
|
||||||
|
Encoding.ASCII.GetBytes(Fixedvalues.SecretForKey))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
@@ -57,6 +78,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseCors(origins);
|
app.UseCors(origins);
|
||||||
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
@@ -13,18 +13,16 @@ namespace Back.Services
|
|||||||
public class servUser
|
public class servUser
|
||||||
{
|
{
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly CheckPermission _checkPermission;
|
|
||||||
private readonly servPermission _servPermission;
|
|
||||||
private readonly servNotification _servNotification;
|
private readonly servNotification _servNotification;
|
||||||
private readonly IAsyncRepository<User> _RepoUser;
|
private readonly IAsyncRepository<User> _RepoUser;
|
||||||
private readonly IAsyncRepository<PermissionPeriod> _RepoPermissionPeriod;
|
private readonly IAsyncRepository<PermissionPeriod> _RepoPermissionPeriod;
|
||||||
public servUser(IConfiguration configuration,
|
public servUser(IConfiguration configuration
|
||||||
CheckPermission checkPermission, servPermission servPermission
|
, servNotification servNotification
|
||||||
, servNotification servNotification, IAsyncRepository<User> RepoUser, IAsyncRepository<PermissionPeriod> RepoPermissionPeriod)
|
, IAsyncRepository<User> RepoUser
|
||||||
|
, IAsyncRepository<PermissionPeriod> RepoPermissionPeriod)
|
||||||
{
|
{
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_checkPermission = checkPermission;
|
|
||||||
_servPermission = servPermission;
|
|
||||||
_servNotification = servNotification;
|
_servNotification = servNotification;
|
||||||
_RepoUser = RepoUser;
|
_RepoUser = RepoUser;
|
||||||
_RepoPermissionPeriod = RepoPermissionPeriod;
|
_RepoPermissionPeriod = RepoPermissionPeriod;
|
||||||
@@ -32,16 +30,16 @@ namespace Back.Services
|
|||||||
public async Task<User?> GetUserByUserNameAndPassword(string UserName, string Password)
|
public async Task<User?> GetUserByUserNameAndPassword(string UserName, string Password)
|
||||||
{
|
{
|
||||||
return await _RepoUser.Get(w => w.Username == UserName && w.Password == Password.encrypted() && w.IsActive)
|
return await _RepoUser.Get(w => w.Username == UserName && w.Password == Password.encrypted() && w.IsActive)
|
||||||
.Include(i => i.RolUsers)
|
// .Include(i => i.RolUsers)
|
||||||
.ThenInclude(ti => ti.rolePermissions)
|
// .ThenInclude(ti => ti.rolePermissions)
|
||||||
.Include(i => i.RolUsers)
|
// .Include(i => i.RolUsers)
|
||||||
.ThenInclude(ti=>ti.Company)
|
// .ThenInclude(ti=>ti.Company)
|
||||||
.ThenInclude(ti => ti.PermissionPeriods)
|
//.ThenInclude(ti => ti.PermissionPeriods)
|
||||||
.ThenInclude(ti => ti.Permission)
|
// .ThenInclude(ti => ti.Permission)
|
||||||
.Include(ti=>ti.RolUsers)
|
.Include(ti=>ti.RolUsers)
|
||||||
.ThenInclude(ti => ti.Company)
|
.ThenInclude(ti => ti.Company)
|
||||||
.ThenInclude(ti => ti.PermissionPeriods)
|
//.ThenInclude(ti => ti.PermissionPeriods)
|
||||||
.ThenInclude(ti => ti.CalculationType)
|
// .ThenInclude(ti => ti.CalculationType)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
public async Task<UserAuthenticationDTO?> UserAuthentication(string UserNameORUserID, string Password="")
|
public async Task<UserAuthenticationDTO?> UserAuthentication(string UserNameORUserID, string Password="")
|
||||||
@@ -158,7 +156,7 @@ namespace Back.Services
|
|||||||
{
|
{
|
||||||
return await _RepoUser.Get(w => w.ID == UserID).FirstOrDefaultAsync();
|
return await _RepoUser.Get(w => w.ID == UserID).FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
public async void SetTokenAndDateLogininDB(int UserID,string Token)
|
public async Task SetTokenAndDateLogininDB(int UserID,string Token)
|
||||||
{
|
{
|
||||||
var user = await GetUserByUserID(UserID);
|
var user = await GetUserByUserID(UserID);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
@@ -274,7 +272,7 @@ namespace Back.Services
|
|||||||
|
|
||||||
string Token = new JwtSecurityTokenHandler()
|
string Token = new JwtSecurityTokenHandler()
|
||||||
.WriteToken(jwtSecurityToke);
|
.WriteToken(jwtSecurityToke);
|
||||||
SetTokenAndDateLogininDB(UserId, Token);
|
await SetTokenAndDateLogininDB(UserId, Token);
|
||||||
//_contextMongodb.InsertItem(new SysLog()
|
//_contextMongodb.InsertItem(new SysLog()
|
||||||
//{
|
//{
|
||||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
@using Shared.DTOs
|
@using Shared.DTOs
|
||||||
@inject HttpClient _hc
|
@inject HttpClient _hc
|
||||||
@inject NavigationManager nav
|
@inject NavigationManager nav
|
||||||
|
@inject UserAuthenticationDTO userinfo
|
||||||
<PageTitle>ثبت نام</PageTitle>
|
<PageTitle>ثبت نام</PageTitle>
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
@@ -88,6 +89,9 @@
|
|||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
|
if (userinfo!=null)
|
||||||
|
nav.NavigateTo("/");
|
||||||
|
|
||||||
editContext = new EditContext(model);
|
editContext = new EditContext(model);
|
||||||
messageStore = new(editContext);
|
messageStore = new(editContext);
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
@page "/Sign-in"
|
@page "/Sign-in"
|
||||||
@using Shared.DTOs
|
@using Shared.DTOs
|
||||||
|
|
||||||
|
@inject HttpClient _hc
|
||||||
|
@inject NavigationManager nav
|
||||||
|
@inject UserAuthenticationDTO userinfo
|
||||||
<PageTitle>ورود</PageTitle>
|
<PageTitle>ورود</PageTitle>
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
@@ -107,6 +110,15 @@
|
|||||||
<button class="signin-btn ">ورود</button>
|
<button class="signin-btn ">ورود</button>
|
||||||
</div>
|
</div>
|
||||||
</EditForm>
|
</EditForm>
|
||||||
|
<div class="row">
|
||||||
|
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
|
||||||
|
<Icon Name="@alertIconName" class="me-2"></Icon>
|
||||||
|
@alertMessage
|
||||||
|
<Button Color="ButtonColor.Primary" @onclick="EndForm">اتمام عملیات</Button>
|
||||||
|
</Alert>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
<div class="signin-banner-from-register">
|
<div class="signin-banner-from-register">
|
||||||
<NavLink href="Register">اکانت ندارید؟ <span>ثبت نام</span></NavLink>
|
<NavLink href="Register">اکانت ندارید؟ <span>ثبت نام</span></NavLink>
|
||||||
</div>
|
</div>
|
||||||
@@ -120,25 +132,46 @@
|
|||||||
|
|
||||||
@code {
|
@code {
|
||||||
[SupplyParameterFromForm]
|
[SupplyParameterFromForm]
|
||||||
public Authentication? Model { get; set; }
|
public Authentication? Model { get; set; }
|
||||||
protected override void OnInitialized() => Model ??= new();
|
protected override void OnInitialized() => Model ??= new();
|
||||||
|
// alert
|
||||||
|
AlertColor alertColor = AlertColor.Primary;
|
||||||
|
IconName alertIconName = IconName.CheckCircleFill;
|
||||||
|
bool Hidealert = true;
|
||||||
|
string alertMessage = "";
|
||||||
|
// protected override async Task OnInitializedAsync()
|
||||||
|
// {
|
||||||
|
// var t1 = userinfo;
|
||||||
|
// var t2 = _hc;
|
||||||
|
// await base.OnInitializedAsync();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
@functions {
|
@functions {
|
||||||
|
private void ShowDangerAlert(string msg)
|
||||||
|
{
|
||||||
|
Hidealert = false;
|
||||||
|
alertColor = AlertColor.Danger;
|
||||||
|
alertIconName = IconName.ExclamationTriangleFill;
|
||||||
|
alertMessage = msg;
|
||||||
|
}
|
||||||
|
private async Task EndForm() =>nav.NavigateTo("/");
|
||||||
|
|
||||||
|
|
||||||
private async Task OnLoginClick()
|
private async Task OnLoginClick()
|
||||||
{
|
{
|
||||||
var request = await _hc.PostAsJsonAsync("User/authenticate", Model);
|
var request = await _hc.PostAsJsonAsync("User/authenticate", Model);
|
||||||
// if (request.IsSuccessStatusCode)
|
if (request.IsSuccessStatusCode)
|
||||||
// {
|
{
|
||||||
// messageStore?.Clear();
|
userinfo = await request.Content.ReadFromJsonAsync<UserAuthenticationDTO>();
|
||||||
// var VerificationID = await request.Content.ReadFromJsonAsync<int>();
|
|
||||||
// nav.NavigateTo($"Verification/{VerificationID}");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// var error = await request.Content.ReadFromJsonAsync<List<string>>();
|
|
||||||
// messageStore?.Add(() => model.Mobile, error);
|
|
||||||
|
|
||||||
// }
|
_hc.DefaultRequestHeaders.Add("Authorization",
|
||||||
|
$"Bearer {userinfo?.Token}");
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (request.StatusCode==System.Net.HttpStatusCode.NotFound)
|
||||||
|
ShowDangerAlert("کاربری با این مشخصات یافت نشد");
|
||||||
|
|
||||||
|
else ShowDangerAlert("خطای سیستمی");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -2,16 +2,18 @@ using Microsoft.AspNetCore.Components.Web;
|
|||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
using Front;
|
using Front;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using Shared.DTOs;
|
||||||
|
|
||||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||||
builder.RootComponents.Add<App>("#app");
|
builder.RootComponents.Add<App>("#app");
|
||||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||||
builder.Services.AddBlazorBootstrap();
|
builder.Services.AddBlazorBootstrap();
|
||||||
|
builder.Services.AddScoped<UserAuthenticationDTO>();
|
||||||
|
|
||||||
|
|
||||||
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") });
|
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") });
|
||||||
|
|
||||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") });
|
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") });
|
||||||
|
|
||||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fa-Ir");
|
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fa-Ir");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user