コード例 #1
0
        public Authenticate Authenticate(string password, string userId)
        {
            FactoryFacade factory = new FactoryFacade();

            domainModel = factory.DomainModelFactory.CreateDomainModel(typeof(Authenticate));
            domainModel.Fill(HashHelper.Authenticate(userId, password));
            domainService = factory.DomainServiceFactory.CreateDomainService(typeof(AccountsDomainService));
            domainModel   = domainService.Query(domainModel, DomainModelEnum.AUTHENTICATE);
            DomainModel.Models.Authenticate authenticate = (DomainModel.Models.Authenticate)domainModel;
            if (authenticate.ResponseMessage != "User id is required" && authenticate.ResponseMessage != "Password is required" && authenticate.ResponseMessage != "Invalid domain model" && authenticate.ResponseMessage != "Please check login credentials and then try again.")
            {
                UserData userData = new UserData(userId, authenticate.Name);
                TicketHelper.CreateAuthCookie(authenticate.Name, userData.GetUserData(), false);
            }
            return(authenticate);
        }
コード例 #2
0
        public IHttpActionResult Authenticate(string userId, string password)
        {
            if (userId == null || password == null)
            {
                return(Ok("Please check login credentials and then try again."));
            }
            FactoryFacade factory = new FactoryFacade();

            domainModel = factory.DomainModelFactory.CreateDomainModel(typeof(Authenticate));
            domainModel.Fill(HashHelper.Authenticate(userId, password));
            domainService = factory.DomainServiceFactory.CreateDomainService(typeof(AccountsDomainService));
            domainModel   = domainService.Query(domainModel, CareHub.Factory.Enumerations.DomainModelEnum.AUTHENTICATE);
            DomainModel.Models.Authenticate authenticate = (DomainModel.Models.Authenticate)domainModel;
            if (authenticate.ResponseMessage != "User id is required" && authenticate.ResponseMessage != "Password is required" && authenticate.ResponseMessage != "Invalid domain model" && authenticate.ResponseMessage != "Please check login credentials and then try again.")
            {
                UserData userData = new UserData(userId, authenticate.ProviderId.ToString(), "");
                TicketHelper.CreateAuthCookie(userData.UserId, userData.GetProviderUserData(), false);
            }
            return(Ok(authenticate.ResponseMessage));
        }
コード例 #3
0
        public override AbstractDomainModel Query(AbstractDomainModel domainModel, DomainModelEnum domainModelType)
        {
            try
            {
                if (domainModel != null)
                {
                    switch (domainModelType)
                    {
                    case DomainModelEnum.AUTHENTICATE:
                        authenticate = (DomainModel.Models.Authenticate)domainModel;
                        if (authenticate.Email == null || authenticate.Email.Length <= 0)
                        {
                            authenticate.ResponseMessage = "Email is required";
                        }
                        else if (authenticate.Password == null || authenticate.Password.Length <= 0)
                        {
                            authenticate.ResponseMessage = "Password is required";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork   = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            authenticate = (DomainModel.Models.Authenticate)unitOfWork.Get(authenticate, OperationTypeEnum.AUTHENTICATE);
                            authenticate.ResponseMessage = "Valid";
                        }
                        break;

                    case DomainModelEnum.GET_SECURITY_QUESTION:
                        forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
                        if (forgotPassword.UserId == null || forgotPassword.UserId.Length <= 0)
                        {
                            forgotPassword.ResponseMessage = "User id is required";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork     = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            forgotPassword = (DomainModel.Models.ForgotPassword)unitOfWork.Get(forgotPassword, OperationTypeEnum.GET_SECURITY_QUESTION);
                            forgotPassword.ResponseMessage = "Valid";
                        }
                        break;

                    case DomainModelEnum.CHECK_SECURITY_QUESTION_ANSWER:
                        forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
                        if (forgotPassword.SecurityQuestionAnswer == null || forgotPassword.SecurityQuestionAnswer.Length <= 0)
                        {
                            forgotPassword.ResponseMessage = "Please answer the given question";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork     = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            forgotPassword = (DomainModel.Models.ForgotPassword)unitOfWork.Get(forgotPassword, OperationTypeEnum.CHECK_SECURITY_QUESTION_ANSWER);
                        }
                        break;

                    case DomainModelEnum.CHECK_VERIFICATION_CODE:
                        forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
                        if (forgotPassword.VerificationCode == 0)
                        {
                            forgotPassword.ResponseMessage = "Please enter the given verification code";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork     = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            forgotPassword = (DomainModel.Models.ForgotPassword)unitOfWork.Get(forgotPassword, OperationTypeEnum.CHECK_VERIFICATION_CODE);
                        }
                        break;

                    case DomainModelEnum.RESET_PASSWORD:
                        forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
                        if (forgotPassword.NewPassword == null || forgotPassword.NewPassword.Length <= 0)
                        {
                            forgotPassword.ResponseMessage = "Please enter new password";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork     = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            forgotPassword = (DomainModel.Models.ForgotPassword)unitOfWork.Get(forgotPassword, OperationTypeEnum.RESET_PASSWORD);
                        }
                        break;

                    case DomainModelEnum.CHECK_USER_ID:
                        authenticate = (DomainModel.Models.Authenticate)domainModel;
                        if (authenticate.Email == null || authenticate.Email.Length <= 0)
                        {
                            authenticate.ResponseMessage = "Please enter valid email";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork   = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            authenticate = (DomainModel.Models.Authenticate)unitOfWork.Get(authenticate, OperationTypeEnum.CHECK_USER_ID);
                        }
                        break;

                    case DomainModelEnum.GET_USER_INFO:
                        userProfile = (DomainModel.Models.UserProfile)domainModel;
                        if (userProfile.UserId == null || userProfile.UserId.Length <= 0)
                        {
                            userProfile.ResponseMessage = "Please enter valid email";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork  = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            userProfile = (DomainModel.Models.UserProfile)unitOfWork.Get(userProfile, OperationTypeEnum.GET_USER_INFO);
                        }
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (domainModelType)
                    {
                    case DomainModelEnum.AUTHENTICATE:
                        authenticate.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.GET_SECURITY_QUESTION:
                        forgotPassword.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.CHECK_SECURITY_QUESTION_ANSWER:
                        forgotPassword.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.CHECK_VERIFICATION_CODE:
                        forgotPassword.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.RESET_PASSWORD:
                        forgotPassword.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.CHECK_USER_ID:
                        authenticate.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.GET_USER_INFO:
                        userProfile.ResponseMessage = "Invalid domain model";
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                switch (domainModelType)
                {
                case DomainModelEnum.AUTHENTICATE:
                    authenticate.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.GET_SECURITY_QUESTION:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.CHECK_SECURITY_QUESTION_ANSWER:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.CHECK_VERIFICATION_CODE:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.RESET_PASSWORD:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.CHECK_USER_ID:
                    authenticate.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.GET_USER_INFO:
                    userProfile.ResponseMessage = ex.Message;
                    break;

                default:
                    break;
                }
            }
            switch (domainModelType)
            {
            case DomainModelEnum.AUTHENTICATE:
                return(authenticate);

            case DomainModelEnum.GET_SECURITY_QUESTION:
                return(forgotPassword);

            case DomainModelEnum.CHECK_SECURITY_QUESTION_ANSWER:
                return(forgotPassword);

            case DomainModelEnum.CHECK_VERIFICATION_CODE:
                return(forgotPassword);

            case DomainModelEnum.RESET_PASSWORD:
                return(forgotPassword);

            case DomainModelEnum.CHECK_USER_ID:
                return(authenticate);

            case DomainModelEnum.GET_USER_INFO:
                return(userProfile);

            default:
                break;
            }
            return(null);
        }
コード例 #4
0
        public override AbstractDomainModel Query(AbstractDomainModel domainModel, CareHub.Factory.Enumerations.DomainModelEnum domainModelType)
        {
            DomainModel.Models.Authenticate authenticate = (DomainModel.Models.Authenticate)domainModel;
            try
            {
                if (domainModel != null)
                {
                    switch (domainModelType)
                    {
                    case CareHub.Factory.Enumerations.DomainModelEnum.AUTHENTICATE:
                        if (authenticate.UserId == null || authenticate.UserId.Length <= 0)
                        {
                            authenticate.ResponseMessage = "User id is required";
                        }
                        else if (authenticate.Password == null || authenticate.Password.Length <= 0)
                        {
                            authenticate.ResponseMessage = "Password is required";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork   = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(CareHub.UnitOfWork.AuthenticateUOW));
                            authenticate = (DomainModel.Models.Authenticate)unitOfWork.Get(authenticate);
                            authenticate.ResponseMessage = "Valid";
                        }
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (domainModelType)
                    {
                    case CareHub.Factory.Enumerations.DomainModelEnum.AUTHENTICATE:
                        authenticate.ResponseMessage = "Invalid domain model";
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                switch (domainModelType)
                {
                case CareHub.Factory.Enumerations.DomainModelEnum.AUTHENTICATE:
                    authenticate.ResponseMessage = ex.Message;
                    break;

                default:
                    break;
                }
            }
            switch (domainModelType)
            {
            case CareHub.Factory.Enumerations.DomainModelEnum.AUTHENTICATE:
                return(authenticate);

            default:
                break;
            }
            return(null);
        }