Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
ProjectsStatusManagement
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
ProjectsStatusManagement
Commits
5d39c9ea
Commit
5d39c9ea
authored
Jul 18, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update auth services.
parent
85f8d4fd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
20 deletions
+18
-20
AuthenticationController.cs
...pi/Controllers/Authentication/AuthenticationController.cs
+3
-7
IAuthenticationService.cs
...cation/Contracts/Authentication/IAuthenticationService.cs
+2
-1
AuthenticationService.cs
...tructure/Services/Authentication/AuthenticationService.cs
+12
-12
PSManagement.SharedKernel.csproj
PSManagement.SharedKernel/PSManagement.SharedKernel.csproj
+1
-0
No files found.
PSManagement.Api/Controllers/Authentication/AuthenticationController.cs
View file @
5d39c9ea
using
Microsoft.AspNetCore.Http
;
using
FluentResults
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Contracts.Authentication
;
using
PSManagement.Contracts.Authentication
;
using
PSManagement.SharedKernel.Utilities
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
AuthenticationResponse
=
PSManagement
.
Contracts
.
Authentication
.
AuthenticationResponse
;
using
AuthenticationResponse
=
PSManagement
.
Contracts
.
Authentication
.
AuthenticationResponse
;
...
@@ -36,7 +32,7 @@ namespace PSManagement.Api.Controllers.Authentication
...
@@ -36,7 +32,7 @@ namespace PSManagement.Api.Controllers.Authentication
return
Ok
(
response
);
return
Ok
(
response
);
}
}
return
Problem
(
title
:
"An Errorr Occured"
,
detail
:
result
.
Error
.
Nam
e
,
statusCode
:
400
);
return
Problem
(
title
:
result
.
Reasons
[
0
].
Message
,
detail
:
result
.
Errors
[
0
].
Messag
e
,
statusCode
:
400
);
}
}
[
HttpPost
(
"Register"
)]
[
HttpPost
(
"Register"
)]
public
async
Task
<
IActionResult
>
Register
([
FromBody
]
RegisterRequest
registerRequest
)
public
async
Task
<
IActionResult
>
Register
([
FromBody
]
RegisterRequest
registerRequest
)
...
@@ -59,7 +55,7 @@ namespace PSManagement.Api.Controllers.Authentication
...
@@ -59,7 +55,7 @@ namespace PSManagement.Api.Controllers.Authentication
return
Ok
(
response
);
return
Ok
(
response
);
}
}
return
Problem
(
title
:
"An Errorr Occured
"
,
detail
:
result
.
Error
.
Nam
e
,
statusCode
:
400
);
return
Problem
(
title
:
"An Errorr Occured
"
+
result
.
Errors
[
0
].
Message
,
detail
:
result
.
Reasons
[
0
].
Messag
e
,
statusCode
:
400
);
}
}
}
}
...
...
PSManagement.Application/Contracts/Authentication/IAuthenticationService.cs
View file @
5d39c9ea
using
PSManagement.SharedKernel.Utilities
;
//using PSManagement.SharedKernel.Utilities;
using
FluentResults
;
using
System
;
using
System
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
...
PSManagement.Infrastructure/Services/Authentication/AuthenticationService.cs
View file @
5d39c9ea
using
PSManagement.Application.Contracts.Authentication
;
using
FluentResults
;
using
PSManagement.Application.Contracts.Authentication
;
using
PSManagement.Application.Contracts.Authorization
;
using
PSManagement.Application.Contracts.Authorization
;
using
PSManagement.SharedKernel.Utilities
;
//
using PSManagement.SharedKernel.Utilities;
using
System
;
using
System
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
@@ -21,24 +22,23 @@ namespace PSManagement.Infrastructure.Services.Authentication
...
@@ -21,24 +22,23 @@ namespace PSManagement.Infrastructure.Services.Authentication
User
u
=
await
_userRepository
.
GetByEmail
(
email
);
User
u
=
await
_userRepository
.
GetByEmail
(
email
);
if
(
u
is
null
||
u
.
Password
!=
password
)
{
if
(
u
is
null
||
u
.
Password
!=
password
)
{
return
Result
.
Fail
ure
<
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
);
String
token
=
_jwtTokenGenerator
.
GenerateToken
(
u
.
Id
,
u
.
FirstName
,
u
.
LastName
,
u
.
Email
);
return
Result
.
Success
<
AuthenticationResult
>(
return
new
AuthenticationResult
{
new
AuthenticationResult
{
Id
=
u
.
Id
,
Id
=
u
.
Id
,
Email
=
u
.
Email
,
Email
=
u
.
Email
,
FirstName
=
u
.
FirstName
,
FirstName
=
u
.
FirstName
,
LastName
=
u
.
LastName
,
LastName
=
u
.
LastName
,
Token
=
token
};
Token
=
token
});
}
}
public
async
Task
<
Result
<
AuthenticationResult
>>
Register
(
String
email
,
String
firstName
,
String
lastName
,
String
password
)
{
public
async
Task
<
Result
<
AuthenticationResult
>>
Register
(
String
email
,
String
firstName
,
String
lastName
,
String
password
)
{
// check if the user exist
// check if the user exist
var
u
=
await
_userRepository
.
GetByEmail
(
email
);
var
u
=
await
_userRepository
.
GetByEmail
(
email
);
if
(
u
is
not
null
)
{
if
(
u
is
not
null
)
{
return
Result
.
Fail
ure
<
AuthenticationResult
>(
new
Error
(
"404"
,
"the user already exist "
));
return
Result
.
Fail
<
AuthenticationResult
>(
new
Error
(
"the user already exist "
));
}
}
await
_userRepository
.
AddAsync
(
await
_userRepository
.
AddAsync
(
new
User
{
new
User
{
...
@@ -49,7 +49,7 @@ namespace PSManagement.Infrastructure.Services.Authentication
...
@@ -49,7 +49,7 @@ namespace PSManagement.Infrastructure.Services.Authentication
});
});
// generate token
// generate token
String
token
=
_jwtTokenGenerator
.
GenerateToken
(
2322323
,
firstName
,
lastName
,
email
);
String
token
=
_jwtTokenGenerator
.
GenerateToken
(
2322323
,
firstName
,
lastName
,
email
);
return
Result
.
Success
<
AuthenticationResult
>(
return
Result
.
Ok
<
AuthenticationResult
>(
new
AuthenticationResult
new
AuthenticationResult
{
{
Id
=
233233
,
Id
=
233233
,
...
...
PSManagement.SharedKernel/PSManagement.SharedKernel.csproj
View file @
5d39c9ea
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<PackageReference Include="FluentResults" Version="3.16.0" />
<PackageReference Include="MediatR" Version="5.1.0" />
<PackageReference Include="MediatR" Version="5.1.0" />
</ItemGroup>
</ItemGroup>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment