Beispiel #1
0
        public void getTokenAndGetFacade(out LoginToken <Admin> token, out LoggedInAdministratorFacade facadeAdmin)
        {
            ILoginService loginService = new LoginService();

            loginService.TryAdminLogin(FlightCenterConfig.ADMIN_NAME, FlightCenterConfig.ADMIN_PASSWORD, out token);
            facadeAdmin = FlightsCenterSystem.GetInstance().GetFacade <Admin>(token) as LoggedInAdministratorFacade;
        }
Beispiel #2
0
        private void AuthenticateAndGetTokenAndGetFacade(out LoginToken <Admin> tokenAdmin,
                                                         out LoggedInAdministratorFacade facadeAdmin)
        {
            ILoginService loginService = new LoginService();

            loginService.TryAdminLogin("admin", "9999", out tokenAdmin);
            facadeAdmin = FlightsCenterSystem.GetInstance().GetFacade(tokenAdmin) as LoggedInAdministratorFacade;
        }
        public async Task <ActionResult <List <Flight> > > GetAllAirlineCompanies()
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade = f as LoggedInCustomerFacade;
            var result = await Task.Run(() => facade.GetAllAirlineCompanies());

            return(StatusCode(200, result));
        }
        public async Task <ActionResult <List <Flight> > > GetFlightsByLandingDate([FromBody] DateTime date)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade = f as LoggedInCustomerFacade;
            var result = await Task.Run(() => facade.GetFlightsByLandingDate(date));

            return(StatusCode(200, result));
        }
        public async Task <ActionResult <List <Flight> > > GetFlightsByOriginCountry(int country_id)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade = f as LoggedInCustomerFacade;
            var result = await Task.Run(() => facade.GetFlightsByOriginCountry(country_id));

            return(StatusCode(200, result));
        }
Beispiel #6
0
        public async Task <ActionResult> GetToken([FromBody] UserDetailsDTO userDetails)

        {
            // 1) try login, with userDetails
            //ILoginService loginService = new LoginService();
            //  loginService.TryAdminLogin(userDetails.Name, userDetails.Password, out LoginToken<Admin> tokenAdmin);
            //facadeAdmin = FlightsCenterSystem.GetInstance().GetFacade(tokenAdmin) as LoggedInAdministratorFacade;


            try
            {
                await Task.Run(() => FlightsCenterSystem.GetInstance().Login(userDetails.Name, userDetails.Password));
            }
            catch (IllegalFlightParameter ex)
            {
                return(Unauthorized("login failed"));
            }



            // 2) create key
            // security key
            string securityKey =
                "this_is_our_supper_long_security_key_for_token_validation_project_2018_09_07$smesk.in";

            // symmetric security key
            var symmetricSecurityKey = new
                                       SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey));

            // signing credentials
            var signingCredentials = new
                                     SigningCredentials(symmetricSecurityKey,
                                                        SecurityAlgorithms.HmacSha256Signature);

            // 3) create claim for specific role
            // add claims
            var claims = new List <Claim>();

            // create claim according to login -- Airline or Admin or ...
            claims.Add(new Claim(ClaimTypes.Role, "Administrator"));
            claims.Add(new Claim(ClaimTypes.Role, "AirlineCompany"));
            claims.Add(new Claim("username", "userDetails.Name"));
            //   claims.Add(new Claim("Id", "110"));

            // 4) create token
            var token = new JwtSecurityToken(
                issuer: "smesk.in",                // change to something better
                audience: "readers",               // change to something better
                expires: DateTime.Now.AddHours(1), // should be configurable
                signingCredentials: signingCredentials,
                claims: claims);

            // 5) return token
            return(Ok(new JwtSecurityTokenHandler().WriteToken(token)));
        }
Beispiel #7
0
        public void GetFlightsByLandingDateTest()
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            TestData.DeleteAllData();
            flightDAOPGSQL.Add(CreateFlightForTest());

            var f_list = facade.GetFlightsByLandingDate(TestData.CreateFlight_LandingTime);

            Assert.AreNotEqual(f_list, null);
            Assert.AreEqual(f_list.Count, 1);
        }
Beispiel #8
0
        public async Task <ActionResult <Customer> > CreateFlight([FromBody] Flight flight)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade        = f as LoggedInAirlineFacade;
            token_airline = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_airline.Password && _.Username == token_airline.Name);

            token_airline.User = new AirlineDAOPGSQL().GetAll().FirstOrDefault(_ => _.UserId == u.Id);
            await Task.Run(() => facade.CreateFlight(token_airline, flight));

            return(StatusCode(200, flight));
        }
