resend
This commit is contained in:
@@ -8,9 +8,20 @@ using Webshop.Application.DTOs.Customers; // UpdateCustomerProfileDto
|
||||
using Webshop.Application.Services;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.Services.Customers;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Webshop.Api.Controllers.Customer
|
||||
{
|
||||
public class ChangeEmailRequestDto
|
||||
{
|
||||
[Required(ErrorMessage = "Neue E-Mail ist erforderlich.")]
|
||||
[EmailAddress(ErrorMessage = "Ung<6E>ltiges E-Mail-Format.")]
|
||||
public string NewEmail { get; set; } = string.Empty;
|
||||
|
||||
[Required(ErrorMessage = "Aktuelles Passwort ist erforderlich.")]
|
||||
public string CurrentPassword { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/customer/[controller]")] // z.B. /api/v1/customer/profile
|
||||
[Authorize(Roles = "Customer")]
|
||||
@@ -66,6 +77,19 @@ namespace Webshop.Api.Controllers.Customer
|
||||
return Ok(new { Message = "Profil erfolgreich aktualisiert." });
|
||||
}
|
||||
|
||||
// << ENTFERNT: UpdateContactInfo Endpoint >>
|
||||
[HttpPost("change-email-request")] // /api/v1/customer/profile/change-email-request
|
||||
public async Task<IActionResult> ChangeEmailRequest([FromBody] ChangeEmailRequestDto request) // DTO erstellen
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrEmpty(userId)) return Unauthorized(new { Message = "Benutzer-ID nicht im Token gefunden." });
|
||||
|
||||
var (success, errorMessage) = await _customerService.ChangeEmailAsync(userId, request.NewEmail, request.CurrentPassword);
|
||||
|
||||
if (!success) return BadRequest(new { Message = errorMessage });
|
||||
|
||||
return Ok(new { Message = errorMessage }); // Sendet Info, dass Mail gesendet wurde
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user