Ejemplo n.º 1
0
        public bool TryLogin(string userName, string password, out LoginToken <IUser> token, out FacadeBase facadeBase)
        {
            Users user = new Users();

            token      = null;
            facadeBase = null;

            if (userName is null)
            {
                throw new ArgumentNullException($"username cannot be: {userName}");
            }
            if (password is null)
            {
                throw new ArgumentNullException($"password cannot be: {password}");
            }

            //in case it's admin "level 4"
            if (userName == "admin" && password == "9999")
            {
                if (_adminDAO.GetUserByUsername(userName).Equals(_userDAO.GetUserByUsername(userName)))
                {
                    if (user.Password == password)
                    {
                        token      = new LoginToken <Administrators>();
                        facadeBase = new LoggedInAdministratorFacade();
                        return(true);
                    }
                }
            }
            else
            {
                if (UserAuthentication.IsUserAuthorized(userName, password))
                {
                    if (user.UserRole == 1)
                    {
                        Administrators admin = _adminDAO.Get(user.ID);
                        token = new LoginToken <Administrators>()
                        {
                            User = admin
                        };
                        facadeBase = new LoggedInAdministratorFacade();
                        return(true);
                    }
                    else if (user.UserRole == 2)
                    {
                        Administrators admin = _adminDAO.Get(user.ID);
                        token = new LoginToken <Administrators>()
                        {
                            User = admin
                        };
                        facadeBase = new LoggedInAdministratorFacade();
                        return(true);
                    }
                    else if (user.UserRole == 3)
                    {
                        Administrators admin = _adminDAO.Get(user.ID);
                        token = new LoginToken <Administrators>()
                        {
                            User = admin
                        };
                        facadeBase = new LoggedInAdministratorFacade();
                        return(true);
                    }
                    else if (user.ID.Equals(_customerDAO.Get(user.ID)))
                    {
                        Customer customer = _customerDAO.Get(user.ID);
                        token = new LoginToken <Customer>()
                        {
                            User = customer
                        };
                        facadeBase = new LoggedInCustomerFacade();
                        return(true);
                    }
                    else
                    {
                        AirlineCompany airline = _airlineDAO.Get(user.ID);
                        token = new LoginToken <AirlineCompany>()
                        {
                            User = airline
                        };
                        facadeBase = new LoggedInAirlineFacade();
                        return(true);
                    }
                }
            }
            my_logger.Info($"Login Faild\n: username: {userName} password: {password},  Not excited!");
            return(false);
        }