-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yusuf Enes Aras
committed
Aug 13, 2021
1 parent
97d2f10
commit 40cde49
Showing
182 changed files
with
51,430 additions
and
579 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Core.Entities.Concrete; | ||
using Core.Utilities.Results; | ||
using Core.Utilities.Security.JWT; | ||
using Entities.DTOs; | ||
|
||
namespace Business.Abstract | ||
{ | ||
public interface IAuthService | ||
{ | ||
IDataResult<User> Register(UserForRegisterDto userForRegisterDto, string password); | ||
IDataResult<User> Login(UserForLoginDto userForLoginDto); | ||
IResult UserExists(string email); | ||
IDataResult<AccessToken> CreateAccessToken(User user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Core.Utilities.Interceptors; | ||
using Core.Utilities.IoC; | ||
using Microsoft.AspNetCore.Http; | ||
using System; | ||
using Castle.DynamicProxy; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Core.Extensions; | ||
using Business.Constans; | ||
|
||
namespace Business.BusinessAspects.Autofac | ||
{ | ||
//Jwt için | ||
public class SecuredOperation : MethodInterception | ||
{ | ||
private string[] _roles; | ||
private IHttpContextAccessor _httpContextAccessor; | ||
|
||
public SecuredOperation(string roles) | ||
{ | ||
_roles = roles.Split(','); | ||
_httpContextAccessor = ServiceTool.ServiceProvider.GetService<IHttpContextAccessor>(); | ||
|
||
} | ||
|
||
protected override void OnBefore(IInvocation invocation) | ||
{ | ||
var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles(); | ||
foreach (var role in _roles) | ||
{ | ||
if (roleClaims.Contains(role)) | ||
{ | ||
return; | ||
} | ||
} | ||
throw new Exception(Messages.AuthorizationDenied); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Business.Abstract; | ||
using Core.Entities.Concrete; | ||
using Core.Utilities.Results; | ||
using Core.Utilities.Security.Hashing; | ||
using Core.Utilities.Security.JWT; | ||
using Entities.DTOs; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using DataAccess.Abstract; | ||
using System.Linq; | ||
using Business.Constans; | ||
|
||
namespace Business.Concrete | ||
{ | ||
public class AuthManager : IAuthService | ||
{ | ||
private IUserService _userService; | ||
private ITokenHelper _tokenHelper; | ||
|
||
public AuthManager(IUserService userService, ITokenHelper tokenHelper) | ||
{ | ||
_userService = userService; | ||
_tokenHelper = tokenHelper; | ||
} | ||
|
||
public IDataResult<User> Register(UserForRegisterDto userForRegisterDto, string password) | ||
{ | ||
byte[] passwordHash, passwordSalt; | ||
HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); | ||
var user = new User | ||
{ | ||
Email = userForRegisterDto.Email, | ||
FirstName = userForRegisterDto.FirstName, | ||
LastName = userForRegisterDto.LastName, | ||
PasswordHash = passwordHash, | ||
PasswordSalt = passwordSalt, | ||
Status = true | ||
}; | ||
_userService.Add(user); | ||
return new SuccessDataResult<User>(user, Messages.UserRegistered); | ||
} | ||
|
||
public IDataResult<User> Login(UserForLoginDto userForLoginDto) | ||
{ | ||
var userToCheck = _userService.GetByMail(userForLoginDto.Email); | ||
if (userToCheck == null) | ||
{ | ||
return new ErrorDataResult<User>(Messages.UserNotFound); | ||
} | ||
|
||
if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.Data.PasswordHash, userToCheck.Data.PasswordSalt)) | ||
{ | ||
return new ErrorDataResult<User>("Parola hatası"); | ||
} | ||
|
||
return new SuccessDataResult<User>(userToCheck.Data,"Giriş başarılı"); | ||
} | ||
|
||
public IResult UserExists(string email) | ||
{ | ||
if (_userService.GetByMail(email).Data != null) | ||
{ | ||
return new ErrorResult(Messages.UserAlreadyExists); | ||
} | ||
return new SuccessResult(); | ||
} | ||
|
||
public IDataResult<AccessToken> CreateAccessToken(User user) | ||
{ | ||
var claims = _userService.GetClaims(user); | ||
var accessToken = _tokenHelper.CreateToken(user, claims.Data); | ||
return new SuccessDataResult<AccessToken>(accessToken, "Token oluşturuldu"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.