public ApartmentProfileModel Authenticate(string username, string password)
        {
            var userApartment = _apartmentRepository.GetAll().FirstOrDefault(x =>
                                                                             x.Name == username);

            if (userApartment == null)
            {
                throw new ApartmentException(null, null,
                                             "User-apartment with that name does not exists");
            }

            var hashedPasword = HashPassword(password);

            if (userApartment.Password != hashedPasword)
            {
                throw new ApartmentException(userApartment.Id, userApartment.Password,
                                             "User-apartment password does not match with user-apartment");
            }

            // TODO: create aut token
            var token = GenerateJwtToken(userApartment);

            var userApartmentModel = new ApartmentProfileModel
            {
                Id    = userApartment.Id,
                Name  = userApartment.Name,
                Area  = userApartment.Area,
                Rooms = userApartment.Rooms,
                Price = userApartment.Price,
                Token = token
            };

            return(userApartmentModel);
        }
Пример #2
0
        public ApartmentProfileModel Authenticate(string username, string password)
        {
            var userApartment = _apartmentRepository.GetAll().FirstOrDefault(x =>
                                                                             x.Name == username);

            if (userApartment == null)
            {
                throw new ApartmentException(null, null,
                                             "User-apartment with that name does not exists");
            }

            var hashedPasword = HashPassword(password);

            if (userApartment.Password != hashedPasword)
            {
                throw new ApartmentException(userApartment.Id, userApartment.Password,
                                             "User-apartment password does not match with user-apartment");
            }

            // TODO: create aut token
            var token = GenerateJwtToken(userApartment);

            var userApartmentModel = new ApartmentProfileModel
            {
                Id                  = userApartment.Id,
                Name                = userApartment.Name,
                Area                = userApartment.Area,
                Rooms               = userApartment.Rooms,
                Price               = userApartment.Price,
                InternetAccess      = userApartment.InternetAccess,
                TvAccess            = userApartment.TvAccess,
                BathEquipped        = userApartment.BathEquipped,
                BedroomsEquipped    = userApartment.BedroomsEquipped,
                KitchenEqupped      = userApartment.KitchenEqupped,
                LivingRoomEqupped   = userApartment.LivingRoomEqupped,
                Smoking             = userApartment.Smoking,
                TvOperator          = userApartment.TvOperator,
                TwoSepratedBedRooms = userApartment.TwoSepratedBedRooms,
                TypeOfHEating       = userApartment.TypeOfHEating,

                Token = token
            };

            return(userApartmentModel);
        }