public void GetAirlineByUserName()
        {
            countryDAO.Add(new Country("Israel"));

            airlineDAO.Add(new AirlineCompany("ELAL", "ELAL123", "PASSWORD", countryDAO.GetCountryByName("Israel").ID));
            Assert.AreEqual("ELAL", airlineDAO.GetAirlineByUsername("ELAL123").AirLineName);
            Assert.AreEqual("ELAL123", airlineDAO.GetAirlineByUsername("ELAL123").UserName);
            Assert.AreEqual("PASSWORD", airlineDAO.GetAirlineByUsername("ELAL123").Password);
            Assert.AreEqual(countryDAO.GetCountryByName("Israel").ID, airlineDAO.GetAirlineByUsername("ELAL123").CountryCode);
        }
예제 #2
0
        public bool TryAirlineLogin(string userName, string password, out LoginToken <AirlineCompany> token)
        {
            if (userName == "AlphaUser" || userName == "BetaUser")
            {
                _airlineDAO = new AirlineDAOMSSQL(true);
            }
            else
            {
                _airlineDAO = new AirlineDAOMSSQL();
            }
            AirlineCompany airlineCompany = _airlineDAO.GetAirlineByUsername(userName);

            if (airlineCompany != null)
            {
                if (airlineCompany.Password == password)
                {
                    token = new LoginToken <AirlineCompany>(airlineCompany);
                    return(true);
                }
                else
                {
                    throw new WrongPasswordException($"failed to login as [{userName}], you entered a wrong password! [{password}]");
                }
            }
            token = null;
            return(false);
        }
예제 #3
0
        public bool TryAirlineLogin(string userName, string password, out LoginToken <AirlineCompany> token)
        {
            AirlineCompany airlineCompany = _airlineDAO.GetAirlineByUsername(userName);

            if (airlineCompany != null)
            {
                if (airlineCompany.Password == password)
                {
                    token = new LoginToken <AirlineCompany>();
                    return(true);
                }
                else
                {
                    throw new WrongPasswordException();
                }
            }
            token = null;
            return(false);
        }
        public bool TryAirlineLogin(string userName, string password, out LoginToken <AirlineCompany> token)
        {
            _arilineDAO = new AirlineDAOMSSQL();
            AirlineCompany airline = _arilineDAO.GetAirlineByUsername(userName);

            if (airline != null)
            {
                if (airline.PASSWORD == password)
                {
                    token = new LoginToken <AirlineCompany>()
                    {
                        User = airline
                    };
                    return(true);
                }
                else
                {
                    throw new WrongPasswordException("Wrong password exception");
                }
            }
            token = null;
            return(false);
        }
        public bool TryLogin(string userName, string password, out ILoginToken token)
        {
            token = null;
            if (userName == "admin" && password == "9999")
            {
                logger.Info("Super administrator logged in.");
                token = new LoginToken <Administrator>();
                return(true);
            }
            else
            {
                try
                {
                    User user;
                    try
                    {
                        user = _userDAO.GetUserByUsername(userName);
                    }
                    catch (Exception e)
                    {
                        logger.Fatal("Wrong username. Please try again.", e);
                        return(false);
                    }

                    if (user.Password == password)
                    {
                        if (user.User_Role == 1)
                        {
                            Administrator admin = _adminDAO.GetById(user.Id);
                            admin.user = user;
                            token      = new LoginToken <Administrator>()
                            {
                                User = admin
                            };
                        }
                        if (user.User_Role == 2)
                        {
                            AirlineCompany airline = _airlineDAO.GetAirlineByUsername(user.Username); //TODO check if null
                            airline.user = user;
                            token        = new LoginToken <AirlineCompany>()
                            {
                                User = airline
                            };
                        }
                        if (user.User_Role == 3)
                        {
                            Customer customer = _customerDAO.GetCustomerByUsername(user.Username);
                            customer.user = user;
                            token         = new LoginToken <Customer>()
                            {
                                User = customer
                            };
                        }
                        logger.Info("Login was completed. Username and password are correct.");
                        return(true);
                    }
                    else
                    {
                        logger.Error("Login failed. Username or password are incorrect.");
                        throw new WrongCredentialsException("Username or password are incorrect. Please try again.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    logger.Error("Login failed.", e);
                    return(false);
                }
                //log4net
            }
        }