Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed bin and obj folders from repository #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Business/Abstract/IAuthService.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Core.Entities.Concrete;
using Core.Entities.Concrete;
using Core.Utilities.Results;
using Core.Utilities.Security.JWT;
using Entities.DTOs;
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);
public interface IAuthService
{
IDataResult<User> Register(UserForRegisterDto userForRegisterDto, string password);
IDataResult<User> Login(UserForLoginDto userForLoginDto);
IResult UserExists(string email);
IDataResult<AccessToken> CreateAccessToken(User user);

}
}
}
2 changes: 1 addition & 1 deletion Business/Abstract/IUserService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Core.Entities.Concrete;
using Core.Entities.Concrete;
using Core.Utilities.Results;

namespace Business.Abstract
Expand Down
68 changes: 34 additions & 34 deletions Business/BusinessAspect/Autofac/SecuredOperation.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
using Business.Constants;
using Castle.DynamicProxy;
using Core.Extensions;
using Core.Utilities.Interceptors;
using Core.Utilities.IoC;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace Business.BusinessAspect.Autofac
{
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);
}
}
}
using Business.Constants;
using Castle.DynamicProxy;
using Core.Extensions;
using Core.Utilities.Interceptors;
using Core.Utilities.IoC;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace Business.BusinessAspect.Autofac
{
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);
}
}
}
132 changes: 66 additions & 66 deletions Business/Concrete/AuthManager.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
using Business.Abstract;
using Business.Constants;
using Core.Entities.Concrete;
using Core.Utilities.Results;
using Core.Utilities.Security.Hashing;
using Core.Utilities.Security.JWT;
using Entities.DTOs;
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).Data;
if (userToCheck == null)
return new ErrorDataResult<User>(userToCheck, Messages.UserNotFound);
if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt))
return new ErrorDataResult<User>(userToCheck, Messages.PasswordError);
return new SuccessDataResult<User>(userToCheck, Messages.SuccessfulLogin);
}
public IResult UserExists(string email)
{
if (_userService.GetByMail(email) == new ErrorResult())
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, Messages.AccessTokenCreated);
}
}
}
using Business.Abstract;
using Business.Constants;
using Core.Entities.Concrete;
using Core.Utilities.Results;
using Core.Utilities.Security.Hashing;
using Core.Utilities.Security.JWT;
using Entities.DTOs;

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).Data;
if (userToCheck == null)
return new ErrorDataResult<User>(userToCheck, Messages.UserNotFound);

if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt))
return new ErrorDataResult<User>(userToCheck, Messages.PasswordError);

return new SuccessDataResult<User>(userToCheck, Messages.SuccessfulLogin);
}

public IResult UserExists(string email)
{
if (_userService.GetByMail(email) == new ErrorResult())
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, Messages.AccessTokenCreated);
}
}
}
156 changes: 78 additions & 78 deletions Business/Concrete/CarManager.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
using Business.Abstract;
using Business.BusinessAspect.Autofac;
using Business.Constants;
using Business.ValidationRules.FluentValidation;
using Core.Aspects.Autofac.Caching;
using Core.Aspects.Autofac.Transaction;
using Core.Aspects.Autofac.Validation;
using Core.Utilities.Results;
using DataAccess.Abstract;
using Entities.Concrete;
using Entities.DTOs;
namespace Business.Concrete
{
public class CarManager : ICarService
{
ICarDal _carDal;
public CarManager(ICarDal carDal)
{
_carDal = carDal;
}
[SecuredOperation("car.add")]
[ValidationAspect(typeof(CarValidator))]
[CacheRemoveAspect("ICarService.Add")]
public IResult Add(Car car)
{
_carDal.Add(car);
return new SuccessResult(Messages.Added);
}
public IResult Delete(Car car)
{
_carDal.Delete(car);
return new SuccessResult(Messages.Deleted);
}
[CacheAspect]
public IDataResult<List<Car>> GetAll()
{
return new SuccessDataResult<List<Car>>(_carDal.GetAll(), Messages.Listed);
}
[CacheAspect]
public IDataResult<Car> GetById(int id)
{
return new SuccessDataResult<Car>(_carDal.Get(x => x.Id == id), Messages.Listed);
}
public IDataResult<List<Car>> GetCarByBrandId(int id)
{
return new SuccessDataResult<List<Car>>(_carDal.GetCarByBrandId(id), Messages.Listed);
}
public IDataResult<List<Car>> GetCarByColorId(int id)
{
return new SuccessDataResult<List<Car>>(_carDal.GetCarByColorId(id), Messages.Listed);
}
public IDataResult<List<CarDetailDto>> GetCarDetails()
{
return new SuccessDataResult<List<CarDetailDto>>(_carDal.GetCarDetails(), Messages.Listed);
}
public IResult Update(Car car)
{
_carDal.Update(car);
return new SuccessResult(Messages.Updated);
}
[TransactionScopeAspect]
public IResult AddTransactionalTest(Car car)
{
throw new NotImplementedException();
}
}
}
using Business.Abstract;
using Business.BusinessAspect.Autofac;
using Business.Constants;
using Business.ValidationRules.FluentValidation;
using Core.Aspects.Autofac.Caching;
using Core.Aspects.Autofac.Transaction;
using Core.Aspects.Autofac.Validation;
using Core.Utilities.Results;
using DataAccess.Abstract;
using Entities.Concrete;
using Entities.DTOs;

namespace Business.Concrete
{
public class CarManager : ICarService
{
ICarDal _carDal;
public CarManager(ICarDal carDal)
{
_carDal = carDal;
}

[SecuredOperation("car.add")]
[ValidationAspect(typeof(CarValidator))]
[CacheRemoveAspect("ICarService.Add")]
public IResult Add(Car car)
{
_carDal.Add(car);
return new SuccessResult(Messages.Added);
}

public IResult Delete(Car car)
{
_carDal.Delete(car);
return new SuccessResult(Messages.Deleted);
}


[CacheAspect]
public IDataResult<List<Car>> GetAll()
{
return new SuccessDataResult<List<Car>>(_carDal.GetAll(), Messages.Listed);
}

[CacheAspect]
public IDataResult<Car> GetById(int id)
{
return new SuccessDataResult<Car>(_carDal.Get(x => x.Id == id), Messages.Listed);
}

public IDataResult<List<Car>> GetCarByBrandId(int id)
{
return new SuccessDataResult<List<Car>>(_carDal.GetCarByBrandId(id), Messages.Listed);
}

public IDataResult<List<Car>> GetCarByColorId(int id)
{
return new SuccessDataResult<List<Car>>(_carDal.GetCarByColorId(id), Messages.Listed);
}

public IDataResult<List<CarDetailDto>> GetCarDetails()
{
return new SuccessDataResult<List<CarDetailDto>>(_carDal.GetCarDetails(), Messages.Listed);
}

public IResult Update(Car car)
{
_carDal.Update(car);
return new SuccessResult(Messages.Updated);
}

[TransactionScopeAspect]
public IResult AddTransactionalTest(Car car)
{
throw new NotImplementedException();
}
}
}
Loading