Initial commit — AsadiTools v1.0
Full ASP.NET Core 10 Razor Pages app for آساد ابزار tool repair shop in Karaj, Iran (official DeWalt representative). Features: - Homepage, Services, DeWalt page, Shop (pagination + images) - 10 brand SEO pages (/brands/*) with rich Persian content + FAQ schema - Blog engine with admin management (/blog, /Admin/Blog) - Cart, Checkout, Contact (OpenStreetMap embed) - Admin panel: Products CRUD, Orders, Blog, Change Password - Jalali date formatting, product images, SiteData centralised contact - Docker + docker-compose with healthcheck - Gitea CI/CD via .gitea/workflows/ci-cd.yml (NuGet through Nexus mirror) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using AsadiTools.Data;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace AsadiTools.Pages.Admin.ChangePassword;
|
||||
|
||||
[Authorize(AuthenticationSchemes = "AdminCookie")]
|
||||
public class ChangePasswordModel(AppDbContext db) : PageModel
|
||||
{
|
||||
[BindProperty] public ChangePasswordInput Input { get; set; } = new();
|
||||
public string? ErrorMessage { get; private set; }
|
||||
public bool Success { get; private set; }
|
||||
|
||||
public void OnGet() { }
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid) return Page();
|
||||
|
||||
var userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||
var user = await db.AdminUsers.FindAsync(userId);
|
||||
if (user is null) return RedirectToPage("/Admin/Login");
|
||||
|
||||
if (!BCrypt.Net.BCrypt.Verify(Input.CurrentPassword, user.PasswordHash))
|
||||
{
|
||||
ErrorMessage = "رمز عبور فعلی اشتباه است";
|
||||
return Page();
|
||||
}
|
||||
|
||||
if (Input.NewPassword != Input.ConfirmPassword)
|
||||
{
|
||||
ErrorMessage = "رمز عبور جدید و تکرار آن یکسان نیستند";
|
||||
return Page();
|
||||
}
|
||||
|
||||
user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(Input.NewPassword);
|
||||
await db.SaveChangesAsync();
|
||||
Success = true;
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
|
||||
public class ChangePasswordInput
|
||||
{
|
||||
[Required] public string CurrentPassword { get; set; } = string.Empty;
|
||||
[Required, MinLength(6)] public string NewPassword { get; set; } = string.Empty;
|
||||
[Required] public string ConfirmPassword { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user