Пример #1
0
        protected void ButtonSubmit_Click(object sender, System.EventArgs e)
        {
            string email    = TextboxEmail.Text.Trim();
            string password = TextboxPassword.Text.Trim();

            var service = new Service();

            if (service.Login(email, password))
            {
                string redirectUrl = FormsAuthentication.GetRedirectUrl(email, false);
                if (redirectUrl != null && redirectUrl.IndexOf("admin") >= 0)
                {
                    FormsAuthentication.RedirectFromLoginPage(email, false);
                }
                else
                {
                    Response.Redirect(UrlMaker.ToAdmin());
                }
            }
            else
            {
                if (Tries >= 5)
                {
                    Response.Redirect(UrlMaker.ToDefault());
                }
                else
                {
                    Tries += 1;
                    this.LiteralError.Text = "Invalid Username or Password. Please try again.";
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Adds item to shopping cart and redirect to shopping cart page.
        /// </summary>
        protected void ButtonAddToCart_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            // Retrieve product via Product Facade.
            var repository = new ProductRepository();

            ActionServiceReference.Product product = repository.GetProduct(ProductId);

            // Get product details and add information to cart.
            int    productId = product.ProductId;
            string name      = product.ProductName;
            double unitPrice = product.UnitPrice;

            int quantity;

            if (!int.TryParse(TextBoxQuantity.Text.Trim(), out quantity))
            {
                quantity = 1;
            }

            var cartRepository = new CartRepository();

            cartRepository.AddItem(productId, name, quantity, unitPrice);

            // Show shopping cart to user.
            Response.Redirect(UrlMaker.ToCart());
        }
Пример #3
0
        public ActionResult Product(int productId, string message = null)
        {
            ViewData["BreadCrumbs"] = new List <BreadCrumb> {
                new BreadCrumb {
                    Url = UrlMaker.ToDefault(), Title = "home"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToShopping(), Title = "shopping"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToProducts(), Title = "product catalog"
                },
                new BreadCrumb {
                    Title = "product details"
                }
            };

            ViewData["ProductImage"] = imageService + "GetProductImage/" + productId;

            if (message != null)
            {
                ModelState.AddModelError("Message", message);
            }

            return(View(_productRepository.Get(productId).ToModel()));
        }
Пример #4
0
        protected void ButtonSubmit_Click(object sender, System.EventArgs e)
        {
            string username = TextboxUserName.Text.Trim();
            string password = TextboxPassword.Text.Trim();

            var repository = new AuthRepository();

            if (repository.Login(username, password))
            {
                FormsAuthentication.SetAuthCookie(username, false);

                string redirectUrl = FormsAuthentication.GetRedirectUrl(username, false);
                if (redirectUrl != null && redirectUrl.IndexOf("admin") >= 0)
                {
                    FormsAuthentication.RedirectFromLoginPage(username, false);
                }
                else
                {
                    Response.Redirect(UrlMaker.ToAdmin());
                }
            }
            else
            {
                if (Tries >= 2)
                {
                    Response.Redirect(UrlMaker.ToDefault());
                }
                else
                {
                    Tries += 1;
                    this.LiteralError.Text = "Invalid Username or Password. Please try again.";
                }
            }
        }
Пример #5
0
        public ActionResult OrderDetails(int customerId, int orderId)
        {
            var order = _orderRepository.Get(orderId);

            ViewData["OrderDate"]   = "Order Date: " + string.Format("{0:MM/dd/yyyy}", order.OrderDate);
            ViewData["BreadCrumbs"] = new List <BreadCrumb> {
                new BreadCrumb {
                    Url = UrlMaker.ToDefault(), Title = "home"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToAdmin(), Title = "administration"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToOrders(), Title = "orders"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToCustomerOrders(customerId), Title = "customer orders"
                },
                new BreadCrumb {
                    Title = "line items"
                }
            };

            return(View(order.OrderDetails.ToList().ToModel()));
        }
Пример #6
0
        public ActionResult CustomerOrders(int customerId)
        {
            ViewData["CustomerId"] = customerId;

            var customer = _customerRepository.GetCustomerWithOrders(
                new Criterion("CustomerId", Operator.Equals, customerId));

            ViewData["Company"]     = customer.Company;
            ViewData["BreadCrumbs"] = new List <BreadCrumb> {
                new BreadCrumb {
                    Url = UrlMaker.ToDefault(), Title = "home"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToAdmin(), Title = "administration"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToOrders(), Title = "orders"
                },
                new BreadCrumb {
                    Title = "customer orders"
                }
            };

            return(View(customer.Orders.ToList().ToModel()));
        }
Пример #7
0
        // saves data for new or edited member to database.

        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            var service = new Service();

            var member = (MemberId == 0) ? new BusinessObjects.Member() : service.GetMember(MemberId);

            // get email name from page

            var row     = DetailsViewMember.Rows[1];
            var textBox = row.Cells[1].Controls[0] as TextBox;

            member.Email = textBox.Text.Trim();

            // get Company name from page.

            row                = DetailsViewMember.Rows[2];
            textBox            = row.Cells[1].Controls[0] as TextBox;
            member.CompanyName = textBox.Text.Trim();

            // get City from page

            row         = DetailsViewMember.Rows[3];
            textBox     = row.Cells[1].Controls[0] as TextBox;
            member.City = textBox.Text.Trim();

            // get Country from page

            row            = DetailsViewMember.Rows[4];
            textBox        = row.Cells[1].Controls[0] as TextBox;
            member.Country = textBox.Text.Trim();

            // validate using business rules engine

            if (member.IsValid())
            {
                if (MemberId == 0)
                {
                    service.InsertMember(member);
                    Session["message"] = "New member successfully added";
                }
                else
                {
                    service.UpdateMember(member);
                    Session["message"] = "Member successfully updated";
                }
            }
            else
            {
                LabelError.Text    = member.Errors.Aggregate((current, next) => current + "</br>" + next);
                PanelError.Visible = true;
                return;
            }

            // return to list of members

            Response.Redirect(UrlMaker.ToMembers());
        }
Пример #8
0
        /// <summary>
        /// Matches the input record request.
        /// Accepts the record request as input and returns matched records
        /// </summary>
        /// <param name="request">Required - ValidateEmailAddressAPIRequest request (object filled with input and option) </param>
        /// <returns>ValidateEmailAddressAPIResponse</returns>
        public ValidateEmailAddressAPIResponse ValidateEmailAddress(ValidateEmailAddressAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(IdentifyEmailUrl));
            string        url        = urlBuilder.ToString() + ValidateEmailAddressUrl;

            String requestString = Utility.ObjectToJson <ValidateEmailAddressAPIRequest>(request);

            return(Utility.processAPIRequest <ValidateEmailAddressAPIResponse>(url, requestString));
        }
        /// <summary>
        /// Retrieves response for the input records request.
        /// Accepts the city and state province records request as input and returns postal codes.
        /// </summary>
        /// <param name="request">Required - GetPostalCodesAPIRequest request (object filled with input and option) </param>
        /// <returns>GetPostalCodesAPIResponse</returns>
        public GetPostalCodesAPIResponse GetPostalCodes(GetPostalCodesAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(identifyAddressUrl));
            string        url        = urlBuilder.ToString() + getPostalCodesUrl;

            String requestString = Utility.ObjectToJson <GetPostalCodesAPIRequest>(request);

            return(Utility.processAPIRequest <GetPostalCodesAPIResponse>(url, requestString));
        }
Пример #10
0
        /// <summary>
        /// Matches the input record request.
        /// Accepts the record request as input and returns matched records
        /// </summary>
        /// <param name="request">Required - ExtractEntitiesAPIRequest request (object filled with input and option) </param>
        /// <returns>ExtractEntitiesAPIResponse</returns>
        public ExtractEntitiesAPIResponse ExtractEntities(ExtractEntitiesAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(IdentifyExtractUrl));
            string        url        = urlBuilder.ToString() + ExtractEntitiesUrl;

            String requestString = Utility.ObjectToJson <ExtractEntitiesAPIRequest>(request);

            return(Utility.processAPIRequest <ExtractEntitiesAPIResponse>(url, requestString));
        }
Пример #11
0
        /// <summary>
        /// Matches the input record request in asynchronous mode.
        /// Response can be retrieved by subscribing to event IdentifyAPIRequestFinishedEvent.
        /// Accepts the record request as input and returns matched records
        /// </summary>
        /// <param name="request">Required - CheckGlobalWatchListAPIRequest request (object filled with input and option) </param>
        public void CheckGlobalWatchListAsync(CheckGlobalWatchListAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(identifyRiskUrl));
            string        url        = urlBuilder.ToString() + checkGlobalWatchListUrl;

            String requestString = Utility.ObjectToJson <CheckGlobalWatchListAPIRequest>(request);
            processAPIRequestDelegate <CheckGlobalWatchListAPIResponse> delegateApiRequest = new processAPIRequestDelegate <CheckGlobalWatchListAPIResponse>(Utility.processAPIRequest <CheckGlobalWatchListAPIResponse>);

            delegateApiRequest.BeginInvoke(url, requestString, new AsyncCallback(WorkflowCompletedCallbackCheckGlobalWatchList), null);
        }
Пример #12
0
        /// <summary>
        /// Matches the input record request.
        /// Accepts the record request as input and returns matched records
        /// </summary>
        /// <param name="request">Required - CheckGlobalWatchListAPIRequest request (object filled with input and option) </param>
        /// <returns>CheckGlobalWatchListAPIResponse</returns>
        public CheckGlobalWatchListAPIResponse CheckGlobalWatchList(CheckGlobalWatchListAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(identifyRiskUrl));
            string        url        = urlBuilder.ToString() + checkGlobalWatchListUrl;


            String requestString = Utility.ObjectToJson <CheckGlobalWatchListAPIRequest>(request);

            return(Utility.processAPIRequest <CheckGlobalWatchListAPIResponse>(url, requestString));
        }
Пример #13
0
        /// <summary>
        /// Matches the input record request in asynchronous mode.
        /// Response can be retrieved by subscribing to event ValidateEmailAddressFinishedEvent.
        /// Accepts the record request as input and returns matched records
        /// </summary>
        /// <param name="request">Required - ValidateEmailAddressAPIRequest request (object filled with input and option) </param>
        public void ValidateEmailAddressAsync(ValidateEmailAddressAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(IdentifyEmailUrl));
            string        url        = urlBuilder.ToString() + ValidateEmailAddressUrl;

            String requestString = Utility.ObjectToJson <ValidateEmailAddressAPIRequest>(request);
            processAPIRequestDelegate <ValidateEmailAddressAPIResponse> delegateApiRequest = new processAPIRequestDelegate <ValidateEmailAddressAPIResponse>(Utility.processAPIRequest <ValidateEmailAddressAPIResponse>);

            delegateApiRequest.BeginInvoke(url, requestString, new AsyncCallback(WorkflowCompletedCallbackValidateEmailAddress), null);
        }
        /// <summary>
        /// Retrieves response for the input records request in asynchronous mode.
        /// Response can be retrieved by subscribing to event GetCityStateProvinceFinishedEvent.
        /// Accepts the postal code records request as input and returns city and state province
        /// </summary>
        /// <param name="request">Required - GetCityStateProvinceAPIRequest request (object filled with input and option) </param>
        public void GetCityStateProvinceAsync(GetCityStateProvinceAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(identifyAddressUrl));
            string        url        = urlBuilder.ToString() + getCityStateProvinceUrl;

            String requestString = Utility.ObjectToJson <GetCityStateProvinceAPIRequest>(request);
            processAPIRequestDelegate <GetCityStateProvinceAPIResponse> delegateApiRequest = new processAPIRequestDelegate <GetCityStateProvinceAPIResponse>(Utility.processAPIRequest <GetCityStateProvinceAPIResponse>);

            delegateApiRequest.BeginInvoke(url, requestString, new AsyncCallback(WorkflowCompletedCallbackGetCityStateProvince), null);
        }
Пример #15
0
        public BasicAuthServiceImpl(String token, String url)
        {
            authToken = token;

            if (url.Equals(""))
            {
                UrlMaker.getInstance().setUrlStrategy(new UrlMaker.UrlStrategy());
            }
            else
            {
                UrlMaker.getInstance().setUrlStrategy(new UrlStrategyTest(url));
            }
        }
