This commit is contained in:
mmrbnjd
2024-04-29 07:58:41 +03:30
parent fd13de3e1d
commit 7b8127dc72
23 changed files with 526 additions and 39 deletions

View File

@@ -26,7 +26,6 @@
<ItemGroup>
<Folder Include="Common\DTOs\" />
<Folder Include="Features\" />
</ItemGroup>
<ItemGroup>

View File

@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace Back.Controllers
{
@@ -59,7 +60,7 @@ namespace Back.Controllers
[HttpPost("CreateCsrAndPrivateKey")]
public async Task<ActionResult<TaxToolsDTO>> CreateCsrAndPrivateKey(CsrPrivateKeyDto model)
{
var resultValidationmodel = await _mobilevalidation.ValidateAsync(model.Mobile);
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(model.Mobile,false));
if (!resultValidationmodel.IsValid)
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
return Ok(await _sBase.CreateCsrAndPrivateKey(model));
@@ -167,6 +168,23 @@ namespace Back.Controllers
}
}
[HttpPost("ForgetPassWord")]
[AllowAnonymous]
public async Task<ActionResult<string>> ForgetPassWord(ForgetPasswordItem Item)
{
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(Item.Username, true));
if (!resultValidationmodel.IsValid)
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
var ID = await _servValidatinMsg.GenerateCode(new VerificationCode
{
prm = Item.Username,
val = Item.PassWord,
Type = "ForgetPassword"
});
_servSendMsg.Authentication(Item.Username, ID.ToString());
return Ok(ID);
}
}
}

View File

@@ -0,0 +1,29 @@
using Back.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
namespace Back.Controllers
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class CompanyController : ControllerBase
{
private readonly servCompany _servCompany;
public CompanyController(servCompany servCompany)
{
_servCompany = servCompany;
}
[HttpPost("ChangeLogo")]
public async Task<ActionResult<bool>> ChangeLogo(byte[] logo)
{
//var result = await _sBase.ReadPublicKeyFromCER(modelfromBase64);
//if (result.type == "error")
// return BadRequest();
return Ok();
}
}
}

View File

@@ -2,6 +2,7 @@
using Back.Data.Models;
using Back.Services;
using Back.Validations;
using FluentValidation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -33,7 +34,7 @@ namespace Back.Controllers
[AllowAnonymous]
public async Task<ActionResult<int>> NewTicketNoAuthentication(CTicketNoAuthenticationDto item)
{
var resultValidationmodel = await _mobilevalidation.ValidateAsync(item.Mobile);
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(item.Mobile,false));
if (!resultValidationmodel.IsValid)
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());

View File

@@ -37,6 +37,19 @@ namespace Back.Controllers
return Ok(result);
}
[HttpPost("ChangePassword")]
public async Task<ActionResult<bool>> ChangePassword(ChangePasswordDto item)
{
if (item.newPass.Trim() != item.renewPass.Trim())
return BadRequest(new List<string> { "تکرار کلمه عبور با کلمه عبور مطابقت ندارد" });
if (item.newPass.Trim().Length <= 3)
return BadRequest(new List<string> { "کلمه عبور جدید باید بیشتر از 3کاراکتر باشد" });
var UserID = HttpContext.User.Claims.First(c => c.Type == "UserID").Value;
if (!await _servUser.PermissionChangePassword(item.oldPass.Trim(), Convert.ToInt32(UserID)))
return BadRequest(new List<string> { "کلمه عبور قبلی صحیح نمی باشد" });
return Ok(await _servUser.ChangePassword(item.newPass.Trim(), Convert.ToInt32(UserID)));
}

View File

@@ -17,13 +17,15 @@ namespace Back.Controllers
private readonly GetVerificationValidation _getVerificationValidation;
private readonly servSendMsg _servSendMsg;
private readonly servCompany _servCompany;
private readonly servUser _servUser;
public VerificationController(ServValidatinMsg servValidatinMsg, GetVerificationValidation getVerificationValidation
, servCompany servCompany, servSendMsg servSendMsg)
, servCompany servCompany, servSendMsg servSendMsg, servUser servUser)
{
_servValidatinMsg = servValidatinMsg;
_getVerificationValidation = getVerificationValidation;
_servCompany = servCompany;
_servSendMsg = servSendMsg;
_servUser = servUser;
}
[HttpGet("GetVerification/{ID}")]
[AllowAnonymous]
@@ -61,6 +63,12 @@ namespace Back.Controllers
_servSendMsg.Authentication(company.Mobile, ID.ToString());
break;
case "ForgetPassword":
var user = await _servUser.ChangePasswordByMobile(_getVerificationValidation.verificationCode.prm, _getVerificationValidation.verificationCode.val);
_servSendMsg.Authentication(_getVerificationValidation.verificationCode.prm, ID.ToString());
break;
default:
return BadRequest("این نوع احراز تعریف نشده");
}