Beispiel #9
0
        public async Task <ActionResult> CancleTicket(int flight_id)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade        = f as LoggedInAirlineFacade;
            token_airline = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_airline.Password && _.Username == token_airline.Name);

            token_airline.User = new AirlineDAOPGSQL().GetAll().FirstOrDefault(_ => _.UserId == u.Id);
            await Task.Run(() => facade.CancelFlight(token_airline, new FlightDAOPGSQL().Get(flight_id)));

            return(Ok());
        }
Beispiel #10
0
        public async Task <ActionResult> MofidyAirlineDetails([FromBody] AirlineCompany airline)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade        = f as LoggedInAirlineFacade;
            token_airline = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_airline.Password && _.Username == token_airline.Name);

            token_airline.User = new AirlineDAOPGSQL().GetAll().FirstOrDefault(_ => _.UserId == u.Id);
            await Task.Run(() => facade.MofidyAirlineDetails(token_airline, airline));

            return(StatusCode(200));
        }
Beispiel #11
0
        public void GetAllAirlineCompaniesTest()
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            TestData.DeleteAllData();

            airlineCompanyDAOPGSQL.Add(CreateAirlineCompanyForTest());

            var ac_list = facade.GetAllAirlineCompanies();

            Assert.AreNotEqual(ac_list, null);
            Assert.AreEqual(ac_list.Count, 1);
        }
Beispiel #12
0
        public void GetFlightsByOriginCountryTest()
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            TestData.DeleteAllData();
            flightDAOPGSQL.Add(CreateFlightForTest());

            var flights_list = flightDAOPGSQL.GetAll();
            var f_list       = facade.GetFlightsByOriginCountry(flights_list[0].Origin_Country_Id);

            Assert.AreNotEqual(f_list, null);
            Assert.AreEqual(f_list.Count, 1);
        }
Beispiel #13
0
        public async Task <ActionResult <List <AirlineAuth> > > GetRequests()
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade      = f as LoggedInAdministratorFacade;
            token_admin = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_admin.Password && _.Username == token_admin.Name);

            token_admin.User = new AdministratorDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id);
            var result = await Task.Run(() => facade.GetRequests(token_admin));

            return(StatusCode(200, result));
        }
        public async Task <ActionResult <List <Flight> > > GetAllMyFlights()
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade         = f as LoggedInCustomerFacade;
            token_customer = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_customer.Password && _.Username == token_customer.Name);

            token_customer.User = new CustomerDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id);
            var result = await Task.Run(() => facade.GetAllMyFlights(token_customer));

            return(StatusCode(200, result));
        }
        public async Task <ActionResult <List <Ticket> > > GetMyTicketByFlight(int flight_id)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade         = f as LoggedInCustomerFacade;
            token_customer = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_customer.Password && _.Username == token_customer.Name);

            token_customer.User = new CustomerDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id);
            var result = await Task.Run(() => new TicketDAOPGSQL().GetAll().FirstOrDefault(ticket => ticket.FlightID == flight_id && ticket.CustimerID == token_customer.User.Id));

            return(StatusCode(200, result));
        }
        public async Task <ActionResult> CancleTicket(int ticket_id)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade         = f as LoggedInCustomerFacade;
            token_customer = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_customer.Password && _.Username == token_customer.Name);

            token_customer.User = new CustomerDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id);
            await Task.Run(() => facade.CancelTicket(token_customer, new TicketDAOPGSQL().Get(ticket_id)));

            return(Ok());
        }
Beispiel #17
0
        private void AuthenticateAndGetFacade(out AnonymousUserFacade facade)
        {
            // after we learned authentication
            // 1. validate token
            // 2. retrieve LoginToken<Customer>
            // 3. get Customer facade

            // before we learn authentication
            // 1. perform login  -- use real user-name + pwd
            // 2. get the token + facade

            facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;
        }
Beispiel #18
0
        public async Task <ActionResult <Customer> > RemoveAdmin([FromBody] Administrator admin)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade      = f as LoggedInAdministratorFacade;
            token_admin = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_admin.Password && _.Username == token_admin.Name);

            token_admin.User = new AdministratorDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id);
            await Task.Run(() => facade.RemoveAdmin(token_admin, admin));

            return(StatusCode(200, admin));
        }
        public void getTokenAndGetFacade(out LoginToken <Admin> tokenAdmin, out LoggedInAdministratorFacade facadeAdmin,
                                         out LoginToken <Customer> tokenCustomer, out LoggedInCustomerFacade fasadeCustomer)
        {
            ILoginService loginService = new LoginService();

            loginService.TryAdminLogin(FlightCenterConfig.ADMIN_NAME, FlightCenterConfig.ADMIN_PASSWORD, out tokenAdmin);
            facadeAdmin = FlightsCenterSystem.GetInstance().GetFacade(tokenAdmin) as LoggedInAdministratorFacade;

            facadeAdmin.CreateNewCustomer(tokenAdmin, CreateCustomerForTest());
            tokenCustomer = new LoginToken <Customer>()
            {
                User = facadeAdmin.GetAllCustomers(tokenAdmin)[0]
            };
            fasadeCustomer = FlightsCenterSystem.GetInstance().GetFacade(tokenCustomer) as LoggedInCustomerFacade;
        }
