Пример #1
0
        public async Task <(string, Guid)> Login(string email, string password)
        {
            var user = await userRepository.GetAsync(email, password);

            var token = JWTTokenGenerator.CreateToken(user);

            return(token, user.Id);
        }
Пример #2
0
        public async Task ReturnCar(Guid bookingId, string bearer)
        {
            var booking = await bookingRepository.GetAsync(bookingId);

            var claim = JWTTokenGenerator.GetClaim(bearer, emailClaim);

            bookingRepository.Remove(booking);
            await bookingRepository.SaveAsync();
        }
Пример #3
0
        public async Task <(string, Guid)> Register(string email, string password, string firstName, string lastName, DateTime birthday)
        {
            var newUser = User.Create(email, password, firstName, lastName, birthday);

            userRepository.Add(newUser);
            await userRepository.SaveAsync();

            var user = await userRepository.GetAsync(email, password);

            var token = JWTTokenGenerator.CreateToken(user);

            return(token, newUser.Id);
        }
Пример #4
0
        public async Task ReturnCar(Guid bookingId, string bearer)
        {
            var booking = await bookingRepository.GetAsync(bookingId);

            var claim = JWTTokenGenerator.GetClaim(bearer, emailClaim);

            if (booking.User.Email != claim)
            {
                throw new InvalidCredentialException("Not authorized!");
            }

            bookingRepository.Remove(booking);
            await bookingRepository.SaveAsync();
        }
Пример #5
0
        public async Task <Booking> BookCar(Guid carId, Guid userId, DateTime startDate, DateTime endDate, string bearer)
        {
            var car = await carRepository.GetAsync(carId);

            User user = await userOperationHandler.GetUser(userId);

            var claim = JWTTokenGenerator.GetClaim(bearer, emailClaim);

            var booking = Booking.Create(car, user, startDate, endDate);

            bookingRepository.Add(booking);
            await bookingRepository.SaveAsync();

            return(booking);
        }
Пример #6
0
        public async Task <(string, Guid)> Register(string email, string password, string firstName, string lastName, DateTime birthday)
        {
            if (userRepository.CheckIfUserAlreadyExists(email))
            {
                return("", new Guid());
            }
            var newUser = User.Create(email, password, firstName, lastName, birthday);

            userRepository.Add(newUser);

            var user  = userRepository.Get(email, password);
            var token = JWTTokenGenerator.CreateToken(user);

            return(token, user.Id);
        }
Пример #7
0
        public async Task <Booking> BookCar(Guid carId, Guid userId, DateTime startDate, DateTime endDate, string bearer)
        {
            var car = await carRepository.GetAsync(carId);

            var user = await userRepository.GetAsync(userId);

            var claim = JWTTokenGenerator.GetClaim(bearer, emailClaim);

            if (user.Email != claim)
            {
                throw new InvalidCredentialException("Not authorized!");
            }

            var booking = Booking.Create(car, user, startDate, endDate);

            bookingRepository.Add(booking);
            await bookingRepository.SaveAsync();

            return(booking);
        }