View File

@@ -0,0 +1,50 @@
using Back.Services;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Threading.Tasks;
namespace Back.Features
{
// You may need to install the Microsoft.AspNetCore.Http.Abstractions package into your project
public class CheckOnlineUser
{
private readonly RequestDelegate _next;
public CheckOnlineUser(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
int UserID = Convert.ToInt32(httpContext.User.Claims.Where(w => w.Type == "UserID").Select(s => s.Value).FirstOrDefault());
var accessToken = httpContext.GetTokenAsync("access_token").Result;
if (UserID==null || UserID==0 || string.IsNullOrEmpty(accessToken))
await _next(httpContext);
else
{
servUser _servUser = (servUser)httpContext.RequestServices.GetService(typeof(servUser));
var user = _servUser.GetUserByUserID(UserID).Result;
if (user.Token==accessToken)
await _next(httpContext);
else
{
httpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
}
}
}
}
// Extension method used to add the middleware to the HTTP request pipeline.
public static class CheckOnlineUserExtensions
{
public static IApplicationBuilder UseCheckOnlineUser(this IApplicationBuilder builder)
{
return builder.UseMiddleware<CheckOnlineUser>();
}
}
}

View File

@@ -1,6 +1,7 @@
using Back;
using Back.Data.Contracts;
using Back.Data.Infrastructure.Repository;
using Back.Features;
using Back.Services;
using Back.Validations;
using Microsoft.EntityFrameworkCore;
@@ -80,7 +81,7 @@ app.UseHttpsRedirection();
app.UseCors(origins);
app.UseAuthentication();
app.UseAuthorization();
app.UseCheckOnlineUser();
app.MapControllers();
app.Run();

View File

@@ -103,9 +103,9 @@ namespace Back.Services
public async Task<bool> ExistMobileAndCompanyIsActive(string mobile)
{
return await _repoCompany.GetAll().AnyAsync(w => w.Mobile == mobile && w.IsActive);
}
}
}

View File