Пример #16
0
        public ActionResult Login()
        {
            ViewData["BreadCrumbs"] = new List <BreadCrumb> {
                new BreadCrumb {
                    Url = UrlMaker.ToDefault(), Title = "home"
                },
                new BreadCrumb {
                    Title = "login"
                }
            };

            return(View(new LoginModel()));
        }
Пример #17
0
        /// <summary>
        /// Saves data for new or edited customer to database.
        /// </summary>
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            var repository = new CustomerRepository();

            ActionServiceReference.Customer customer;
            if (CustomerId == 0)
            {
                customer = new ActionServiceReference.Customer();
            }
            else
            {
                customer = repository.GetCustomer(CustomerId);
            }

            // Get Company name from page.
            var row     = DetailsViewCustomer.Rows[1];
            var textBox = row.Cells[1].Controls[0] as TextBox;

            customer.Company = textBox.Text.Trim();

            // Get City from page.
            row           = DetailsViewCustomer.Rows[2];
            textBox       = row.Cells[1].Controls[0] as TextBox;
            customer.City = textBox.Text.Trim();

            // Get Country from page.
            row              = DetailsViewCustomer.Rows[3];
            textBox          = row.Cells[1].Controls[0] as TextBox;
            customer.Country = textBox.Text.Trim();

            try
            {
                if (CustomerId == 0)
                {
                    repository.AddCustomer(customer);
                }
                else
                {
                    repository.UpdateCustomer(customer);
                }
            }
            catch (ApplicationException ex)
            {
                LabelError.Text    = ex.Message.Replace(Environment.NewLine, "<br />");
                PanelError.Visible = true;
                return;
            }

            // Return to list of customers.
            Response.Redirect(UrlMaker.ToCustomers());
        }
Пример #18
0
        /// <summary>
        /// Action method. Performs a logout for current user.
        /// </summary>
        /// <returns></returns>
        public ActionResult Logout()
        {
            _authRepository.Logout();
            FormsAuthentication.SignOut();

            ViewData["BreadCrumbs"] = new List <BreadCrumb> {
                new BreadCrumb {
                    Url = UrlMaker.ToDefault(), Title = "home"
                },
                new BreadCrumb {
                    Title = "logout"
                }
            };
            return(View());
        }
Пример #19
0
        // private Helper
        private void SetCustomerViewData(int?customerId = 0)
        {
            ViewData["BreadCrumbs"] = new List <BreadCrumb> {
                new BreadCrumb {
                    Url = UrlMaker.ToDefault(), Title = "home"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToAdmin(), Title = "administration"
                },
                new BreadCrumb {
                    Url = UrlMaker.ToCustomers(), Title = "customers"
                },
                new BreadCrumb {
                    Title = "customer details"
                }
            };

            ViewData["CustomerImage"] = imageService + "GetCustomerImageLarge/" + customerId;
        }
Пример #20
0
        /// <summary>
        /// Gets the authentication token.
        /// </summary>
        /// <returns></returns>
        public override String getAuthenticationToken()
        {
            String authToken = getToken();
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            Debug.WriteLine("It seems token is not generated yet, Going for OAuth mechanism");
            // Token is not generated yet
            if (authToken == null && tokenRegeneration)
            {
                try{
                    UrlMaker maker = UrlMaker.getInstance();
                    String   url   = maker.getAbsoluteUrl(oAuthUrl);

                    String authHeader = Constants.BASIC + Convert.ToBase64String(Encoding.UTF8.GetBytes(consumerKey + ":" + consumerSecretKey));
                    Uri    uri        = new Uri(url);

                    using (ExtendedWebClient webClient = new ExtendedWebClient())
                    {
                        NameValueCollection headers = new NameValueCollection();

                        headers.Add(Constants.AUTH_HEADER, authHeader);
                        webClient.Headers.Add(headers);

                        string jsonResponse = webClient.UploadString(url, Constants.GRANT_TYPE + "=" + Constants.CLIENT_CREDENTIALS);

                        OAuthServiceResponse oAuthServiceResponse = serializer.Deserialize <OAuthServiceResponse>(jsonResponse);
                        authToken = Constants.BEARER + oAuthServiceResponse.access_token;
                    }
                }

                catch (Exception e) {
                    Debug.WriteLine("Unexpected Exception while generating token, so Invalidating the Authentication Token" + e);
                    invalidateIdentifyServiceManagerInstance();
                    throw new SdkException(new SdkInternalError(e.Message));
                }
            }

            return(authToken);
        }
