Ejemplo n.º 1
0
        protected void Application_AuthorizeRequest(object sender, EventArgs e)
        {
            IPrincipal user = Context.User;

            if (user != null && user.Identity.IsAuthenticated && user is RolePrincipal)
            {
                try
                {
                    if (Request.Url.ToString().Contains("myob"))
                    {
                        return;
                    }

                    MembershipUser membershipUser = Membership.GetUser(user.Identity.Name);
                    CffUserService cffUserService = CffUserService.Create();
                    ICffUser       cffUser        = cffUserService.LoadCffUser(new Guid(membershipUser.ProviderUserKey.ToString()));
                    if (cffUser != null)
                    {
                        CffPrincipal cffPrincipal = new CffPrincipal(user, cffUser);
                        Context.User = cffPrincipal;
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }
        }
        public ICffClient LoadCffClientAssociatedWith(ICffUser user)
        {
            ArgumentChecker.ThrowIfNull(user, "user");

            ICffClient client;

            if (user.UserType == UserType.EmployeeAdministratorUser ||
                user.UserType == UserType.EmployeeManagementUser ||
                user.UserType == UserType.EmployeeStaffUser)
            {
                client = AllClients.Create();
            }
            else if (user.UserType == UserType.ClientStaffUser)
            {
                client = clientRepository.GetCffClientByClientId((int)((ClientStaffUser)user).ClientId);
            }
            else if (user.UserType == UserType.ClientManagementUser)
            {
                client = clientRepository.GetCffClientByClientId((int)((ClientManagementUser)user).ClientId);
            }
            else if (user.UserType == UserType.CustomerUser)
            {
                client = clientRepository.GetCffClientByCustomerId((int)((CustomerUser)user).CustomerId);
            }

            else
            {
                throw new CffUserNotFoundException("No cff user found");
            }
            return(client);
        }
        public CffPrincipal(IPrincipal rolePrincipal, ICffUser cffUser)
        {
            ArgumentChecker.ThrowIfNull(rolePrincipal, "rolePrincipal");
            ArgumentChecker.ThrowIfNull(cffUser, "cffUser");

            this.rolePrincipal = rolePrincipal;
            this.cffUser       = cffUser;
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((ParamRefUserQueryString != "" && ParamRefIdQueryString != "") && (ParamRefUserQueryString != null && ParamRefIdQueryString != null))
            {
                presenter = LogOnPresenter.Create((IAccountToAccess)this, 0);
                Int32 n = presenter.ValidateUserAccess(ParamRefUserQueryString, ParamRefIdQueryString);
                switch (n)
                {
                case 1:     //pass
                    CffLoginAccount account        = presenter.GetSpecialAccessAccount(ParamRefUserQueryString, ParamRefIdQueryString);
                    MembershipUser  membershipUser = Membership.GetUser(new Guid(ParamRefIdQueryString));
                    if (Membership.ValidateUser(account.Username, account.Password))
                    {
                        FormsAuthentication.SetAuthCookie(account.Username, false);
                        string viewID = Request.QueryString["ViewID"];
                        if (string.IsNullOrEmpty(viewID))
                        {
                            viewID = SaferTrader.Core.Common.StringEnum.GenerateUniqueKey(12);
                        }

                        Cff.SaferTrader.Core.Repositories.ICffUserRepository repository = Cff.SaferTrader.Core.Repositories.RepositoryFactory.CreateCffUserRepository();
                        ICffUser loggedOnUser = repository.LoadCffUser(new Guid(ParamRefIdQueryString));

                        SessionWrapper.Instance.GetSession(viewID);            //Generate a new instance of this session
                        SessionWrapper.Instance.GetSession(viewID).IsStartsWithChecked   = true;
                        SessionWrapper.Instance.GetSession(viewID).MultiClientSelected   = false;
                        SessionWrapper.Instance.GetSession(viewID).IsMultipleAccounts    = true;
                        SessionWrapper.Instance.GetSession(viewID).UserIdentity          = GetSessionWrapperIdentity(loggedOnUser.UserType.Id);
                        SessionWrapper.Instance.GetSession(viewID).CurrentUserID         = loggedOnUser.UserId.ToString();
                        SessionWrapper.Instance.GetSession(viewID).IsDeselectingCustomer = false;
                        SessionWrapper.Instance.GetSession(viewID).ClientFromQueryString = Cff.SaferTrader.Core.Repositories.RepositoryFactory.CreateClientRepository().GetCffClientByClientId(Convert.ToInt32(loggedOnUser.ClientId.ToString()));

                        string returnUrl  = Request.QueryString["ReturnUrl"];
                        bool   rememberMe = Request.QueryString["RememberMe"] != null && Request.QueryString["RememberMe"].Equals(true.ToString());
                        string url        = string.Format("{0}?RememberMe={1}&ViewID={2}&Criteria=0&ClientID={3}&User={4}&ReturnUrl=",
                                                          "LogOnRedirection.aspx", rememberMe, viewID, loggedOnUser.ClientId, loggedOnUser.EmployeeId); //LogOnRedirection.aspx

                        Response.Redirect(url);
                    }
                    else
                    {
                        Response.Redirect("LogOn.aspx");
                    }
                    break;

                case 0:     // blocked
                    break;

                default:     // failed
                    Response.Redirect("LogOn.aspx");
                    break;
                }
            }
            else
            {
                Response.Redirect("LogOn.aspx");
            }
        }
        public CffCustomer LoadCffCustomerAssociatedWith(ICffUser user)
        {
            ArgumentChecker.ThrowIfNull(user, "user");

            CffCustomer  customer     = null;
            CustomerUser customerUser = user as CustomerUser;

            if (customerUser != null)
            {
                customer = customerRepository.GetCffCustomerByCustomerId((int)customerUser.CustomerId);
            }
            return(customer);
        }
        public void SelectDefaultAssociationAndRedirectToDashboard(ICffUser user)
        {
            string path = string.Format("~/{0}", Config.DashboardPage);

            if (user.UserType == UserType.CustomerUser)
            {
                CustomerUser customerUser = (CustomerUser)user;
                path = string.Format("{0}?Client={1}&Customer={2}&ViewID={3}", path, customerUser.ClientId, customerUser.CustomerId, QueryString.ViewIDValue);
            }
            else
            {
                //QueryString.ClientId
                path = string.Format("{0}?Client={1}&ViewID={2}", path, user.ClientId, QueryString.ViewIDValue);
            }
            view.RedirectTo(path);
        }
Ejemplo n.º 7
0
        public void LogOnUser(Guid userId, string returnUrl, bool rememberMe)
        {
            bool   bAddViewID = false;
            string url        = "LogOnRedirection.aspx";

            ICffUserRepository repository   = RepositoryFactory.CreateCffUserRepository();
            ICffUser           loggedOnUser = repository.LoadCffUser(userId);
            short currentUserIdentity       = GetSessionWrapperIdentity(loggedOnUser.UserType.Id);

            string             viewID = Common.StringEnum.GenerateUniqueKey(12);
            SessionWrapperBase sBase  = new SessionWrapperBase();

            if (SessionWrapper.Instance.Get != null && (loggedOnUser.UserType == UserType.ClientManagementUser ||
                                                        loggedOnUser.UserType == UserType.ClientStaffUser ||
                                                        loggedOnUser.UserType == UserType.CustomerUser))
            {
                if (SessionWrapper.Instance.Get.ClientFromQueryString != null)
                {
                    if (SessionWrapper.Instance.Get.ClientFromQueryString.Id <= 0)
                    {
                        SessionWrapper.Instance.ClearSession(SessionWrapper.Instance.Get.SessionID);
                    }
                }
            }

            if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString["ViewID"]))
            { //clear any remaining session keys here and generate new viewID
                if (SessionWrapper.Instance.Get != null)
                {
                    try
                    {
                        sBase = SessionWrapper.Instance.Get.Clone();
                    }
                    catch { }
                    SessionWrapper.Instance.Clear();
                    SessionWrapper.Instance.GetSession(viewID);
                    if ((currentUserIdentity == sBase.UserIdentity) && (sBase.CurrentUserID == userId.ToString()))
                    {     //get last data
                        SessionWrapper.Instance.GetSession(viewID).ClientFromQueryString   = sBase.ClientFromQueryString;
                        SessionWrapper.Instance.GetSession(viewID).CustomerFromQueryString = sBase.CustomerFromQueryString;
                        SessionWrapper.Instance.GetSession(viewID).IsMultipleAccounts      = sBase.IsMultipleAccounts;
                        SessionWrapper.Instance.GetSession(viewID).IsStartsWithChecked     = sBase.IsStartsWithChecked;
                    }

                    if ((SessionWrapper.Instance.GetSession(viewID).UserIdentity == (short)SessionWrapper.UserIdentity.Client) &&
                        (sBase.ClientFromQueryString.Id == loggedOnUser.ClientId))
                    {
                        SessionWrapper.Instance.GetSession(viewID).AccountsIDList = sBase.AccountsIDList;
                    }

                    SessionWrapper.Instance.GetSession(viewID).MultiClientSelected = false;
                    SessionWrapper.Instance.GetSession(viewID).EmptyWindowHit      = 0;
                    SessionWrapper.Instance.GetSession(viewID).AccountsIDList      = "";
                    SessionWrapper.Instance.GetSession(viewID).UserIdentity        = currentUserIdentity;
                    SessionWrapper.Instance.GetSession(viewID).CurrentUserID       = userId.ToString();
                }
            }
            else
            {
                bAddViewID = true;
            }


            if (!string.IsNullOrEmpty(returnUrl))
            {
                if (SessionWrapper.Instance.Get == null)
                {
                    SessionWrapper.Instance.GetSession(viewID);
                    SessionWrapper.Instance.GetSession(viewID).IsMultipleAccounts  = false;
                    SessionWrapper.Instance.GetSession(viewID).IsStartsWithChecked = true;
                    SessionWrapper.Instance.GetSession(viewID).MultiClientSelected = false;
                    SessionWrapper.Instance.GetSession(viewID).EmptyWindowHit      = 0;
                    SessionWrapper.Instance.GetSession(viewID).AccountsIDList      = "";
                    SessionWrapper.Instance.GetSession(viewID).UserIdentity        = currentUserIdentity;
                    SessionWrapper.Instance.GetSession(viewID).CurrentUserID       = userId.ToString();
                    if (loggedOnUser.ClientId == -1 && (returnUrl.Contains("Client")))
                    {      //retain to whatever scope was previously stored in the returnurl
                        string strRawURL = returnUrl;
                        int    cidx      = strRawURL.IndexOf("Client=") + 7;
                        int    eidx      = strRawURL.IndexOf('&', cidx);
                        if (eidx > 0)
                        {
                            strRawURL = strRawURL.Substring(cidx, (eidx - cidx));
                            int clientID = string.IsNullOrEmpty(strRawURL) ? 0 : Convert.ToInt32(strRawURL);
                            if (clientID > 0)
                            {
                                SessionWrapper.Instance.GetSession(viewID).ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(clientID);
                            }
                            else
                            {
                                SessionWrapper.Instance.GetSession(viewID).ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(Convert.ToInt32(loggedOnUser.ClientId.ToString()));
                            }
                        }
                    }
                    else
                    {
                        SessionWrapper.Instance.GetSession(viewID).ClientFromQueryString =
                            RepositoryFactory.CreateClientRepository().GetCffClientByClientId(Convert.ToInt32(loggedOnUser.ClientId.ToString()));
                    }

                    returnUrl  = cleanUpClientIDAndCustomerID(returnUrl);
                    returnUrl += "&ClientID=" + loggedOnUser.ClientId.ToString();
                    returnUrl += "&CustomerID=0";
                }

                string url1 = returnUrl;
                if (bAddViewID)
                {
                    url = string.Format("{0}?ReturnUrl={1}&RememberMe={2}&ViewID={3}", url, returnUrl, rememberMe, viewID);
                    if (url1.IndexOf("Criteria") < 0)
                    {
                        url += "&Criteria=0";
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        int idx1 = returnUrl.IndexOf("ViewID");
                        if (idx1 >= 0)
                        {     //remove ViewId from URL
                            url1 = returnUrl.Substring(0, idx1 - 1);
                            string url2 = returnUrl.Substring(returnUrl.IndexOf("ViewID"));
                            idx1 = url2.IndexOf("&");
                            if (idx1 >= 0)
                            {
                                url2      = url2.Substring(idx1);
                                returnUrl = url1 + url2;
                            }
                            else
                            {
                                returnUrl = url1;
                            }
                        }
                    }
                    url = string.Format("{0}?ReturnUrl={1}&RememberMe={2}&ViewID={3}", url, returnUrl, rememberMe, viewID);
                }
            }
            else
            {
                if (SessionWrapper.Instance.Get == null)
                {
                    SessionWrapper.Instance.GetSession(viewID);
                    SessionWrapper.Instance.GetSession(viewID).IsMultipleAccounts    = false;
                    SessionWrapper.Instance.GetSession(viewID).IsStartsWithChecked   = true;
                    SessionWrapper.Instance.GetSession(viewID).MultiClientSelected   = false;
                    SessionWrapper.Instance.GetSession(viewID).EmptyWindowHit        = 0;
                    SessionWrapper.Instance.GetSession(viewID).AccountsIDList        = "";
                    SessionWrapper.Instance.GetSession(viewID).UserIdentity          = currentUserIdentity;
                    SessionWrapper.Instance.GetSession(viewID).CurrentUserID         = userId.ToString();
                    SessionWrapper.Instance.GetSession(viewID).ClientFromQueryString =
                        RepositoryFactory.CreateClientRepository().GetCffClientByClientId(Convert.ToInt32(loggedOnUser.ClientId.ToString()));
                }
                url = string.Format("{0}?RememberMe={1}&ViewID={2}&Criteria=0", url, rememberMe, viewID);
            }

            if (repository.AcceptAgreement(userId, null) == false)
            {
                view.RedirectToAgreement();
            }
            view.Redirect(url);
        }
        public ICffUser LoadCffUser(Guid userId)
        {
            ArgumentChecker.ThrowIfGuidEmpty(userId, "userId");
            ICffUser user = null;

            using (SqlConnection connection = CreateConnection())
            {
                using (SqlDataReader dataReader = SqlHelper.ExecuteReader(connection,
                                                                          CommandType.StoredProcedure,
                                                                          "CffUserView_LoadUserByUserId",
                                                                          CreateUserKeyParameter(userId)))
                {
                    CleverReader cleverReader = new CleverReader(dataReader);

                    if (!cleverReader.IsNull && cleverReader.Read())
                    {
                        UserType userType       = UserType.Parse(cleverReader.ToInteger("UserTypeId"));
                        Guid     returnedUserId = cleverReader.ToGuid("UserId");
                        string   userName       = cleverReader.ToString("UserName");
                        int      employeeId     = cleverReader.ToInteger("EmployeeId");
                        string   displayName    = cleverReader.ToString("DisplayName");

                        int clientId = cleverReader.FromBigInteger("ClientId");
                        if (userType == UserType.EmployeeStaffUser)
                        {
                            user = new EmployeeStaffUser(returnedUserId, userName, employeeId, displayName, clientId);
                        }
                        else if (userType == UserType.EmployeeManagementUser)
                        {
                            user = new EmployeeManagementUser(returnedUserId, userName, employeeId, displayName, clientId);
                        }
                        else if (userType == UserType.EmployeeAdministratorUser)
                        {
                            user = new EmployeeAdministratorUser(returnedUserId, userName, employeeId, displayName, clientId);
                        }
                        else if (userType == UserType.ClientStaffUser)
                        {
                            user = new ClientStaffUser(returnedUserId,
                                                       userName,
                                                       employeeId,
                                                       displayName,
                                                       clientId,
                                                       cleverReader.FromBigInteger("ClientNum"),
                                                       cleverReader.ToString("ClientName"));
                        }
                        else if (userType == UserType.ClientManagementUser)
                        {
                            user = new ClientManagementUser(returnedUserId,
                                                            userName,
                                                            employeeId,
                                                            displayName,
                                                            clientId,
                                                            cleverReader.FromBigInteger("ClientNum"),
                                                            cleverReader.ToString("ClientName"));
                        }
                        else if (userType == UserType.CustomerUser)
                        {
                            user = new CustomerUser(returnedUserId,
                                                    userName,
                                                    employeeId,
                                                    displayName,
                                                    cleverReader.FromBigInteger("CustomerId"),
                                                    cleverReader.FromBigInteger("CustNum"),
                                                    cleverReader.ToString("Customer"),
                                                    clientId);
                        }
                    }
                }
            }
            return(user);
        }