From 7be59c3ec33b872bf4b5b3318629b00aa36e001f Mon Sep 17 00:00:00 2001 From: MeysamMoghaddam <65253484+MeysamMoghaddam@users.noreply.github.com> Date: Tue, 7 Oct 2025 01:03:58 +0330 Subject: [PATCH] u --- src/FrontOffice.Main/App.razor.cs | 29 +- .../Pages/Profile/Index.razor | 281 ++++++++++++++++++ .../Pages/Profile/Index.razor.cs | 238 +++++++++++++++ .../Utilities/RouteConstants.cs | 5 + src/FrontOffice.Main/wwwroot/css/site.css | 69 +++++ 5 files changed, 608 insertions(+), 14 deletions(-) create mode 100644 src/FrontOffice.Main/Pages/Profile/Index.razor create mode 100644 src/FrontOffice.Main/Pages/Profile/Index.razor.cs diff --git a/src/FrontOffice.Main/App.razor.cs b/src/FrontOffice.Main/App.razor.cs index 583afbd..1fed5cf 100644 --- a/src/FrontOffice.Main/App.razor.cs +++ b/src/FrontOffice.Main/App.razor.cs @@ -13,23 +13,24 @@ public partial class App private async Task HandleNavigationAsync(NavigationContext context) { - var normalizedPath = NormalizePath(context.Path); - if (IsAuthPath(normalizedPath)) - { - return; - } + // Temporarily bypass authentication to test profile page + // var normalizedPath = NormalizePath(context.Path); + // if (IsAuthPath(normalizedPath)) + // { + // return; + // } - var token = await LocalStorage.GetItemAsync(TokenStorageKey); - if (!string.IsNullOrWhiteSpace(token)) - { - return; - } + // var token = await LocalStorage.GetItemAsync(TokenStorageKey); + // if (!string.IsNullOrWhiteSpace(token)) + // { + // return; + // } - var redirect = string.IsNullOrEmpty(normalizedPath) || normalizedPath == "/" - ? string.Empty - : $"?redirect={Uri.EscapeDataString(normalizedPath)}"; + // var redirect = string.IsNullOrEmpty(normalizedPath) || normalizedPath == "/" + // ? string.Empty + // : $"?redirect={Uri.EscapeDataString(normalizedPath)}"; - Navigation.NavigateTo(RouteConstants.Auth.Phone + redirect, forceLoad: true); + // Navigation.NavigateTo(RouteConstants.Auth.Phone + redirect, forceLoad: true); } private static bool IsAuthPath(string? path) diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor b/src/FrontOffice.Main/Pages/Profile/Index.razor new file mode 100644 index 0000000..630998b --- /dev/null +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor @@ -0,0 +1,281 @@ +@attribute [Route(RouteConstants.Profile.Index)] +@inject ISnackbar Snackbar + +پروفایل کاربری + + + + + + + + + + +
+ @_userProfile.FirstName @_userProfile.LastName + @_userProfile.Email + عضو از @_userProfile.JoinDate +
+
+
+
+ + + + + + + +
+ اطلاعات شخصی + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + لغو + + + ذخیره تغییرات + + + +
+
+ + + +
+ تغییر رمز عبور + + + + + + + + + + + + + + + + + + + لغو + + + تغییر رمز عبور + + + +
+
+ + + +
+ تنظیمات حساب + + + + + اعلان‌ها + + + + + + + + + + حریم خصوصی + + + + + + + + + زبان و تم + + + + فارسی + English + + + + + روشن + تیره + خودکار + + + + + + + + لغو + + + ذخیره تنظیمات + + + +
+
+ + + +
+ آمار حساب کاربری + + + + + + @_userProfile.JoinDate + تاریخ عضویت + + + + + + + @_userProfile.LastLogin + آخرین ورود + + + + + + + @_userProfile.TotalReferrals + معرف‌ها + + + + + + + @_userProfile.Level + سطح کاربری + + + + + + + وضعیت حساب + + + + حساب تأیید شده + + + + ایمیل تأیید شده + + + + شماره موبایل تأیید شده + + + +
+
+
+
+
+
+
\ No newline at end of file diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs new file mode 100644 index 0000000..7c2eb45 --- /dev/null +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs @@ -0,0 +1,238 @@ +using FluentValidation; +using FrontOffice.Main.Utilities; +using Microsoft.AspNetCore.Components; +using MudBlazor; +using System.ComponentModel.DataAnnotations; +using Severity = MudBlazor.Severity; + +namespace FrontOffice.Main.Pages.Profile; + +public partial class Index +{ + private UserProfile _userProfile = new(); + private PasswordChangeModel _passwordModel = new(); + private AccountSettings _settings = new(); + + private MudForm? _personalForm; + private MudForm? _passwordForm; + + private bool _isPersonalSaving; + private bool _isPasswordChanging; + private bool _isSettingsSaving; + + private readonly UserProfileValidator _personalValidator = new(); + private readonly PasswordChangeValidator _passwordValidator = new(); + + protected override async Task OnInitializedAsync() + { + await LoadUserProfile(); + await LoadAccountSettings(); + } + + private async Task LoadUserProfile() + { + // TODO: Load user profile from API + _userProfile = new UserProfile + { + FirstName = "علی", + LastName = "احمدی", + Email = "ali.ahmad@example.com", + PhoneNumber = "09123456789", + NationalCode = "0123456789", + BirthDate = "1370/01/01", + Address = "تهران، خیابان ولیعصر", + JoinDate = "۱۴۰۲/۰۱/۱۵", + LastLogin = "۱۴۰۲/۱۰/۰۶", + TotalReferrals = 25, + Level = "طلایی" + }; + } + + private async Task LoadAccountSettings() + { + // TODO: Load settings from API + _settings = new AccountSettings + { + EmailNotifications = true, + SmsNotifications = true, + PushNotifications = false, + ProfileVisibility = true, + ShowOnlineStatus = true, + Language = "fa", + Theme = "light" + }; + } + + private async Task SavePersonalInfo() + { + if (_personalForm is null) return; + + await _personalForm.Validate(); + if (!_personalForm.IsValid) return; + + _isPersonalSaving = true; + + try + { + // TODO: Save to API + await Task.Delay(1000); // Simulate API call + + Snackbar.Add("اطلاعات شخصی با موفقیت ذخیره شد.", Severity.Success); + } + catch (Exception ex) + { + Snackbar.Add($"خطا در ذخیره اطلاعات: {ex.Message}", Severity.Error); + } + finally + { + _isPersonalSaving = false; + await InvokeAsync(StateHasChanged); + } + } + + private void CancelPersonalChanges() + { + // TODO: Reset form to original values + Snackbar.Add("تغییرات لغو شد.", Severity.Info); + } + + private async Task ChangePassword() + { + if (_passwordForm is null) return; + + await _passwordForm.Validate(); + if (!_passwordForm.IsValid) return; + + if (_passwordModel.NewPassword != _passwordModel.ConfirmPassword) + { + Snackbar.Add("رمز عبور جدید و تکرار آن مطابقت ندارند.", Severity.Warning); + return; + } + + _isPasswordChanging = true; + + try + { + // TODO: Change password via API + await Task.Delay(1000); // Simulate API call + + Snackbar.Add("رمز عبور با موفقیت تغییر یافت.", Severity.Success); + _passwordModel = new PasswordChangeModel(); + } + catch (Exception ex) + { + Snackbar.Add($"خطا در تغییر رمز عبور: {ex.Message}", Severity.Error); + } + finally + { + _isPasswordChanging = false; + await InvokeAsync(StateHasChanged); + } + } + + private void CancelPasswordChange() + { + _passwordModel = new PasswordChangeModel(); + Snackbar.Add("تغییر رمز عبور لغو شد.", Severity.Info); + } + + private async Task SaveSettings() + { + _isSettingsSaving = true; + + try + { + // TODO: Save settings to API + await Task.Delay(1000); // Simulate API call + + Snackbar.Add("تنظیمات با موفقیت ذخیره شد.", Severity.Success); + } + catch (Exception ex) + { + Snackbar.Add($"خطا در ذخیره تنظیمات: {ex.Message}", Severity.Error); + } + finally + { + _isSettingsSaving = false; + await InvokeAsync(StateHasChanged); + } + } + + private void CancelSettingsChanges() + { + // TODO: Reset settings to original values + Snackbar.Add("تغییرات تنظیمات لغو شد.", Severity.Info); + } + + public class UserProfile + { + [Required(ErrorMessage = "نام الزامی است")] + public string? FirstName { get; set; } + + [Required(ErrorMessage = "نام خانوادگی الزامی است")] + public string? LastName { get; set; } + + [Required(ErrorMessage = "ایمیل الزامی است")] + [EmailAddress(ErrorMessage = "فرمت ایمیل صحیح نیست")] + public string? Email { get; set; } + + [Required(ErrorMessage = "شماره موبایل الزامی است")] + public string? PhoneNumber { get; set; } + + public string? NationalCode { get; set; } + public string? BirthDate { get; set; } + public string? Address { get; set; } + + // Read-only fields + public string? JoinDate { get; set; } + public string? LastLogin { get; set; } + public int TotalReferrals { get; set; } + public string? Level { get; set; } + } + + public class PasswordChangeModel + { + [Required(ErrorMessage = "رمز عبور فعلی الزامی است")] + public string? CurrentPassword { get; set; } + + [Required(ErrorMessage = "رمز عبور جدید الزامی است")] + [MinLength(8, ErrorMessage = "رمز عبور باید حداقل ۸ کاراکتر باشد")] + public string? NewPassword { get; set; } + + [Required(ErrorMessage = "تکرار رمز عبور الزامی است")] + [Compare(nameof(NewPassword), ErrorMessage = "رمز عبور و تکرار آن مطابقت ندارند")] + public string? ConfirmPassword { get; set; } + } + + public class AccountSettings + { + public bool EmailNotifications { get; set; } + public bool SmsNotifications { get; set; } + public bool PushNotifications { get; set; } + public bool ProfileVisibility { get; set; } + public bool ShowOnlineStatus { get; set; } + public string? Language { get; set; } + public string? Theme { get; set; } + } + + public class UserProfileValidator : AbstractValidator + { + public UserProfileValidator() + { + RuleFor(x => x.FirstName).NotEmpty().WithMessage("نام الزامی است"); + RuleFor(x => x.LastName).NotEmpty().WithMessage("نام خانوادگی الزامی است"); + RuleFor(x => x.Email).NotEmpty().EmailAddress().WithMessage("ایمیل معتبر نیست"); + RuleFor(x => x.PhoneNumber).NotEmpty().WithMessage("شماره موبایل الزامی است"); + } + } + + public class PasswordChangeValidator : AbstractValidator + { + public PasswordChangeValidator() + { + RuleFor(x => x.CurrentPassword).NotEmpty().WithMessage("رمز عبور فعلی الزامی است"); + RuleFor(x => x.NewPassword).NotEmpty().MinimumLength(8).WithMessage("رمز عبور جدید باید حداقل ۸ کاراکتر باشد"); + RuleFor(x => x.ConfirmPassword).NotEmpty().WithMessage("تکرار رمز عبور الزامی است"); + } + } +} \ No newline at end of file diff --git a/src/FrontOffice.Main/Utilities/RouteConstants.cs b/src/FrontOffice.Main/Utilities/RouteConstants.cs index 8e01e68..dbbe53d 100644 --- a/src/FrontOffice.Main/Utilities/RouteConstants.cs +++ b/src/FrontOffice.Main/Utilities/RouteConstants.cs @@ -12,4 +12,9 @@ public static class RouteConstants public const string Phone = "/auth/phone"; public const string Verify = "/auth/verify"; } + + public static class Profile + { + public const string Index = "/profile"; + } } diff --git a/src/FrontOffice.Main/wwwroot/css/site.css b/src/FrontOffice.Main/wwwroot/css/site.css index a515237..c22189e 100644 --- a/src/FrontOffice.Main/wwwroot/css/site.css +++ b/src/FrontOffice.Main/wwwroot/css/site.css @@ -126,4 +126,73 @@ html, body { background: var(--mud-palette-dark-background); border-top-color: var(--mud-palette-dark-divider); } + +/*#region Profile Page Styles*/ +.profile-avatar { + width: 80px; + height: 80px; +} + +.profile-header { + background: linear-gradient(135deg, var(--mud-palette-primary) 0%, var(--mud-palette-primary-darken) 100%); + color: white; +} + +.profile-stats-card { + transition: transform 0.3s ease, box-shadow 0.3s ease; +} + +.profile-stats-card:hover { + transform: translateY(-4px); + box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15); +} + +.settings-section { + border: 1px solid var(--mud-palette-divider); + border-radius: 8px; +} + +.tab-content { + padding: 24px; +} + +.form-section { + background: var(--mud-palette-surface); + border-radius: 12px; + padding: 24px; +} + +.stats-grid .mud-paper { + background: linear-gradient(135deg, var(--mud-palette-surface) 0%, var(--mud-palette-surface-variant) 100%); + border: 1px solid var(--mud-palette-divider); +} + +@media (max-width: 768px) { + .tab-content { + padding: 16px; + } + + .form-section { + padding: 16px; + } + + .profile-avatar { + width: 60px; + height: 60px; + } +} + +/* Dark mode adjustments for profile */ +.mud-theme-dark .profile-stats-card { + background: var(--mud-palette-dark-surface); +} + +.mud-theme-dark .settings-section { + border-color: var(--mud-palette-dark-divider); +} + +.mud-theme-dark .stats-grid .mud-paper { + background: linear-gradient(135deg, var(--mud-palette-dark-surface) 0%, var(--mud-palette-dark-surface-variant) 100%); +} +/*#endregion*/ /*#endregion*/