Commit 5d39c9ea authored by hasan khaddour's avatar hasan khaddour

update auth services.

parent 85f8d4fd
using Microsoft.AspNetCore.Http;
using FluentResults;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Application.Contracts.Authentication;
using PSManagement.Contracts.Authentication;
using PSManagement.SharedKernel.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AuthenticationResponse = PSManagement.Contracts.Authentication.AuthenticationResponse;
......@@ -36,7 +32,7 @@ namespace PSManagement.Api.Controllers.Authentication
return Ok(response);
}
return Problem(title:"An Errorr Occured",detail:result.Error.Name,statusCode:400);
return Problem(title: result.Reasons[0].Message,detail:result.Errors[0].Message,statusCode:400);
}
[HttpPost("Register")]
public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest)
......@@ -59,7 +55,7 @@ namespace PSManagement.Api.Controllers.Authentication
return Ok(response);
}
return Problem(title: "An Errorr Occured", detail: result.Error.Name, statusCode: 400);
return Problem(title: "An Errorr Occured "+result.Errors[0].Message , detail: result.Reasons[0].Message, statusCode: 400);
}
}
......
using PSManagement.SharedKernel.Utilities;
//using PSManagement.SharedKernel.Utilities;
using FluentResults;
using System;
using System.Threading.Tasks;
......
using PSManagement.Application.Contracts.Authentication;
using FluentResults;
using PSManagement.Application.Contracts.Authentication;
using PSManagement.Application.Contracts.Authorization;
using PSManagement.SharedKernel.Utilities;
//using PSManagement.SharedKernel.Utilities;
using System;
using System.Threading.Tasks;
......@@ -21,24 +22,23 @@ namespace PSManagement.Infrastructure.Services.Authentication
User u = await _userRepository.GetByEmail(email);
if (u is null || u.Password != password) {
return Result.Failure<AuthenticationResult>(new Error("404", "the password or email maybe wrong!."));
return Result.Fail<AuthenticationResult>(new Error( "the password or email maybe wrong!."));
}
String token = _jwtTokenGenerator.GenerateToken(u.Id,u.FirstName,u.LastName,u.Email);
return Result.Success<AuthenticationResult>(
new AuthenticationResult {
Id = u.Id,
Email=u.Email,
FirstName=u.FirstName,
LastName =u.LastName,
Token=token});
return new AuthenticationResult {
Id = u.Id,
Email=u.Email,
FirstName=u.FirstName,
LastName =u.LastName,
Token=token};
}
public async Task<Result<AuthenticationResult>> Register(String email, String firstName, String lastName, String password) {
// check if the user exist
var u = await _userRepository.GetByEmail(email);
if (u is not null) {
return Result.Failure<AuthenticationResult>(new Error("404","the user already exist "));
return Result.Fail<AuthenticationResult>(new Error("the user already exist "));
}
await _userRepository.AddAsync(
new User{
......@@ -49,7 +49,7 @@ namespace PSManagement.Infrastructure.Services.Authentication
});
// generate token
String token = _jwtTokenGenerator.GenerateToken(2322323,firstName,lastName,email);
return Result.Success<AuthenticationResult>(
return Result.Ok<AuthenticationResult>(
new AuthenticationResult
{
Id = 233233,
......
......@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentResults" Version="3.16.0" />
<PackageReference Include="MediatR" Version="5.1.0" />
</ItemGroup>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment