Example #1
0
        public UserType TryLogin(string userName, string password, out ILogin token, out FacadeBase facade)
        {
            token  = null;
            facade = new AnonymousUserFacade();

            // Default Admin.
            if (userName.ToUpper() == FlyingCenterConfig.ADMIN_NAME.ToUpper())
            {
                if (password.ToUpper() == FlyingCenterConfig.ADMIN_PASSWORD.ToUpper())
                {
                    token = new LoginToken <Administrator>
                    {
                        User = new Administrator
                               (
                            0, //Admin Number
                            0, //Id
                            FlyingCenterConfig.ADMIN_NAME,
                            FlyingCenterConfig.ADMIN_PASSWORD
                               )
                    };
                    facade = new LoggedInAdministratorFacade();
                    return(UserType.Administrator);
                }
                else
                {
                    throw new WrongPasswordException("Sorry, But Your Password Isn't Match To Your User Name.");
                }
            }

            // DAO Users.
            User user = _userDAO.GetUserByUserName(userName);

            if (user != null)
            {
                if (user.User_Name == userName)
                {
                    if (password.ToUpper() == user.Password.ToUpper())
                    {
                        switch (user.MyType)
                        {
                        case UserType.Administrator:
                        {
                            Administrator admin = _administratorDAO.GetById(user.Id);
                            token = new LoginToken <Administrator>
                            {
                                User = new Administrator
                                       (
                                    admin.Admin_Number,
                                    user.Id,
                                    user.User_Name,
                                    user.Password
                                       )
                            };
                            facade = new LoggedInAdministratorFacade();
                            return(UserType.Administrator);
                        }

                        case UserType.Airline:
                        {
                            AirlineCompany airline = _airlineDAO.GetById(user.Id);
                            token = new LoginToken <AirlineCompany>
                            {
                                User = new AirlineCompany
                                       (
                                    airline.Airline_Number,
                                    user.Id,
                                    user.User_Name,
                                    user.Password,
                                    airline.Airline_Name,
                                    airline.Country_Code
                                       )
                            };
                            facade = new LoggedInAirlineFacade();
                            return(UserType.Airline);
                        }

                        case UserType.Customer:
                        {
                            Customer customer = _customerDAO.GetById(user.Id);
                            token = new LoginToken <Customer>
                            {
                                User = new Customer
                                       (
                                    customer.Customer_Number,
                                    user.Id,
                                    user.User_Name,
                                    user.Password,
                                    customer.First_Name,
                                    customer.Last_Name,
                                    customer.Address,
                                    customer.Phone_No,
                                    customer.Credit_Card_Number
                                       )
                            };
                            facade = new LoggedInCustomerFacade();
                            return(UserType.Customer);
                        }

                        default:
                        {
                            return(UserType.Anonymous);
                        }
                        }
                    }
                    else
                    {
                        throw new WrongPasswordException("Sorry, But Your Password Is Not Match To Your User Name.");
                    }
                }
                else
                {
                    throw new UserNotExistException($"Sorry, But {userName} Does Not Exist.");
                }
            }
            return(UserType.Anonymous);
        }
Example #2
0
        public bool TryLogin(User userDetails, out ILogin token, out FacadeBase facade)
        {
            token  = null;
            facade = new AnonymousUserFacade();
            // Default Admin.
            if (userDetails.Type == UserTypes.Administrator && userDetails.UserName.ToUpper() == FlyingCenterConfig.ADMIN_NAME.ToUpper())
            {
                if (userDetails.Password.ToUpper() == FlyingCenterConfig.ADMIN_PASSWORD.ToUpper())
                {
                    token = new LoginToken <IUser>
                    {
                        User = new Administrator
                               (
                            0, //Admin Number
                            0, //UserId
                            FlyingCenterConfig.ADMIN_NAME,
                            FlyingCenterConfig.ADMIN_PASSWORD
                               )
                    };
                    facade = new LoggedInAdministratorFacade();
                    return(true);
                }
                else
                {
                    throw new WrongPasswordException("Sorry, But Your Password Isn't Match To Your User Name.");
                }
            }

            // DAO Users.
            User user = _userDAO.GetUserByUserName(userDetails.UserName);

            if (user != null)
            {
                if (user.UserName.ToUpper() == userDetails.UserName.ToUpper())
                {
                    if (userDetails.Password.ToUpper() == user.Password.ToUpper())
                    {
                        switch (userDetails.Type)
                        {
                        case UserTypes.Administrator:
                        {
                            Administrator admin = _administratorDAO.GetById(user.Id);
                            token = new LoginToken <IUser>
                            {
                                User = new Administrator
                                       (
                                    admin.AdminNumber,
                                    user.Id,
                                    user.UserName,
                                    user.Password
                                       )
                            };
                            facade = new LoggedInAdministratorFacade();
                            return(true);
                        }

                        case UserTypes.Airline:
                        {
                            AirlineCompany airline = _airlineDAO.GetById(user.Id);
                            token = new LoginToken <IUser>
                            {
                                User = new AirlineCompany
                                       (
                                    airline.AirlineNumber,
                                    user.Id,
                                    user.UserName,
                                    user.Password,
                                    airline.AirlineName,
                                    airline.CountryCode
                                       )
                            };
                            facade = new LoggedInAirlineFacade();
                            return(true);
                        }

                        case UserTypes.Customer:
                        {
                            Customer customer = _customerDAO.GetById(user.Id);
                            token = new LoginToken <IUser>
                            {
                                User = new Customer
                                       (
                                    customer.CustomerNumber,
                                    user.Id,
                                    user.UserName,
                                    user.Password,
                                    customer.FirstName,
                                    customer.LastName,
                                    customer.Address,
                                    customer.PhoneNo,
                                    customer.CreditCardNumber
                                       )
                            };
                            return(true);
                        }

                        default:
                            return(false);
                        }
                    }
                    else
                    {
                        throw new WrongPasswordException("Sorry, But Your Password Doe's Not Match To Your User Name.");
                    }
                }
                else
                {
                    throw new UserNotExistException($"Sorry, But {userDetails.UserName} Does Not Exist.");
                }
            }
            return(false);
        }