This commit is contained in:
mmrbnjd
2025-07-26 11:47:32 +03:30
parent 29107ce9c6
commit c045ace959
10 changed files with 88 additions and 64 deletions

View File

@@ -74,7 +74,7 @@ namespace Hushian.Application.Services
} }
else else
{ {
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(f => f.UserName == auth.Username var exper = await _ExperRepository.Get().Include(inc=>inc.Company).FirstOrDefaultAsync(f => f.UserName == auth.Username
&& f.Password == auth.Password.GetHash() && f.Available); && f.Password == auth.Password.GetHash() && f.Available);
if (exper == null) if (exper == null)
{ {
@@ -85,7 +85,7 @@ namespace Hushian.Application.Services
Response.Success = true; Response.Success = true;
Response.Value = new AuthResponse() Response.Value = new AuthResponse()
{ {
Fullname = exper.FullName, Fullname = exper.FullName+" ("+ exper.Company.FullName+")",
Id = exper.ID, Id = exper.ID,
CompanyId = exper.CompanyID, CompanyId = exper.CompanyID,
MobileOrUserName = exper.UserName, MobileOrUserName = exper.UserName,

View File

@@ -70,6 +70,8 @@ namespace Hushian.Application.Services
company.Email = model.Email; company.Email = model.Email;
company.WebSite = model.WebSite; company.WebSite = model.WebSite;
company.logo = model.logo; company.logo = model.logo;
company.allowBot = model.allowBot;
company.Available = model.Available;
if (await _CompanyRepository.UPDATEBool(company)) if (await _CompanyRepository.UPDATEBool(company))
{ {

View File

@@ -1,4 +1,5 @@
using Common.Dtos.Company; using Common.Dtos;
using Common.Dtos.Company;
using Hushian.Application.Constants; using Hushian.Application.Constants;
using Hushian.Application.Services; using Hushian.Application.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@@ -39,7 +40,15 @@ namespace Hushian.WebApi.Controllers.v1
return response.Success && response.Value ? NoContent() return response.Success && response.Value ? NoContent()
: BadRequest(response.Errors); : BadRequest(response.Errors);
} }
[HttpPut("ChangePasswordCompany")]
[Authorize(Roles = "Company")]
public async Task<ActionResult> ChangePasswordCompany([FromBody] ChangePasswordDto item)
{
var response = await _companyService.ChangePasswordCompany(item, Convert.ToInt32(User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First()));
return response.Success && response.Value ? NoContent()
: BadRequest(response.Errors);
}
} }
} }

View File

@@ -6,6 +6,8 @@
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject AuthService authService; @inject AuthService authService;
@inject ILocalStorageService localStorageService; @inject ILocalStorageService localStorageService;
@inject CompanyService companyService
<form style="background-color: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column;"> <form style="background-color: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column;">
<label style="margin-bottom: 8px; font-size: 14px; color: #333;" for="oldpass">رمز عبور قبلی:</label> <label style="margin-bottom: 8px; font-size: 14px; color: #333;" for="oldpass">رمز عبور قبلی:</label>
@@ -52,7 +54,7 @@
return; return;
} }
List<string> errors = new(); List<string> errors = new();
if (!dto.NewPassWord.CheckLawPassword(ref errors)) if (!dto.NewPassWord.CheckLawPassword(ref errors))
{ {
ToastService.Notify(new(ToastType.Danger, errors.First())); ToastService.Notify(new(ToastType.Danger, errors.First()));
@@ -60,7 +62,15 @@
} }
SpinnerVisible = true; SpinnerVisible = true;
var result = await userService.ChangePasswordYourself(dto); var result = false;
string Role = await localStorageService.GetItem<string>("C/Role");
if (Role == "Company")
result = await companyService.ChangePasswordCompany(dto);
else if (Role == "Exper")
result = await userService.ChangePasswordYourself(dto);
if (result) if (result)
{ {
ToastService.Notify(new ToastMessage(ToastType.Success, "تغییر کلمه عبور با موفقیت انجام شد")); ToastService.Notify(new ToastMessage(ToastType.Success, "تغییر کلمه عبور با موفقیت انجام شد"));

View File

@@ -27,12 +27,12 @@
public Update_ExperDto model { get; set; } = new(); public Update_ExperDto model { get; set; } = new();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
var user=await userService.GetCurrentUser(); var user = await userService.GetCurrentExper();
if (user!=null) if (user!=null)
{ {
model.FullName = user.FullName; model.FullName = user.FullName;
Role = await localStorageService.GetItem<string>("Role"); Role = await localStorageService.GetItem<string>("C/Role");
isAuthorizedCompanyUser = Role=="Exper" && await userService.CheckAvailableExperInCompany(); isAuthorizedCompanyUser = Role=="Exper" && await userService.CheckAvailableExperInCompany();
} }
else else

View File

@@ -82,20 +82,21 @@
public string TitleRole { get; set; } = ""; public string TitleRole { get; set; } = "";
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
Role = await localStorageService.GetItem<string>("C/Role");
await CheckOnline(); await CheckOnline();
if (isonline) if (isonline)
{ {
//Roles = await localStorageService.GetItem<List<string>>("Role"); //Roles = await localStorageService.GetItem<List<string>>("Role");
Username = await localStorageService.GetItem<string>("Username"); Username = await localStorageService.GetItem<string>("C/Username");
Fullname = await localStorageService.GetItem<string>("Fullname"); Fullname = await localStorageService.GetItem<string>("C/Fullname");
string UserID = await localStorageService.GetItem<string>("UserID"); string UserID = await localStorageService.GetItem<string>("C/UserID");
img = await localStorageService.GetItem<byte[]?>("img"); img = await localStorageService.GetItem<byte[]?>("C/img");
} }
TitleRole = Role == "Company" ? "مدیر" : "کارشناس"; TitleRole = Role == "Company" ? "مدیر" : "کارشناس";
isAuthorizedCompanyUser = Role=="Company" || Role=="Exper" && await userService.CheckAvailableExperInCompany(); isAuthorizedCompanyUser = Role == "Company" || Role == "Exper" && await userService.CheckAvailableExperInCompany();
string route = NavigationManager.Uri.Replace(NavigationManager.BaseUri, "").ToLower(); string route = NavigationManager.Uri.Replace(NavigationManager.BaseUri, "").ToLower();
if (route.Length > 0) if (route.Length > 0)
@@ -120,13 +121,6 @@
await authService.Logout(); await authService.Logout();
NavigationManager.NavigateTo("/login"); NavigationManager.NavigateTo("/login");
} }
private async Task ChangePasword()
{
var parameters = new Dictionary<string, object>();
parameters.Add("Username", Username);
await modal.ShowAsync<ChangePassWordComponent>(title: "تغییر رمز عبور", parameters: parameters);
}
private async Task Settings() private async Task Settings()
{ {
var parameters = new Dictionary<string, object>(); var parameters = new Dictionary<string, object>();
@@ -135,10 +129,14 @@
} }
private async Task EditCurrentUser() private async Task EditCurrentUser()
{ {
var parameters = new Dictionary<string, object>(); if (Role == "Exper")
parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<Update_ExperDto>(this, CallBack)); {
var parameters = new Dictionary<string, object>();
parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<Update_ExperDto>(this, CallBack));
await modal.ShowAsync<EditUserYourselfComponent>(title: $"ویرایش کاربر {Username}", parameters: parameters);
}
await modal.ShowAsync<EditUserYourselfComponent>(title: $"ویرایش کاربر {Username}", parameters: parameters);
} }
async Task CallBack(Update_ExperDto edit) async Task CallBack(Update_ExperDto edit)
@@ -148,8 +146,8 @@
// await localStorageService.SetItem("img", img); // await localStorageService.SetItem("img", img);
Fullname = edit.FullName; Fullname = edit.FullName;
await localStorageService.RemoveItem("Fullname"); await localStorageService.RemoveItem("C/Fullname");
await localStorageService.SetItem("Fullname", Fullname); await localStorageService.SetItem("C/Fullname", Fullname);
} }
private void SetActiveMenu(string menu) private void SetActiveMenu(string menu)
@@ -189,7 +187,7 @@
else else
{ {
Role = await localStorageService.GetItem<string>("C/Role"); Role = await localStorageService.GetItem<string>("C/Role");
if (Role=="User") if (Role == "User")
{ {
isonline = false; isonline = false;
NavigationManager.NavigateTo("/NotFound"); NavigationManager.NavigateTo("/NotFound");
@@ -225,15 +223,23 @@
private IEnumerable<NavItem> GetNavItems() private IEnumerable<NavItem> GetNavItems()
{ {
navItems = new List<NavItem> if (Role == "Exper")
{ navItems = new List<NavItem>
// new NavItem { Href = "/", IconName = IconName.HouseDoorFill, Text = "خانه"}, {
// new NavItem { Href = "/Conversation", IconName = IconName.ChatText, Text = " گفتگو ها"}, new NavItem { Href = "/", IconName = IconName.ChatText, Text = " گفتگو ها"},
new NavItem { Href = "/Settings", IconName = IconName.Hammer, Text = " تنظیمات"},
};
else if (Role == "Company")
navItems = new List<NavItem>{
new NavItem { Href = "/", IconName = IconName.ChatText, Text = " گفتگو ها"}, new NavItem { Href = "/", IconName = IconName.ChatText, Text = " گفتگو ها"},
new NavItem { Href = "/UserManagement", IconName = IconName.PersonBoundingBox, Text = " مدیریت کاربران"}, new NavItem { Href = "/UserManagement", IconName = IconName.PersonBoundingBox, Text = " مدیریت کاربران"},
new NavItem { Href = "/GroupManagement", IconName = IconName.Grid1X2, Text = " مدیریت گروه ها"}, new NavItem { Href = "/GroupManagement", IconName = IconName.Grid1X2, Text = " مدیریت گروه ها"},
new NavItem { Href = "/Settings", IconName = IconName.Hammer, Text = " تنظیمات"}, new NavItem { Href = "/Settings", IconName = IconName.Hammer, Text = " تنظیمات"},
}; };
else navItems = new List<NavItem>();
return navItems; return navItems;
} }

View File

@@ -17,13 +17,13 @@
<span>به هوشیان</span> <span>به هوشیان</span>
</div> </div>
<div id="primary_form" class="form"> <EditForm id="primary_form" class="form" Model="model" OnSubmit="onClick" FormName="LoginForm">
<div class=" group w-full"> <div class=" group w-full">
<label for="user-name" class="block mb-2 text-slate-600 font-bold"> <label for="user-name" class="block mb-2 text-slate-600 font-bold">
شماره همراه / نام کاربری شماره همراه / نام کاربری
</label> </label>
<div class="container-input"> <div class="container-input">
<input style="text-align:center" type="text" @bind-value="username" id="user-name" maxlength="64" title="نام کاربری را وارد کنید." class="input-form input_vk_1" required="" data-val="true" data-val-required="شماره همراه / نام کاربری را وارد کنید." name="Username"> <input style="text-align:center" type="text" @bind-value="model.Username" id="user-name" maxlength="64" title="نام کاربری را وارد کنید." class="input-form input_vk_1" required="" data-val="true" data-val-required="شماره همراه / نام کاربری را وارد کنید." name="Username">
</div> </div>
</div> </div>
<div class="relative group"> <div class="relative group">
@@ -31,7 +31,7 @@
کلمه عبور کلمه عبور
</label> </label>
<div class="container-input"> <div class="container-input">
<input style="text-align:center" @bind-value=Password type="password" id="password" title="کلمه عبور را وارد کنید." maxlength="36" class="input-form input_vk_2" autocomplete="off" required="" data-val="true" data-val-required="کلمه عبور را وارد کنید." name="Password"> <input style="text-align:center" @bind-value=model.Password type="password" id="password" title="کلمه عبور را وارد کنید." maxlength="36" class="input-form input_vk_2" autocomplete="off" required="" data-val="true" data-val-required="کلمه عبور را وارد کنید." name="Password">
<div class=" flex gap-1 px-1"> <div class=" flex gap-1 px-1">
<div class="cursor-pointer hover:text-black hover:bg-primary hover:bg-opacity-10 rounded transition-all p-1 bg-slate-50 z-10 text-slate-500" onclick="showPassword(event, 'password')"> <div class="cursor-pointer hover:text-black hover:bg-primary hover:bg-opacity-10 rounded transition-all p-1 bg-slate-50 z-10 text-slate-500" onclick="showPassword(event, 'password')">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -53,7 +53,7 @@
</div> </div>
<div class=" space-y-5 flex flex-col items-center"> <div class=" space-y-5 flex flex-col items-center">
<Button Loading=Loading LoadingText="در حال ورود ..." Color="ButtonColor.Primary" Type="ButtonType.Submit" @onclick=onClick class="btn-primary w-full mb-4 lg:mb-0"> <Button Loading=Loading LoadingText="در حال ورود ..." Color="ButtonColor.Primary" Type="ButtonType.Submit" class="btn-primary w-full mb-4 lg:mb-0">
ورود ورود
</Button> </Button>
</div> </div>
@@ -64,14 +64,13 @@
</div> </div>
<input name="__RequestVerificationToken" type="hidden" value="CfDJ8P2efyfpaLFHon15HCO5GnTcqzVeJClceMnnP99o04SA4Jbau0j_wcgDQBvHrI3oVb7JTofciu8lxPVwkHOn85rf9-vWzZefUXIBfzQb9upg_bF2ZDxTduIs62mLs07I48u7WZpLohGSjdmJTjjcCQY"> <input name="__RequestVerificationToken" type="hidden" value="CfDJ8P2efyfpaLFHon15HCO5GnTcqzVeJClceMnnP99o04SA4Jbau0j_wcgDQBvHrI3oVb7JTofciu8lxPVwkHOn85rf9-vWzZefUXIBfzQb9upg_bF2ZDxTduIs62mLs07I48u7WZpLohGSjdmJTjjcCQY">
</div> </EditForm>
@code { @code {
[Inject] protected ToastService ToastService { get; set; } = default!; [Inject] protected ToastService ToastService { get; set; } = default!;
private ConfirmDialog dialog = default!; private ConfirmDialog dialog = default!;
[SupplyParameterFromForm]
AuthRequestFromCompanySide model { get; set; } = new();
private Modal modal = default!; private Modal modal = default!;
public string username { get; set; }
public string Password { get; set; }
public bool Loading { get; set; } public bool Loading { get; set; }
} }
@functions { @functions {
@@ -80,21 +79,11 @@
async Task onClick() async Task onClick()
{ {
if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password)) return;
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(Password)) return;
Loading = true; Loading = true;
var msg = await auth.login(new AuthRequestFromCompanySide() var msg = await auth.login(model);
{ if (msg == "ok") navigationManager.NavigateTo("/");
Username = username,
Password = Password
});
if (msg == "ok")
{
navigationManager.NavigateTo("/");
}
Loading = false; Loading = false;
} }

View File

@@ -40,8 +40,8 @@
</style> </style>
<div class="container-fluid"> <div class="container-fluid">
<div class="row row-fullheight"> @* <div class="row row-fullheight"> *@
<div class="row">
<!-- تغییر کلمه عبور --> <!-- تغییر کلمه عبور -->
<div class="col-md-6 d-flex flex-column" style="height: fit-content;"> <div class="col-md-6 d-flex flex-column" style="height: fit-content;">
<div class="section-box w-100"> <div class="section-box w-100">
@@ -82,7 +82,7 @@
<div class="col-md-12"> <div class="col-md-12">
<input dir="ltr" class="form-control text-center mb-2" @bind-value="@dto.WebSite" type="text" placeholder="وب سایت" /> <input dir="ltr" class="form-control text-center mb-2" @bind-value="@dto.WebSite" type="text" placeholder="وب سایت" />
</div> </div>
<div class="col-md-12 d-flex align-items-center mb-2"> <div class="col-md-12 d-flex align-items-center mb-2">
<InputFile type="file" OnChange="OnFileChange" accept=".png" /> <InputFile type="file" OnChange="OnFileChange" accept=".png" />
@if (dto.logo != null && dto.logo.Length > 0) @if (dto.logo != null && dto.logo.Length > 0)
@@ -101,7 +101,7 @@
} }
<!-- پایین چپ --> @* <!-- پایین چپ -->
<div class="col-md-6 d-flex flex-column"> <div class="col-md-6 d-flex flex-column">
<div class="section-box w-100"> <div class="section-box w-100">
<div class="section-title"> <div class="section-title">
@@ -119,23 +119,25 @@
</div> </div>
<!-- محتوای دلخواه --> <!-- محتوای دلخواه -->
</div> </div>
</div> </div> *@
</div> </div>
</div> </div>
@code { @code {
[Inject] protected ToastService ToastService { get; set; } = default!; [Inject] protected ToastService ToastService { get; set; } = default!;
bool ALLOWcompanyinfo = true; bool ALLOWcompanyinfo = false;
public bool loading { get; set; } = false; public bool loading { get; set; } = false;
public ReadANDUpdate_CompanyDto dto { get; set; } public ReadANDUpdate_CompanyDto dto { get; set; }
= new(); = new();
int CompanyID = 0; int CompanyID = 0;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
if (await localStorageService.GetItem<string>("Role") != "Company") if (await localStorageService.GetItem<string>("C/Role") == "User")
navigationManager.NavigateTo("/NotFound"); navigationManager.NavigateTo("/NotFound");
ALLOWcompanyinfo = await localStorageService.GetItem<string>("C/Role") == "Company";
CompanyID= await localStorageService.GetItem<int>("C/CompanyId"); CompanyID= await localStorageService.GetItem<int>("C/CompanyId");
dto = await companyService.GetCompany(CompanyID); dto = await companyService.GetCompany(CompanyID);

View File

@@ -1,4 +1,5 @@
using Common.Dtos.Company; using Common.Dtos;
using Common.Dtos.Company;
using System.Net.Http.Json; using System.Net.Http.Json;
namespace HushianWebApp.Service namespace HushianWebApp.Service
@@ -35,6 +36,11 @@ namespace HushianWebApp.Service
var response = await _baseController.Put($"{BaseRoute}UpdateCompany",dto); var response = await _baseController.Put($"{BaseRoute}UpdateCompany",dto);
return response.IsSuccessStatusCode; return response.IsSuccessStatusCode;
} }
public async Task<bool> ChangePasswordCompany(ChangePasswordDto request)
{
var response = await _baseController.Put($"{BaseRoute}ChangePasswordCompany", request);
return response.IsSuccessStatusCode;
}
//public async Task<bool> AddContentInfo(string str) //public async Task<bool> AddContentInfo(string str)
//{ //{
// var response = await _baseController.Post($"{BaseRoute}AddContentInfo?ContentInfo={str}"); // var response = await _baseController.Post($"{BaseRoute}AddContentInfo?ContentInfo={str}");

View File

@@ -46,9 +46,9 @@ namespace HushianWebApp.Service
var response = await _baseController.Put($"{BaseRoute}EditUserYourself", request); var response = await _baseController.Put($"{BaseRoute}EditUserYourself", request);
return response.IsSuccessStatusCode; return response.IsSuccessStatusCode;
} }
public async Task<Read_ExperDto?> GetCurrentUser() //ویرایش کاربران توسط خود public async Task<Read_ExperDto?> GetCurrentExper() //ویرایش کاربران توسط خود
{ {
var response = await _baseController.Get($"{BaseRoute}GetCurrentUser"); var response = await _baseController.Get($"{BaseRoute}GetCurrentExper");
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
return await response.Content.ReadFromJsonAsync<Read_ExperDto>(); return await response.Content.ReadFromJsonAsync<Read_ExperDto>();