-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegisterHandler.cs
More file actions
44 lines (39 loc) · 1.41 KB
/
RegisterHandler.cs
File metadata and controls
44 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Eventz.Application.Common;
using Eventz.Application.Dtos;
using Eventz.Application.Interfaces;
using Eventz.Domain.Entitites;
using MediatR;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Eventz.Application.Features.Auth.Register
{
internal class RegisterHandler : IRequestHandler<RegistrationCommand, ApiResponse<RegisterDto>>
{
private readonly IAuth _auth;
public RegisterHandler(IAuth auth)
{
_auth = auth;
}
public async Task<ApiResponse<RegisterDto>> Handle (RegistrationCommand command, CancellationToken cancellationToken) {
var hasher = new PasswordHasher<object>();
var hashedPassword = hasher.HashPassword(null, command.Password);
var result = hasher.VerifyHashedPassword(null, hashedPassword, command.Password);
if (result != PasswordVerificationResult.Success)
{
return ApiResponse<RegisterDto>.Failure("Password Mismatch");
}
var newUser = new RegisterDto
{
UserName = command.UserName,
Email = command.Email,
Password = hashedPassword
};
await _auth.RegisterUser (newUser);
return ApiResponse<RegisterDto>.Success(newUser);
}
}
}