protected void SaveButton_Click(object sender, ImageClickEventArgs e) { //TODO FOR Tommorrow,when user click save I need to be able to update the client note. CffPrincipal cffPrincipal = Context.User as CffPrincipal; if (cffPrincipal != null && ViewState != null) { int modifiedBy = cffPrincipal.CffUser.EmployeeId; object orginalNote = ViewState[SelectedNote]; //TODO Interface ME! if (orginalNote.GetType() == typeof(CustomerNote)) { UpdateCustomerNote(orginalNote, modifiedBy, EncodedText(CommentEditTextBox.Text)); } else if (orginalNote.GetType() == typeof(PermanentCustomerNote)) { UpdatePermanentNote(orginalNote, modifiedBy, EncodedText(CommentEditTextBox.Text)); } else if (orginalNote.GetType() == typeof(ClientNote)) { UpdateClientNote(orginalNote, modifiedBy, EncodedText(CommentEditTextBox.Text)); } else if (orginalNote.GetType() == typeof(PermanentClientNote)) { UpdateClientPermanentNote(orginalNote, modifiedBy, EncodedText(CommentEditTextBox.Text)); } } }
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; } } }
protected void Page_Load(object sender, EventArgs e) { if (User.Identity.IsAuthenticated) { CffPrincipal cffPrincipal = Context.User as CffPrincipal; if (cffPrincipal != null) { String logonUrl = ResolveUrl("~/KeepSessionAlive.aspx"); if (cffPrincipal.IsInAdministratorRole) { metaRefresh.Attributes["http-equiv"] = "refresh"; //Refresh this page 60 seconds before session timeout, to reset the session timeout counter. //";url=KeepSessionAlive.aspx?q=" metaRefresh.Attributes["content"] = Convert.ToString((Session.Timeout * 60) - 60) + ";url=" + logonUrl + "?q=" + DateTime.Now.Ticks; } else if (cffPrincipal.IsInManagementRole) { metaRefresh.Attributes["http-equiv"] = "refresh"; metaRefresh.Attributes["content"] = Convert.ToString((Session.Timeout * 60) - 5) + ";url=" + logonUrl + "?q=" + DateTime.Now.Ticks; } else if (cffPrincipal.IsInClientRole) { metaRefresh.Attributes["http-equiv"] = "refresh"; metaRefresh.Attributes["content"] = Convert.ToString((Session.Timeout * 60) + 1) + ";url=" + logonUrl + "?q=" + DateTime.Now.Ticks; } } WindowStatusText = "Last refresh " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); } }
public SafeTraderPresenter(ISafeTraderView view, ICustomerRepository customerRepository, ISecurityManager securityManager, IRedirectionService redirectionService, ICffUserService userService, CffPrincipal principal) { ArgumentChecker.ThrowIfNull(view, "view"); ArgumentChecker.ThrowIfNull(customerRepository, "customerRepository"); this.view = view; this.customerRepository = customerRepository; this.securityManager = securityManager; this.redirectionService = redirectionService; this.userService = userService; this.principal = principal; }
// ReSharper disable InconsistentNaming /// <summary> /// Load Client and Customer into session when a new session is created /// </summary> /// public void Session_OnStart() // ReSharper restore InconsistentNaming { CffPrincipal cffPrincipal = Context.User as CffPrincipal; if (cffPrincipal != null && Session.IsNewSession) { Session.Timeout = 3600; CffUserService cffUserService = CffUserService.Create(); if (SessionWrapper.Instance.Get != null) { SessionWrapper.Instance.Get.ClientFromQueryString = cffUserService.LoadCffClientAssociatedWith(cffPrincipal.CffUser); SessionWrapper.Instance.Get.CustomerFromQueryString = (ICffCustomer)cffUserService.LoadCffCustomerAssociatedWith(cffPrincipal.CffUser); } } }
public bool ValidateClientCustomerSelection(int?clientId, int?customerId, CffPrincipal principal) { bool bRet = false; if (clientId == principal.CffUser.ClientId || principal.CffUser.ClientId == -1) { if (!clientId.HasValue) { // Use user's default ClientId if none supplied clientId = (int)principal.CffUser.ClientId; } if (customerId.HasValue && !customerRepository.CheckCustomerBelongsToClient(clientId.Value, customerId.Value)) { // Customer and Client should be associated with each other return(false); } CustomerUser customerUser = principal.CffUser as CustomerUser; if (customerUser != null) { // Customer can only select itself return(customerId.HasValue && customerUser.CustomerId == customerId.Value && clientId.Value == customerUser.ClientId); } if (principal.IsInClientRole) { // Client can only select itself return(clientId == principal.CffUser.ClientId); } bRet = true; } else { // if user is allowed for this client then proceed - new implementation to allow multiple login if (clientId.HasValue) { if (customerRepository.CheckClientBelongToUser(clientId.Value, principal.CffUser.UserId) == true) { bRet = true; } //} } //bRet = false; } return(bRet); }
protected virtual void Page_Init(object sender, EventArgs e) { CffPrincipal cffPrincipal = Context.User as CffPrincipal; if (cffPrincipal != null && Session.IsNewSession) { Cff.SaferTrader.Core.Services.CffUserService cffUserService = Cff.SaferTrader.Core.Services.CffUserService.Create(); if (SessionWrapper.Instance.Get == null && QueryString.ViewIDValue != null) { SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).ClientFromQueryString = cffUserService.LoadCffClientAssociatedWith(cffPrincipal.CffUser); } else if (SessionWrapper.Instance.Get != null) { SessionWrapper.Instance.Get.ClientFromQueryString = cffUserService.LoadCffClientAssociatedWith(cffPrincipal.CffUser); } } ((SafeTrader)Master).ScopeChanged += ScopeChanged; }
public static ISecurityManager Create(CffPrincipal cffPrincipal, Scope scope) { ISecurityManager securityManager; UserType userType = cffPrincipal.CffUser.UserType; if (userType == UserType.EmployeeAdministratorUser) { securityManager = new AdministratorSecurityManager(scope); } else if (userType == UserType.EmployeeManagementUser) { securityManager = new ManagementSecurityManager(scope); } else if (userType == UserType.EmployeeStaffUser) { securityManager = new StaffSecurityManager(scope); } else if (userType == UserType.ClientStaffUser) { securityManager = new ClientStaffSecurityManager(scope); } else if (userType == UserType.ClientManagementUser) { securityManager = new ClientSecurityManager(scope); } else if (userType == UserType.CustomerUser) { securityManager = new CustomerSecurityManager(); } else { throw new CffUserTypeNotFoundException("Not usertype found exception"); } return(securityManager); }
public static IReportManager Create(Scope scope, CffPrincipal cffPrincipal) { IReportManager reportManager; UserType userType = cffPrincipal.CffUser.UserType; if (userType == UserType.EmployeeAdministratorUser) { reportManager = new AdministratorReportManager(); } else if (userType == UserType.EmployeeManagementUser) { reportManager = new ManagementReportManager(); } else if (userType == UserType.EmployeeStaffUser) { reportManager = new StaffReportManager(scope); } else if (userType == UserType.ClientStaffUser) { reportManager = new ClientStaffReportManager(); } else if (userType == UserType.ClientManagementUser) { reportManager = new ClientManagementReportManager(); } else if (userType == UserType.CustomerUser) { reportManager = new CustomerReportManager(); } else { throw new CffUserTypeNotFoundException("Not usertype found exception"); } return(reportManager); }
protected void Page_Load(object sender, EventArgs e) { CffPrincipal cffPrincipal = Context.User as CffPrincipal; if (cffPrincipal != null) { CffUserService cffUserService = CffUserService.Create(); string returnUrl = Request.QueryString["ReturnUrl"]; bool rememberMe = Request.QueryString["RememberMe"] != null && Request.QueryString["RememberMe"].Equals(true.ToString()); string userName = cffPrincipal.Identity.Name; string viewID = Request.QueryString["ViewID"]; string criteria = Request.QueryString["Criteria"]; // If ReturnUrl is set, redirect to it // This logic shouldn't have to have been implemented according to MSDN but it doesn't seem to use ReturnUrl System.Web.Security.FormsAuthentication.SetAuthCookie(userName, rememberMe); if ((cffPrincipal.CffUser.EmployeeId == QueryString.UserId) && (!string.IsNullOrEmpty(returnUrl))) { if (!string.IsNullOrEmpty(viewID)) { string url1 = returnUrl; int idx1 = returnUrl.IndexOf("ViewID"); if (idx1 >= 0) { 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; } } returnUrl += "&ViewID=" + viewID; } if (!string.IsNullOrEmpty(criteria)) { string url1 = returnUrl; if (!string.IsNullOrEmpty(returnUrl)) { int idx1 = returnUrl.IndexOf("Criteria"); if (idx1 >= 0) { url1 = returnUrl.Substring(0, idx1 - 1); string url2 = returnUrl.Substring(returnUrl.IndexOf("Criteria")); idx1 = url2.IndexOf("&"); if (idx1 >= 0) { url2 = url2.Substring(idx1); returnUrl = url1 + url2; } else { returnUrl = url1; } } } returnUrl += "&Criteria=" + criteria.Replace("#", ""); } Response.Redirect(returnUrl); } else { returnUrl = "~/Dashboard.aspx"; if (cffUserService.LoadCffCustomerAssociatedWith(cffPrincipal.CffUser) != null) { returnUrl = returnUrl + "?Client=" + cffUserService.LoadCffClientAssociatedWith(cffPrincipal.CffUser).Id + "&Customer=" + cffUserService.LoadCffCustomerAssociatedWith(cffPrincipal.CffUser).Id + "&User="******"&ViewID=" + viewID; } else { returnUrl = returnUrl + "?Client=" + cffUserService.LoadCffClientAssociatedWith(cffPrincipal.CffUser).Id + "&User="******"&ViewID=" + viewID; } if (QueryString.Criteria != null) { returnUrl += "&Criteria=" + QueryString.CriteriaValue.ToString().Replace("#", ""); } Response.Redirect(returnUrl); } //} } }
protected void Page_Load(object sender, EventArgs e) { CffPrincipal cPrincipal = (CffPrincipal)Context.User; // verify if this user agreed on the CFF Agreement if (SessionWrapper.Instance.Get == null) { if ((cPrincipal.CffUser.UserType == UserType.EmployeeStaffUser) || (cPrincipal.CffUser.UserType == UserType.EmployeeManagementUser) || (cPrincipal.CffUser.UserType == UserType.EmployeeAdministratorUser)) { string viewID = SaferTrader.Core.Common.StringEnum.GenerateUniqueKey(12); SessionWrapper.Instance.GetSession(viewID).ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(Convert.ToInt32(QueryString.ClientId)); SessionWrapper.Instance.GetSession(viewID).UserIdentity = 1; string rUrl = ResolveClientUrl(Context.Request.Url.AbsolutePath + "?Client=" + QueryString.ClientId.ToString() + "&User="******"&ViewID=" + viewID); string tUrl = this.Context.Request.RawUrl; this.Response.Redirect(rUrl); } else { //redirect to logon page - allow only one window tab instance to open, unless it came from the reports tab etc string rUrl = ResolveClientUrl("~/Logon.aspx"); string tUrl = this.Context.Request.RawUrl; this.Response.Redirect(rUrl); } } if ((QueryString.ClientId != cPrincipal.CffUser.ClientId) && (cPrincipal.IsInClientRole || cPrincipal.IsInCustomerRole)) { SessionWrapper.Instance.Get.ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId((int)cPrincipal.CffUser.ClientId); } if (Page.IsPostBack) { int ClientId = (this.Client != null) ? this.Client.Id : 0; if (ClientId == 0) { if (QueryString.ClientId == null) { ClientId = Convert.ToInt32(cPrincipal.CffUser.ClientId.ToString()); } else { ClientId = (int)QueryString.ClientId; } } if (SessionWrapper.Instance.Get != null) { if ((SessionWrapper.Instance.Get.ClientFromQueryString.Id != ClientId) && (!string.IsNullOrEmpty(SessionWrapper.Instance.Get.AccountsIDList))) { SessionWrapper.Instance.Get.ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(ClientId); } else if (SessionWrapper.Instance.Get.ClientFromQueryString.Id != ClientId) { if (cPrincipal.CffUser.UserType == UserType.EmployeeAdministratorUser || cPrincipal.CffUser.UserType == UserType.EmployeeManagementUser || cPrincipal.CffUser.UserType == UserType.EmployeeStaffUser) { SessionWrapper.Instance.Get.ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(ClientId); } else if (cPrincipal.IsInClientRole || cPrincipal.IsInCustomerRole) { SessionWrapper.Instance.Get.ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(Convert.ToInt32(cPrincipal.CffUser.ClientId.ToString())); } } } else if (!string.IsNullOrEmpty(QueryString.ViewIDValue)) { if ((SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).ClientFromQueryString.Id != ClientId) && (!string.IsNullOrEmpty(SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).AccountsIDList))) { SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(ClientId); } else if (SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).ClientFromQueryString.Id != ClientId) { if (cPrincipal.CffUser.UserType == UserType.EmployeeAdministratorUser || cPrincipal.CffUser.UserType == UserType.EmployeeManagementUser || cPrincipal.CffUser.UserType == UserType.EmployeeStaffUser) { SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(ClientId); } else if (cPrincipal.IsInClientRole || cPrincipal.IsInCustomerRole) { SessionWrapper.Instance.GetSession(QueryString.ViewIDValue).ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(Convert.ToInt32(cPrincipal.CffUser.ClientId.ToString())); } } } } IScopeService scopeService = new ScopeService(this, SecurityManagerFactory.Create(Context.User as CffPrincipal, SessionWrapper.Instance.Get.Scope), RepositoryFactory.CreateClientRepository(), RepositoryFactory.CreateCustomerRepository()); presenter = new DashboardPresenter(this, scopeService); MembershipUser membershipUser = Membership.GetUser(User.Identity.Name); if (presenter.IsReadAgreement((Guid)membershipUser.ProviderUserKey) == false) { RedirectTo("AgreementPage.aspx"); } else { if (!IsPostBack) { presenter.InitialiseView(); } content.InnerHtml = presenter.DashboardMainContent(); } }
public void ProcessRequest(HttpContext context) { string criteria = context.Request.Params["Criteria"]; CustomerSearchPresenter presenter = CustomerSearchPresenter.Create(this); CffPrincipal cffPrincipal = HttpContext.Current.User as CffPrincipal; CffUserService cffUserService = CffUserService.Create(); if (cffPrincipal != null && (cffPrincipal.IsInCustomerRole || cffPrincipal.IsInClientRole)) { if (SessionWrapper.Instance.Get.IsMultipleAccounts && QueryString.ClientId != -1) { string rawURl = context.Request.RawUrl; rawURl = rawURl.Substring(rawURl.IndexOf("Client")); rawURl = rawURl.Substring(rawURl.IndexOf("=") + 1); int eidx = rawURl.IndexOf("&"); if (eidx > 0) { rawURl = rawURl.Substring(0, eidx); } int clientId = int.Parse(rawURl); presenter.ShowMatchedNames(context.Request.Params["q"], clientId, System.Convert.ToInt32((criteria == "") ? "0" : criteria)); } else { presenter.ShowMatchedNames(context.Request.Params["q"], (cffUserService.LoadCffClientAssociatedWith(cffPrincipal.CffUser)).Id, System.Convert.ToInt32((criteria == "")?"0":criteria)); } } else { if (cffPrincipal.IsInClientRole || cffPrincipal.IsInCustomerRole) { presenter.ShowMatchedNames(context.Request.Params["q"], SessionWrapper.Instance.Get.ClientFromQueryString.Id, System.Convert.ToInt32((criteria == "")?"0":criteria)); } else { int clientID = -1; if (context.Request.Params["Client"] != null) { string contextPar = context.Request.Params["Client"].Replace("+", " "); if (contextPar.Contains("All Clients")) { clientID = -1; } else { clientID = System.Convert.ToInt32(context.Request.Params["Client"].ToString()); } string viewID = QueryString.ViewIDValue; int? SessionClientID = null; if (!string.IsNullOrEmpty(viewID)) { SessionClientID = (SessionWrapper.Instance.GetSession(QueryString.ViewIDValue)).ClientFromQueryString.Id; } else if (SessionWrapper.Instance.Get != null) { SessionClientID = SessionWrapper.Instance.Get.ClientFromQueryString.Id; } if (SessionClientID != null && (viewID != null)) { if (SessionClientID != clientID && (cffPrincipal.CffUser.UserType == UserType.EmployeeAdministratorUser || cffPrincipal.CffUser.UserType == UserType.EmployeeManagementUser || cffPrincipal.CffUser.UserType == UserType.EmployeeStaffUser)) { //if not in client role, we must be able to reset session wrapper's querystring details from here var nameValues = HttpUtility.ParseQueryString(context.Request.QueryString.ToString()); nameValues.Set("Client", SessionClientID.ToString()); string url = context.Request.Url.AbsolutePath; string updatedQueryString = "?" + nameValues.ToString(); //context.Response.Redirect(url + updatedQueryString); SessionWrapper.Instance.GetSession(viewID).ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(System.Convert.ToInt32(SessionClientID)); SessionWrapper.Instance.GetSession(viewID).IsDeselectingCustomer = false; if (SessionWrapper.Instance.GetSession(viewID).CurrentUserID != (System.Web.HttpContext.Current.User as CffPrincipal).CffUser.UserId.ToString()) { SessionWrapper.Instance.GetSession(viewID).CurrentUserID = (System.Web.HttpContext.Current.User as CffPrincipal).CffUser.UserId.ToString(); } if (SessionWrapper.Instance.Get != null) { SessionWrapper.Instance.Get.ClientFromQueryString = RepositoryFactory.CreateClientRepository().GetCffClientByClientId(System.Convert.ToInt32(SessionClientID));; SessionWrapper.Instance.Get.IsDeselectingCustomer = false; SessionWrapper.Instance.Get.CurrentUserID = (System.Web.HttpContext.Current.User as CffPrincipal).CffUser.UserId.ToString(); } clientID = (int)SessionClientID; } } } //if (context.Request.Params["Client"] == clientID.ToString()) //{ presenter.ShowMatchedNames(context.Request.Params["q"], clientID, System.Convert.ToInt32((string.IsNullOrEmpty(criteria)) ? "0" : criteria)); //} } } }