diff --git a/Hushian.Application/Services/AuthService.cs b/Hushian.Application/Services/AuthService.cs index dbe8fee..5a8e802 100644 --- a/Hushian.Application/Services/AuthService.cs +++ b/Hushian.Application/Services/AuthService.cs @@ -74,7 +74,7 @@ namespace Hushian.Application.Services } 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); if (exper == null) { @@ -85,7 +85,7 @@ namespace Hushian.Application.Services Response.Success = true; Response.Value = new AuthResponse() { - Fullname = exper.FullName, + Fullname = exper.FullName+" ("+ exper.Company.FullName+")", Id = exper.ID, CompanyId = exper.CompanyID, MobileOrUserName = exper.UserName, diff --git a/Hushian.Application/Services/CompanyService.cs b/Hushian.Application/Services/CompanyService.cs index 54901ef..b80918d 100644 --- a/Hushian.Application/Services/CompanyService.cs +++ b/Hushian.Application/Services/CompanyService.cs @@ -70,6 +70,8 @@ namespace Hushian.Application.Services company.Email = model.Email; company.WebSite = model.WebSite; company.logo = model.logo; + company.allowBot = model.allowBot; + company.Available = model.Available; if (await _CompanyRepository.UPDATEBool(company)) { diff --git a/Presentation/Hushian.WebApi/Controllers/v1/CompanyController.cs b/Presentation/Hushian.WebApi/Controllers/v1/CompanyController.cs index 4b4df7b..4f7679d 100644 --- a/Presentation/Hushian.WebApi/Controllers/v1/CompanyController.cs +++ b/Presentation/Hushian.WebApi/Controllers/v1/CompanyController.cs @@ -1,4 +1,5 @@ -using Common.Dtos.Company; +using Common.Dtos; +using Common.Dtos.Company; using Hushian.Application.Constants; using Hushian.Application.Services; using Microsoft.AspNetCore.Authorization; @@ -39,7 +40,15 @@ namespace Hushian.WebApi.Controllers.v1 return response.Success && response.Value ? NoContent() : BadRequest(response.Errors); } - + [HttpPut("ChangePasswordCompany")] + [Authorize(Roles = "Company")] + public async Task 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); + } + } } diff --git a/Presentation/HushianWebApp/Components/ChangePassWordComponent.razor b/Presentation/HushianWebApp/Components/ChangePassWordComponent.razor index 91de216..59d99eb 100644 --- a/Presentation/HushianWebApp/Components/ChangePassWordComponent.razor +++ b/Presentation/HushianWebApp/Components/ChangePassWordComponent.razor @@ -6,6 +6,8 @@ @inject NavigationManager NavigationManager @inject AuthService authService; @inject ILocalStorageService localStorageService; +@inject CompanyService companyService +
@@ -52,7 +54,7 @@ return; } - List errors = new(); + List errors = new(); if (!dto.NewPassWord.CheckLawPassword(ref errors)) { ToastService.Notify(new(ToastType.Danger, errors.First())); @@ -60,7 +62,15 @@ } SpinnerVisible = true; - var result = await userService.ChangePasswordYourself(dto); + var result = false; + string Role = await localStorageService.GetItem("C/Role"); + + if (Role == "Company") + result = await companyService.ChangePasswordCompany(dto); + + else if (Role == "Exper") + result = await userService.ChangePasswordYourself(dto); + if (result) { ToastService.Notify(new ToastMessage(ToastType.Success, "تغییر کلمه عبور با موفقیت انجام شد")); diff --git a/Presentation/HushianWebApp/Components/EditUserYourselfComponent.razor b/Presentation/HushianWebApp/Components/EditUserYourselfComponent.razor index 6fa166f..9de3b3a 100644 --- a/Presentation/HushianWebApp/Components/EditUserYourselfComponent.razor +++ b/Presentation/HushianWebApp/Components/EditUserYourselfComponent.razor @@ -27,12 +27,12 @@ public Update_ExperDto model { get; set; } = new(); protected override async Task OnInitializedAsync() { - var user=await userService.GetCurrentUser(); + var user = await userService.GetCurrentExper(); if (user!=null) { model.FullName = user.FullName; - Role = await localStorageService.GetItem("Role"); + Role = await localStorageService.GetItem("C/Role"); isAuthorizedCompanyUser = Role=="Exper" && await userService.CheckAvailableExperInCompany(); } else diff --git a/Presentation/HushianWebApp/Layout/MainLayout.razor b/Presentation/HushianWebApp/Layout/MainLayout.razor index 56751d3..8b360b1 100644 --- a/Presentation/HushianWebApp/Layout/MainLayout.razor +++ b/Presentation/HushianWebApp/Layout/MainLayout.razor @@ -82,20 +82,21 @@ public string TitleRole { get; set; } = ""; protected override async Task OnInitializedAsync() { + Role = await localStorageService.GetItem("C/Role"); await CheckOnline(); if (isonline) { //Roles = await localStorageService.GetItem>("Role"); - Username = await localStorageService.GetItem("Username"); - Fullname = await localStorageService.GetItem("Fullname"); - string UserID = await localStorageService.GetItem("UserID"); - img = await localStorageService.GetItem("img"); + Username = await localStorageService.GetItem("C/Username"); + Fullname = await localStorageService.GetItem("C/Fullname"); + string UserID = await localStorageService.GetItem("C/UserID"); + img = await localStorageService.GetItem("C/img"); } 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(); if (route.Length > 0) @@ -120,13 +121,6 @@ await authService.Logout(); NavigationManager.NavigateTo("/login"); } - private async Task ChangePasword() - { - var parameters = new Dictionary(); - parameters.Add("Username", Username); - await modal.ShowAsync(title: "تغییر رمز عبور", parameters: parameters); - - } private async Task Settings() { var parameters = new Dictionary(); @@ -135,10 +129,14 @@ } private async Task EditCurrentUser() { - var parameters = new Dictionary(); - parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBack)); + if (Role == "Exper") + { + var parameters = new Dictionary(); + parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBack)); + + await modal.ShowAsync(title: $"ویرایش کاربر {Username}", parameters: parameters); + } - await modal.ShowAsync(title: $"ویرایش کاربر {Username}", parameters: parameters); } async Task CallBack(Update_ExperDto edit) @@ -148,8 +146,8 @@ // await localStorageService.SetItem("img", img); Fullname = edit.FullName; - await localStorageService.RemoveItem("Fullname"); - await localStorageService.SetItem("Fullname", Fullname); + await localStorageService.RemoveItem("C/Fullname"); + await localStorageService.SetItem("C/Fullname", Fullname); } private void SetActiveMenu(string menu) @@ -189,7 +187,7 @@ else { Role = await localStorageService.GetItem("C/Role"); - if (Role=="User") + if (Role == "User") { isonline = false; NavigationManager.NavigateTo("/NotFound"); @@ -225,15 +223,23 @@ private IEnumerable GetNavItems() { - navItems = new List - { - // new NavItem { Href = "/", IconName = IconName.HouseDoorFill, Text = "خانه"}, - // new NavItem { Href = "/Conversation", IconName = IconName.ChatText, Text = " گفتگو ها"}, + if (Role == "Exper") + navItems = new List + { + new NavItem { Href = "/", IconName = IconName.ChatText, Text = " گفتگو ها"}, + new NavItem { Href = "/Settings", IconName = IconName.Hammer, Text = " تنظیمات"}, + }; + + else if (Role == "Company") + navItems = new List{ new NavItem { Href = "/", IconName = IconName.ChatText, Text = " گفتگو ها"}, new NavItem { Href = "/UserManagement", IconName = IconName.PersonBoundingBox, Text = " مدیریت کاربران"}, new NavItem { Href = "/GroupManagement", IconName = IconName.Grid1X2, Text = " مدیریت گروه ها"}, new NavItem { Href = "/Settings", IconName = IconName.Hammer, Text = " تنظیمات"}, - }; + }; + + else navItems = new List(); + return navItems; } diff --git a/Presentation/HushianWebApp/Pages/Auth/Login.razor b/Presentation/HushianWebApp/Pages/Auth/Login.razor index 24f6701..11a590e 100644 --- a/Presentation/HushianWebApp/Pages/Auth/Login.razor +++ b/Presentation/HushianWebApp/Pages/Auth/Login.razor @@ -17,13 +17,13 @@ به هوشیان -
+
- +
@@ -31,7 +31,7 @@ کلمه عبور
- +
@@ -53,7 +53,7 @@
-
@@ -64,14 +64,13 @@
-
+ @code { [Inject] protected ToastService ToastService { get; set; } = default!; private ConfirmDialog dialog = default!; - + [SupplyParameterFromForm] + AuthRequestFromCompanySide model { get; set; } = new(); private Modal modal = default!; - public string username { get; set; } - public string Password { get; set; } public bool Loading { get; set; } } @functions { @@ -80,21 +79,11 @@ async Task onClick() { - - if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(Password)) return; + if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password)) return; Loading = true; - var msg = await auth.login(new AuthRequestFromCompanySide() - { - Username = username, - Password = Password - }); - if (msg == "ok") - { - navigationManager.NavigateTo("/"); - } - - - + var msg = await auth.login(model); + if (msg == "ok") navigationManager.NavigateTo("/"); + Loading = false; } diff --git a/Presentation/HushianWebApp/Pages/Manage/Settings.razor b/Presentation/HushianWebApp/Pages/Manage/Settings.razor index 5cb63a1..ecf288f 100644 --- a/Presentation/HushianWebApp/Pages/Manage/Settings.razor +++ b/Presentation/HushianWebApp/Pages/Manage/Settings.razor @@ -40,8 +40,8 @@
-
- + @*
*@ +
@@ -82,7 +82,7 @@
- +
@if (dto.logo != null && dto.logo.Length > 0) @@ -101,7 +101,7 @@ } - + @*
@@ -119,23 +119,25 @@
-
+
*@
@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 ReadANDUpdate_CompanyDto dto { get; set; } = new(); int CompanyID = 0; protected override async Task OnInitializedAsync() { - if (await localStorageService.GetItem("Role") != "Company") + if (await localStorageService.GetItem("C/Role") == "User") navigationManager.NavigateTo("/NotFound"); + + ALLOWcompanyinfo = await localStorageService.GetItem("C/Role") == "Company"; CompanyID= await localStorageService.GetItem("C/CompanyId"); dto = await companyService.GetCompany(CompanyID); diff --git a/Presentation/HushianWebApp/Service/CompanyService.cs b/Presentation/HushianWebApp/Service/CompanyService.cs index 01cd68e..31f9510 100644 --- a/Presentation/HushianWebApp/Service/CompanyService.cs +++ b/Presentation/HushianWebApp/Service/CompanyService.cs @@ -1,4 +1,5 @@ -using Common.Dtos.Company; +using Common.Dtos; +using Common.Dtos.Company; using System.Net.Http.Json; namespace HushianWebApp.Service @@ -35,6 +36,11 @@ namespace HushianWebApp.Service var response = await _baseController.Put($"{BaseRoute}UpdateCompany",dto); return response.IsSuccessStatusCode; } + public async Task ChangePasswordCompany(ChangePasswordDto request) + { + var response = await _baseController.Put($"{BaseRoute}ChangePasswordCompany", request); + return response.IsSuccessStatusCode; + } //public async Task AddContentInfo(string str) //{ // var response = await _baseController.Post($"{BaseRoute}AddContentInfo?ContentInfo={str}"); diff --git a/Presentation/HushianWebApp/Service/UserService.cs b/Presentation/HushianWebApp/Service/UserService.cs index 6335fea..ae80e70 100644 --- a/Presentation/HushianWebApp/Service/UserService.cs +++ b/Presentation/HushianWebApp/Service/UserService.cs @@ -46,9 +46,9 @@ namespace HushianWebApp.Service var response = await _baseController.Put($"{BaseRoute}EditUserYourself", request); return response.IsSuccessStatusCode; } - public async Task GetCurrentUser() //ویرایش کاربران توسط خود + public async Task GetCurrentExper() //ویرایش کاربران توسط خود { - var response = await _baseController.Get($"{BaseRoute}GetCurrentUser"); + var response = await _baseController.Get($"{BaseRoute}GetCurrentExper"); if (response.IsSuccessStatusCode) { return await response.Content.ReadFromJsonAsync();