Beispiel #20
0
        public void RemoveAirlineTest()
        {
            TestData.DeleteAllData();
            getTokenAndGetFacade(out LoginToken <Admin> token, out LoggedInAdministratorFacade facadeAdmin);
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            airlineCompanyDAOPGSQL.Add(CreateAirlineCompanyForTest());
            var list = airlineCompanyDAOPGSQL.GetAll();

            facadeAdmin.RemoveAirline(token, list[0]);
            list = facade.GetAllAirlineCompanies();

            Assert.AreNotEqual(1, list.Count);
            Assert.AreEqual(0, list.Count);
        }
Beispiel #21
0
        public async Task <ActionResult <Customer> > UpdateMyDetails([FromBody] AllAirlineDetails details)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade        = f as LoggedInAirlineFacade;
            token_airline = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_airline.Password && _.Username == token_airline.Name);

            token_airline.User = new AirlineDAOPGSQL().GetAll().FirstOrDefault(_ => _.UserId == u.Id);
            await Task.Run(() => new UserDAOPGSQL().Update(new User(u.Id, details.Username, details.Password, details.Email, 2)));

            await Task.Run(() => new AirlineDAOPGSQL().Update(new AirlineCompany(token_airline.User.Id, details.Name, details.CountryId, details.UserId)));

            return(StatusCode(200, details));
        }
        public async Task <ActionResult <Customer> > UpdateMyDetails([FromBody] AllCustomerDetails details)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade         = f as LoggedInCustomerFacade;
            token_customer = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_customer.Password && _.Username == token_customer.Name);

            token_customer.User = new CustomerDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id);
            await Task.Run(() => new UserDAOPGSQL().Update(new User(u.Id, details.Username, details.Password, details.Email, 3)));

            await Task.Run(() => new CustomerDAOPGSQL().Update(new Customer(token_customer.User.Id, details.FisrtName,
                                                                            details.LastName, details.Adress, details.PhoneNumber, details.CreditCardNumber, u.Id)));

            return(StatusCode(200, details));
        }
        public async Task <ActionResult> PurchaseTicket(int flight_id)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade         = f as LoggedInCustomerFacade;
            token_customer = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_customer.Password && _.Username == token_customer.Name);

            token_customer.User = new CustomerDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id);
            var result = await Task.Run(() => facade.PurchaseTicket(token_customer, new FlightDAOPGSQL().Get(flight_id)));

            if (result is null)
            {
                return(StatusCode(204, $"{{there are no tickets left for the flight \"{flight_id}\"}}"));
            }
            return(Ok(result));
        }
        private void AuthenticateAndGetTokenAndGetFacade(out LoginToken <Customer> tokenCustomer,
                                                         out LoggedInCustomerFacade facadeCustomer)
        {
            // after we learned authentication
            // 1. validate token
            // 2. retrieve LoginToken<Customer>
            // 3. get Customer facade

            // before we learn authentication
            // 1. perform login  -- use real user-name + pwd
            // 2. get the token + facade

            ILoginService loginService = new LoginService();

            loginService.TryCustomerLogin("customer89", "NJKlGs", out tokenCustomer);
            facadeCustomer = FlightsCenterSystem.GetInstance().GetFacade(tokenCustomer) as LoggedInCustomerFacade;
        }
Beispiel #25
0
        public void UpdateAirlineDetailsTest()
        {
            TestData.DeleteAllData();
            getTokenAndGetFacade(out LoginToken <Admin> token, out LoggedInAdministratorFacade facadeAdmin);
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            facadeAdmin.CreateNewAirline(token, CreateAirlineCompanyForTest());
            var            list = airlineCompanyDAOPGSQL.GetAll();
            AirlineCompany ac   = list[0];

            ac.Name = TestData.UpdateAirlineCompany_Name;

            facadeAdmin.UpdateAirlineDetails(token, ac);
            var ac_new = airlineCompanyDAOPGSQL.Get((int)ac.Id);

            Assert.AreEqual(TestData.UpdateAirlineCompany_Name, ac_new.Name);
        }