Пример #21
0
        // establishes the composite menu hierarchy which is present on all pages.

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // build the composite menu tree
                // this tree implements the Composite Design Pattern

                var root = new MenuCompositeItem("root", null);
                var home = new MenuCompositeItem("home", UrlMaker.ToDefault());
                var shop = new MenuCompositeItem("shopping", UrlMaker.ToShopping());
                var prod = new MenuCompositeItem("products", UrlMaker.ToProducts());
                var srch = new MenuCompositeItem("search", UrlMaker.ToSearch());
                var admn = new MenuCompositeItem("administration", UrlMaker.ToAdmin());
                var cust = new MenuCompositeItem("members", UrlMaker.ToMembers());
                var ordr = new MenuCompositeItem("orders", UrlMaker.ToOrders());

                MenuCompositeItem auth;
                if (Request.IsAuthenticated)
                {
                    auth = new MenuCompositeItem("logout", UrlMaker.ToLogout());
                }
                else
                {
                    auth = new MenuCompositeItem("login", UrlMaker.ToLogin());
                }

                shop.Children.Add(prod);
                shop.Children.Add(srch);
                admn.Children.Add(cust);
                admn.Children.Add(ordr);
                root.Children.Add(home);
                root.Children.Add(shop);
                root.Children.Add(admn);
                root.Children.Add(auth);


                TheMenuComposite.MenuItems = root;
            }
        }
        public void ConfigureServices(IServiceCollection services)
        {
            EmailTools.Replacements.AddRange(UrlMaker.GetTagReplacements());

            database = new Database(Configuration["ConnectionStrings:DefaultConnection"]);

            IEmailSender emailSender = new Office365Emailer(Configuration["Email:Address"], Configuration["Email:Password"], "Admin");
            Emailer      emailer     = new Emailer(emailSender, "");

            // add objects to initialise constructors with
            services.AddSingleton(typeof(Database), database);
            services.AddSingleton(typeof(Emailer), emailer);
            services.AddSingleton(typeof(IEmailSender), emailSender);
            services.AddTransient <ISmsSender, AuthMessageSender>();

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
            });

            // Require https sitewide
            services.Configure <MvcOptions>(options => { options.Filters.Add(new RequireHttpsAttribute()); });

            services.AddIdentity <User, Role>(o =>
            {
                o.User.RequireUniqueEmail = true;

                o.Lockout.MaxFailedAccessAttempts = 5;
                o.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(5);
                o.Lockout.AllowedForNewUsers      = false;

                o.Password.RequireDigit           = false;
                o.Password.RequiredLength         = 6;
                o.Password.RequiredUniqueChars    = 1;
                o.Password.RequireLowercase       = false;
                o.Password.RequireNonAlphanumeric = false;
                o.Password.RequireUppercase       = false;
            })
            .AddUserStore <MyUserStore>()
            .AddRoleStore <MyRoleStore>()
            .AddDefaultTokenProviders();

            services.AddAuthentication()
            .AddGoogle(googleOptions =>
            {
                googleOptions.ClientId     = Configuration["Authentication:Google:ClientId"];
                googleOptions.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
            })
            .AddMicrosoftAccount(microsoftOptions =>
            {
                microsoftOptions.ClientId     = Configuration["Authentication:Microsoft:ClientId"];
                microsoftOptions.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
            })
            .AddFacebook(facebookOptions =>
            {
                facebookOptions.ClientId     = Configuration["Authentication:Facebook:ClientId"];
                facebookOptions.ClientSecret = Configuration["Authentication:Facebook:ClientSecret"];
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("CanAdmin", policy => policy.RequireClaim("IsAdmin"));
            });

            services.AddControllersWithViews().AddNewtonsoftJson();
            services.AddRazorPages();

            services.AddLogging(builder =>
            {
                builder.AddConfiguration(Configuration.GetSection("Logging"))
                .AddConsole()
                .AddDebug();
            });
        }
Пример #23
0
        // cancel the page and redirect user to page with list of members

        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect(UrlMaker.ToMembers());
        }