@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Shared.DTOs;
using System.IdentityModel.Tokens.Jwt;
using System.Reflection;
using System.Security.Claims;
using System.Text;
@@ -56,7 +57,7 @@ namespace Back.Services
return null;
string Jwt_Lifetime_Minutes = await GetJwt_Lifetime_Minutes();
ret.UserName = user.Username;
ret.Token =newtoken ? await CerateToken(user.ID, user.Username, Jwt_Lifetime_Minutes) : user.Token;
ret.FullName = user.Fullname;
ret.Photo = user.Photo==null ? null : Convert.ToBase64String(user.Photo);
@@ -175,7 +176,14 @@ namespace Back.Services
await _RepoUser.UpdateAsync(user);
}
}
public async Task<bool> ChangePasswordByMobile(string mobile, string newpassword)
{
var user =await GetUserByUsername(mobile);
if (user == null)
return false;
user.Password = newpassword.encrypted();
return await _RepoUser.UpdateAsync(user);
}
public async Task<DashBoardDTO> GetDashBoard(int CompanyID,int UserID)
{
DashBoardDTO request=new DashBoardDTO();
@@ -237,6 +245,19 @@ namespace Back.Services
//});
return await _RepoUser.UpdateByObjAsync(user);
}
public async Task<bool> ChangePassword(string newPass, int UserID)
{
var user = await GetUserByUserID(UserID);
if (user == null)
return false;
user.Password = newPass.encrypted();
return await _RepoUser.UpdateAsync(user);
}
public async Task<bool> PermissionChangePassword(string oldPass,int UserID)
{
return await _RepoUser.GetAll().AnyAsync(w => w.ID == UserID && w.Password==oldPass.encrypted() && w.IsActive);
}
//--------internal
private async Task<string> GetJwt_Lifetime_Minutes()
{

View File

@@ -1,19 +1,33 @@
using FluentValidation;
using Back.Services;
using FluentValidation;
using Shared.DTOs;
using System;
namespace Back.Validations
{
public class MobileValidation : AbstractValidator<string>
public class MobileValidation : AbstractValidator<Tuple<string,bool>>
{
public MobileValidation()
public MobileValidation(servCompany servCompany)
{
CascadeMode = CascadeMode.Stop;
RuleFor(m => m)
RuleFor(m => m.Item1)
.NotEmpty().WithMessage("موبایل نمی تواند باشد")
.NotNull().WithMessage("موبایل نمی تواند باشد")
.Length(11).WithMessage("فرمت موبایل صحیح نمی باشد")
.Must(m => m.StartsWith("09")).WithMessage("فرمت موبایل صحیح نمی باشد");
RuleFor(m => m)
.Custom((model, context) => {
if (model.Item2)
{
if (!servCompany.ExistMobileAndCompanyIsActive(model.Item1).Result)
{
context.AddFailure("این موبایل یافت نشد");
}
}
});
}
}
}

View File

@@ -10,6 +10,6 @@
},
"Fixedvalues": {
"Jwt_Lifetime_Minutes": "60"
"Jwt_Lifetime_Minutes": "144000"
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs
{
public class ChangePasswordDto
{
public string oldPass { get; set; }
public string newPass { get; set; }
public string renewPass { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs
{
public class ForgetPasswordItem
{
public string Username { get; set; }
public string PassWord { get; set; }
}
}

View File

@@ -4,7 +4,7 @@ namespace Shared.DTOs
{
public class UserAuthenticationDTO
{
public string UserName { get; set; }
public string FullName { get; set; }
public string Token { get; set; }
public DateTime enterDate { get; set; }

View File

@@ -1,4 +1,10 @@
@inherits LayoutComponentBase
@using Front.Services
@using Shared.DTOs
@inject ILocalStorageService Storage;
@inject UserAuthenticationDTO userinfo
@inject HttpClient _hc
@inject NavigationManager nav
<HeadContent>
<link rel="canonical" href="#">
<!-- Favicon -->
@@ -116,33 +122,42 @@
<ul class="navbar-nav flex-row align-items-center mr-auto f-ir">
<!-- Place this tag where you want the button to render. -->
<li class="nav-item lh-1 me-3 f-ir">
<span class="fw-semibold d-block">جان دو</span>
<span class="fw-semibold d-block">@userinfo.Company.Name</span>
</li>
<!-- User -->
<li class="nav-item navbar-dropdown dropdown-user dropdown">
<a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);" data-bs-toggle="dropdown">
<div class="avatar avatar-online">
<img src="assets/img/avatars/1.png" alt class="w-px-40 h-auto rounded-circle">
@{
string _src = "assets/img/avatars/1.png";
if (userinfo.Company.Logo != null)
_src = "data:image/jpeg;base64," + @userinfo.Company.Logo;
}
<img src=@_src alt class="w-px-40 h-auto rounded-circle">
</div>
</a>
<ul class="dropdown-menu dropdown-menu-end new-style-13">
<li>
<a class="dropdown-item" href="#">
<NavLink class="dropdown-item" href="Profile">
<i class="bx bx-user me-2"></i>
<span class="align-middle">پروفایل من</span>
</a>
</NavLink>
</li>
<li>
<div class="dropdown-divider"></div>
</li>
<li>
<a class="dropdown-item" href="auth-login-basic.html">
<li> <a class="dropdown-item">
<i class="bx bx-power-off me-2"></i>
<span class="align-middle">خروج</span>
</a>
<NavLink style="cursor:pointer" onclick="@Logout">
<span style="color:red;">خروج</span>
</NavLink>
</a>
</li>
</ul>
</li>
@@ -165,14 +180,11 @@
<div class="mb-2 mb-md-0">
<span>کپی رایت با <a href="#">مهدی</a> 2023</span>
</div>
@* <div>
<a href="#" class="footer-link me-4">مجوز</a>
<a href="#" class="footer-link me-4">تم های بیشتر</a>
<a href="#" class="footer-link me-4">مستندات</a>
<a href="#" class="footer-link me-4">پشتیبانی</a>
</div> *@
<div>
<NavLink style="cursor:pointer" onclick="@Logout">
<span style="color:red;">خروج</span>
</NavLink>
</div>
</div>
</footer>
<!-- / Footer -->
@@ -187,3 +199,12 @@
</div>
@functions {
private async Task Logout()
{
_hc.DefaultRequestHeaders.Clear();
await Storage.RemoveItem("token");
userinfo.Token = "";
nav.NavigateTo("/");
}
}

View File

@@ -34,27 +34,34 @@
<!-- Misc -->
<li class="menu-header small text-uppercase"><span class="menu-header-text">متفرقه</span></li>
<li class="menu-item @cssActionItem[4]" @onclick="() => onClickcssActionItem(4)">
<NavLink class="dropdown-item" href="Profile">
<i class="bx bx-user me-2"></i>
<span class="align-middle">پروفایل</span>
</NavLink>
</li>
<li class="menu-item @cssActionItem[5]" @onclick="() => onClickcssActionItem(5)">
<NavLink href="#" target="_blank" class="menu-link">
<i class="menu-icon tf-icons bx bx-support"></i>
<div>پشتیبانی</div>
</NavLink>
</li>
<li class="menu-item @cssActionItem[5]" @onclick="() => onClickcssActionItem(5)">
<li class="menu-item @cssActionItem[6]" @onclick="() => onClickcssActionItem(6)">
<NavLink href="#" target="_blank" class="menu-link">
<i class="menu-icon tf-icons bx bx-copy"></i>
<div >سفارشات</div>
</NavLink>
</li>
<li class="menu-item @cssActionItem[6]" @onclick="() => onClickcssActionItem(6)">
<li class="menu-item @cssActionItem[7]" @onclick="() => onClickcssActionItem(7)">
<NavLink href="#" target="_blank" class="menu-link">
<i class="menu-icon tf-icons bx bx-file"></i>
<div>تنظیمات</div>
</NavLink>
</li>
</ul>
@code{
string[] cssActionItem = { "active", "", "", "", "", "", "" };
string[] cssActionItem = { "active", "", "", "", "", "", "", "" };
}
@functions{

View File

@@ -58,7 +58,7 @@
<div class="postbox__comment-input mb-30">
<InputText @bind-Value="Model.Username" id="Username" type="text" class="inputText" required="" />
<span class="floating-label">نام کاربری</span>
<span class="floating-label">نام کاربری(موبایل)</span>
</div>
</div>
<div class="col-12">
@@ -104,7 +104,7 @@
</div>
<div class="col-6">
<div class="postbox__forget text-end">
<a href="#">رمز عبور را فراموش کرده اید؟</a>
<a onclick="@ForgetPass">رمز عبور را فراموش کرده اید؟</a>
</div>
</div>
</div>
@@ -150,10 +150,23 @@
string alertMessage = "";
protected override async Task OnParametersSetAsync()
{
if (from == "Verification")
if (from == "VerificationRegister")
{
ShowSuccessAlert("ثبت نام شما با موفقیت انجام شد");
}
else if (from == "VerificationFrogetPass")
{
ShowSuccessAlert("تغییر کلمه عبور با موفقیت انجام شد");
}
else if (from == "unon")
{
ShowSuccessAlert("برای استفاده از برنامه لطفا مجدد وارد شود");
}
else if (from == "changePass")
{
ShowSuccessAlert("کلمه عبور با موفقیت تغییر کرد");
}
await base.OnParametersSetAsync();
}
protected override async Task OnInitializedAsync()
@@ -184,7 +197,36 @@
alertMessage = msg;
}
private async Task EndForm() => nav.NavigateTo("/");
private async Task ForgetPass()
{
if (string.IsNullOrEmpty(Model.Username))
{
ShowDangerAlert("لطفا نام کابری(موبایل) خود را وارد نمایید");
}
else if (string.IsNullOrEmpty(Model.Password))
{
ShowDangerAlert("لطفا کلمه عبور جدید را وارد نمایید");
}
else
{
var request = await _hc.PostAsJsonAsync("Base/ForgetPassWord", new ForgetPasswordItem
{
Username = Model.Username,
PassWord = Model.Password
});
if (request.IsSuccessStatusCode)
{
var VerificationID = await request.Content.ReadFromJsonAsync<int>();
nav.NavigateTo($"Verification/{VerificationID}");
}
else
{
var error = await request.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(error[0]);
}
}
}
private async Task OnLoginClick()
{
@@ -207,7 +249,7 @@
userinfo.Photo = userinfomodel.Photo;
userinfo.exitDate = userinfomodel.exitDate;
userinfo.enterDate = userinfomodel.enterDate;
userinfo.UserName = userinfomodel.UserName;
nav.NavigateTo("/Panel");
}

View File

@@ -0,0 +1,200 @@
@page "/Profile"
@using Front.Services
@using Shared.DTOs
@layout PanelLayout
@inject UserAuthenticationDTO userinfo
@inject HttpClientController _hc
@inject ILocalStorageService Storage;
<div class="container-xxl flex-grow-1 container-p-y">
<h4 class="fw-bold py-3 mb-4">
<span class="text-muted fw-light">متفرقه /</span> پروفایل
</h4>
<div class="row">
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
<Icon Name="@alertIconName" class="me-2"></Icon>
@alertMessage
</Alert>
</div>
<div class="row">
<div class="col-md-12">
<div class="card mb-4">
<h5 class="card-header">تغییر عکس</h5>
<div class="card-body">
<div class="d-flex align-items-start align-items-sm-center gap-4">
@{
_src = "assets/img/avatars/1.png";
if (userinfo.Company.Logo != null)
_src = "data:image/jpeg;base64," + @userinfo.Company.Logo;
}
<img src="@_src" alt="user-avatar" class="d-block rounded" height="100" width="100" id="uploadedAvatar">
<div class="button-wrapper">
<label for="upload" class="btn btn-primary me-2 mb-4" tabindex="0">
<span class="d-none d-sm-block">آپلود تصویر جدید</span>
<i class="bx bx-upload d-block d-sm-none"></i>
<InputFile OnChange="changePic" type="file" id="upload" class="account-file-input" hidden="" accept="image/png, image/jpeg"/>
</label>
<p class="text-muted mb-0">JPG، GIF یا PNG مجاز است. حداکثر اندازه @maxFileSize هزار</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="card mb-4">
<h5 class="card-header">تغییر کلمه عبور</h5>
<div class="card-body">
<EditForm Model="changepassModel" OnSubmit="changepassSubmit" FormName="changepass">
<div class="mb-3 row">
<label for="defaultFormControlInput" class="form-label">کلمه عبور فعلی</label>
<div class="col-md-10">
<InputText @bind-Value="@changepassModel.oldPass" style="text-align:center;" class="form-control" type="password" id="html5-password-input"/>
</div>
</div>
<div class="mb-3 row">
<label for="defaultFormControlInput" class="form-label">کلمه عبور جدید</label>
<div class="col-md-10">
<InputText style="text-align:center;" @bind-Value="@changepassModel.newPass" class="form-control" type="password" id="html5-password-input" />
</div>
</div>
<div class="mb-3 row">
<label for="defaultFormControlInput" class="form-label">تکرار کلمه عبور جدید</label>
<div class="col-md-10">
<InputText @bind-Value="@changepassModel.renewPass" style="text-align:center;" class="form-control" type="password" id="html5-password-input" />
</div>
</div>
<button type="submit" class="btn btn-primary">ارسال</button>
</EditForm>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card mb-4">
<h5 class="card-header">تغییر نام کاربری/ موبایل</h5>
<div class="card-body">
<form>
<div class="mb-3 row">
<label for="defaultFormControlInput" class="form-label">موبایل جدید</label>
<div class="input-group input-group-merge">
<input type="text" style="text-align:left;" id="basic-icon-default-phone" class="form-control phone-mask" placeholder="0000 000 0911" aria-label="0000 000 0911" value="@userinfo.UserName" aria-describedby="basic-icon-default-phone2">
<span id="basic-icon-default-phone2" class="input-group-text"><i class="bx bx-phone"></i></span>
</div>
</div>
<button type="submit" class="btn btn-primary">ارسال</button>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="card mb-4">
<h5 class="card-header">تغییر نام</h5>
<div class="card-body">
<form>
<div class="mb-3 row">
<label for="defaultFormControlInput" class="form-label">نام جدید</label>
<div class="input-group input-group-merge">
<span id="basic-icon-default-company2" class="input-group-text"><i class="bx bx-buildings"></i></span>
<input style="text-align:right;" type="text" id="basic-icon-default-company" value="@userinfo.Company.Name" class="form-control" placeholder="@userinfo.Company.Name" aria-label="@userinfo.Company.Name" aria-describedby="basic-icon-default-company2">
</div>
</div>
<button type="submit" class="btn btn-primary">ارسال</button>
</form>
</div>
</div>
</div>
</div>
</div>
@code {
public string _src { get; set; }
private long maxFileSize = 1024 * 15;
[SupplyParameterFromForm]
public ChangePasswordDto changepassModel { get; set; }
// alert
AlertColor alertColor = AlertColor.Primary;
IconName alertIconName = IconName.CheckCircleFill;
bool Hidealert = true;
string alertMessage = "";
protected override void OnInitialized() => changepassModel ??= new();
}
@functions{
private void ShowDangerAlert(string msg)
{
Hidealert = false;
alertColor = AlertColor.Danger;
alertIconName = IconName.ExclamationTriangleFill;
alertMessage = msg;
}
private void ShowSuccessAlert(string msg)
{
Hidealert = false;
alertColor = AlertColor.Success;
alertIconName = IconName.CheckCircleFill;
alertMessage = msg;
}
private async Task changepassSubmit(){
var request = await _hc.Post<ChangePasswordDto>("User/ChangePassword", changepassModel);
if (request.IsSuccessStatusCode)
{
if (await request.Content.ReadFromJsonAsync<bool>())
{
_hc._hc.DefaultRequestHeaders.Clear();
await Storage.RemoveItem("token");
userinfo.Token = "";
_hc._nav.NavigateTo("/Sign-in/changePass");
}
else ShowDangerAlert("خطای سیستمی");
}else
{
var errors = await request.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(errors[0]);
}
}
private async Task changePic(InputFileChangeEventArgs e){
if (e.GetMultipleFiles()[0].Size <= maxFileSize)
{
string Base64Str = "";
byte[] Array;
using (MemoryStream stream = new MemoryStream())
{
await e.GetMultipleFiles()[0].OpenReadStream(maxFileSize).CopyToAsync(stream);
Array = stream.ToArray();
Base64Str = Convert.ToBase64String(Array);
}
if (!string.IsNullOrEmpty(Base64Str))
{
var request = await _hc.Post<byte[]>("Company/ChangeLogo", Array);
if (request.IsSuccessStatusCode)
{
userinfo.Company.Logo = _src = Base64Str;
ShowSuccessAlert("تصویر با موفقیت تغییر کرد");
}
else
{
ShowDangerAlert ( "خطایی در اجرای عملیات رخ داده");
}
}
}
else
{
ShowDangerAlert ( "حجم فایل بیشتر از حد مجاز می باشد");
}
}
}

View File

@@ -143,7 +143,9 @@
if (status)
{
if (VerificationCodeModel.Type == "CompanyRegistration")
nav.NavigateTo("/Sign-in/Verification");
nav.NavigateTo("/Sign-in/VerificationRegister");
else if (VerificationCodeModel.Type == "ForgetPassword")
nav.NavigateTo("/Sign-in/VerificationFrogetPass");
else
nav.NavigateTo("/");

View File

@@ -13,6 +13,7 @@ builder.Services.AddBlazorBootstrap();
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
builder.Services.AddScoped<localService>();
builder.Services.AddScoped<HttpClientController>();
builder.Services.AddScoped(sp => new UserAuthenticationDTO());

View File

@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Components;
using System.Net.Http.Json;
namespace Front.Services
{
public class HttpClientController
{
public readonly HttpClient _hc;
public readonly NavigationManager _nav;
public HttpClientController(HttpClient hc, NavigationManager nav)
{
_hc = hc;
_nav = nav;
}
public async Task<HttpResponseMessage> Get(string route)
{
var request = await _hc.GetAsync(route);
if (request.StatusCode==System.Net.HttpStatusCode.Unauthorized)
_nav.NavigateTo("/Sign-in/unon");
return request;
}
public async Task<HttpResponseMessage> Post<T>(string route,T mode)
{
var request = await _hc.PostAsJsonAsync(route,mode);
if (request.StatusCode == System.Net.HttpStatusCode.Unauthorized)
_nav.NavigateTo("/Sign-in/unon");
return request;
}
}
}

View File

@@ -31,6 +31,7 @@ namespace Front.Services
_user.Photo = userinfomodel.Photo;
_user.exitDate = userinfomodel.exitDate;
_user.enterDate = userinfomodel.enterDate;
_user.UserName= userinfomodel.UserName;
}
}