Beispiel #26
0
        internal void AuthenticateAndGetTokenAndGetFacade(out LoginToken <AirlineCompany> tokenAirline,
                                                          out LoggedsInAirlineFacade fasadeAirline)
        {
            // after we learned authentication
            // 1. validate token
            // 2. retrieve LoginToken<Customer>
            // 3. get Customer facade
            tokenAirline = GetLoginToken();

            // before we learn authentication
            // 1. perform login  -- use real user-name + pwd
            // 2. get the token + facade

            //ILoginService loginService = new LoginService();
            // loginService.TryAirlineLogin("airline99", "LiGpmH", out tokenAirline);
            fasadeAirline = FlightsCenterSystem.GetInstance().GetFacade(tokenAirline) as LoggedsInAirlineFacade;
        }
        private void AuthenticateAndGetTokenAndGetFacade(out LoginToken <Admin> tokenAdmin,
                                                         out LoggedInAdministratorFacade facadeAdmin)
        {
            // after we learned authentication
            // 1. validate token
            // 2. retrieve LoginToken<Customer>
            // 3. get Customer facade

            tokenAdmin = GetLoginToken();

            // before we learn authentication
            // 1. perform login  -- use real user-name + pwd
            // 2. get the token + facade

            //ILoginService loginService = new LoginService();
            //loginService.TryAdminLogin("manager87", "lF9A7v", out tokenAdmin);
            facadeAdmin = FlightsCenterSystem.GetInstance().GetFacade(tokenAdmin) as LoggedInAdministratorFacade;
        }
Beispiel #28
0
        public void getTokenAndGetFacade(out LoginToken <Admin> tokenAdmin, out LoggedInAdministratorFacade facadeAdmin,
                                         out LoginToken <AirlineCompany> tokenAirline, out LoggedsInAirlineFacade fasadeAirline)
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            ILoginService loginService = new LoginService();

            loginService.TryAdminLogin(FlightCenterConfig.ADMIN_NAME, FlightCenterConfig.ADMIN_PASSWORD, out tokenAdmin);
            facadeAdmin = FlightsCenterSystem.GetInstance().GetFacade(tokenAdmin) as LoggedInAdministratorFacade;

            facadeAdmin.CreateNewAirline(tokenAdmin, CreateAirlineCompanyForTest());

            AirlineCompany airline = airlineCompanyDAOPGSQL.GetAirlineByUserame(TestData.CreateAirlineUser_Username);

            tokenAirline = new LoginToken <AirlineCompany>()
            {
                User = airline
            };
            fasadeAirline = FlightsCenterSystem.GetInstance().GetFacade(tokenAirline) as LoggedsInAirlineFacade;
        }
Beispiel #29
0
        public void GetFlightByIdTest()
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            TestData.DeleteAllData();

            flightDAOPGSQL.Add(CreateFlightForTest());

            var flights_list = flightDAOPGSQL.GetAll();

            Flight f = facade.GetFlightById((int)flights_list[0].Id);

            Assert.AreNotEqual(f, null);
            Assert.AreEqual(TestData.CreateAirlineCompany_Id, f.Airline_Company_Id);
            Assert.AreEqual(TestData.CreateFlight_OriginCountryId, f.Origin_Country_Id);
            Assert.AreEqual(TestData.CreateFlight_DestinationCountryId, f.Destination_Country_Id);
            Assert.AreEqual(TestData.CreateFlight_DepartureTime.AddHours(10), f.Departure_Time);
            Assert.AreEqual(TestData.CreateFlight_LandingTime.AddHours(10), f.Landing_Time);
            Assert.AreEqual(TestData.CreateFlight_TicketsRemaining, f.Tickets_Remaining);
        }
        public async Task <ActionResult <Customer> > GetMyDetails()
        {
            AllCustomerDetails details = new AllCustomerDetails();
            User     myUser            = new User();
            Customer myCustomer        = new Customer();

            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade         = f as LoggedInCustomerFacade;
            token_customer = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_customer.Password && _.Username == token_customer.Name);

            token_customer.User = new CustomerDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id);
            await Task.Run(() => myUser = new UserDAOPGSQL().Get(u.Id));

            await Task.Run(() => myCustomer = new CustomerDAOPGSQL().Get(token_customer.User.Id));

            details = new AllCustomerDetails(myUser.Username, myUser.Password, myCustomer.First_name,
                                             myCustomer.Last_name, myUser.Email, myCustomer.Phone, myCustomer.Adress, myCustomer.Credit_card_no);
            return(StatusCode(200, details));
        }