예제 #1
0
        public async Task <ActionResult> ContactUs([FromServices] DataContext dataContext, ContactUsViewModel data)
        {
            if (ModelState.IsValid)
            {
                if (!Recaptcha.Validate(Request.Form["g-recaptcha-response"]))
                {
                    ModelState.AddModelError("ReCaptchaValid", "ReCaptcha failed please try again");
                }
                else
                {
                    ContactSubmission contactSubmission = ContactSubmission.CreateFromViewModel(data);
                    contactSubmission.EmailedTo = Settings.Emails.ToAddresses;
                    dataContext.ContactSubmissions.Add(contactSubmission);
                    dataContext.SaveChanges(currentUserName);

                    Response resp = await EmailFacade.SendAsync(contactSubmission);

                    SimpleNotifier noty = notifier();

                    if (resp.StatusCode == HttpStatusCode.Accepted)
                    {
                        noty.AddMessage(MsgTypes.Success, "Thanks for getting in contact, we will reply in due course");
                        return(Redirect("/"));
                    }
                    else
                    {
                        noty.AddMessage(MsgTypes.Warning, "Problems sending sending your message, please try again.");
                        return(View(data));
                    }
                }
            }
            return(View(data));
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                SignInResult result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : false);// To enable password failures to trigger account lockout, set lockoutOnFailure: true

                if (result.Succeeded)
                {
                    SimpleNotifier noty = notifier();
                    noty.AddMessage(MsgTypes.Success, "You were logged in");
                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt"); //N.B. This doesn't count login failures towards account lockout
                    return(Page());
                }
            }
            return(Page());// If we got this far, something failed, re-display form
        }
예제 #3
0
        public async Task <IActionResult> Index(
            [FromServices] DataContext dataContext,
            [FromServices] IContentfulService contentfulService)
        {
            SimpleNotifier noty = notifier();

            noty.AddMessage(MsgTypes.Information, "TIP: Try changing Map Layers (top right)");

            IQueryable <Need> allNeedsPosts = dataContext.Needs.Include(n => n.NeedPpeTypes);

            //This logic is intentionally "fluffy", we are (justifiably) bumping up the Met and Partially Met percentages
            //by excluding posts from the "total" which volunteers cannot possibly meet: see notes on IsNotMarkedAllNotMetAndIsContactable etc

            int countAllNeedsPosts = allNeedsPosts.Count();
            int countSeeminglyContactableNeedsPosts = allNeedsPosts.ToList().Count(n => n.IsNotMarkedAllNotMetAndIsContactable());

            IQueryable <Need> fullyMetNeeds = allNeedsPosts.Where(p => p.NeedPpeTypes.All(pt => pt.StatusId == (int)PpeStatus.Met));
            int countFullyMetNeeds          = fullyMetNeeds.Count();
            int countPartiallyMetNeeds      = allNeedsPosts.Except(fullyMetNeeds).Count(p => p.NeedPpeTypes.Any(pt => pt.StatusId == (int)PpeStatus.Met));

            ViewData["met"]     = countFullyMetNeeds;
            ViewData["partial"] = countPartiallyMetNeeds;
            ViewData["new"]     = countSeeminglyContactableNeedsPosts - (countFullyMetNeeds + countPartiallyMetNeeds);

            ViewData["contactable"]    = countSeeminglyContactableNeedsPosts;
            ViewData["noncontactable"] = countAllNeedsPosts - countSeeminglyContactableNeedsPosts;
            ViewData["contentful"]     = await contentfulService.GetFirstByContentType <HomePageViewModel>("home-page");

            return(View());
        }
예제 #4
0
        public async Task <IActionResult> OnGetAsync(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(RedirectToPage("/Index"));
            }

            AppUser user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(RedirectToPage("/Index"));//let's NOT give potential attackers details about User Ids !!! return NotFound($"Unable to load user with ID '{userId}'.");
            }

            code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
            IdentityResult result = await _userManager.ConfirmEmailAsync(user, code);

            SimpleNotifier notifier = base.notifier();

            if (result.Succeeded)
            {
                notifier.AddMessage(MsgTypes.Information, "Thanks, your email was verified");
            }
            else
            {
                notifier.AddMessage(MsgTypes.Error, "Error confirming your email");
            }
            return(Page());
        }
예제 #5
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            SimpleNotifier noty = notifier();

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new AppUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    noty.AddMessage(MsgTypes.Success, "Created user account");
                    IdentityResult roleRes = await _usersFacade.EnsureRole(user.Id, SecurityRoles.Volunteer.ToString());

                    if (roleRes.Succeeded)
                    {
                        noty.AddMessage(MsgTypes.Success, $"Added Role {SecurityRoles.Volunteer.GetText()}");
                        noty.AddMessage(MsgTypes.Information, $"Please check your email and confirm your address");
                    }

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
 public void NotifyTestHttpChecker()
 {
     string username = "******"; // TODO: Initialize to an appropriate value
     string key = "f3aa9bf27db60674f228fd90beeb028897657c4a6450fc9de8a8c87221a12dcfe"; // TODO: Initialize to an appropriate value
     string senderName = "ND"; // TODO: Initialize to an appropriate value
     IEnumerable<string> destinations = new string[] {"+61433003505" }; // TODO: Initialize to an appropriate value
     SimpleNotifier target = new SimpleNotifier(username, key, senderName, destinations); // TODO: Initialize to an appropriate value
     CheckResult checkResult = new CheckResult(false, new Dictionary<string, string>()); // TODO: Initialize to an appropriate value
     string configuration = "Test"; // TODO: Initialize to an appropriate value
     target.Notify(checkResult, configuration);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
        public void NotifyTestHttpChecker()
        {
            string username   = "******";                                                                   // TODO: Initialize to an appropriate value
            string key        = "f3aa9bf27db60674f228fd90beeb028897657c4a6450fc9de8a8c87221a12dcfe";         // TODO: Initialize to an appropriate value
            string senderName = "ND";                                                                        // TODO: Initialize to an appropriate value
            IEnumerable <string> destinations = new string[] { "+61433003505" };                             // TODO: Initialize to an appropriate value
            SimpleNotifier       target       = new SimpleNotifier(username, key, senderName, destinations); // TODO: Initialize to an appropriate value
            CheckResult          checkResult  = new CheckResult(false, new Dictionary <string, string>());   // TODO: Initialize to an appropriate value
            string configuration = "Test";                                                                   // TODO: Initialize to an appropriate value

            target.Notify(checkResult, configuration);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
예제 #8
0
        public IActionResult RequestPpe([FromServices] DataContext dataContext, NeedsViewModel vm)
        {
            SimpleNotifier noty = notifier();

            if (ModelState.IsValid)
            {
                Need need = Need.CreateFromViewModel(vm);
                dataContext.Needs.Add(need);
                dataContext.SaveChanges(currentUserName);
                noty.AddMessage(MsgTypes.Success, "Thanks you have been added to the database, we will be in contact in due course");
                return(Redirect("/"));
            }
            else
            {
                noty.AddMessage(MsgTypes.Warning, "Problems saving details, please fix and try again");
                return(View(vm));
            }
        }
예제 #9
0
        public IActionResult EditSupplies([FromServices] DataContext dataContext, EditSuppliesPost data)
        {
            SimpleNotifier noty = notifier();

            if (!ModelState.IsValid)
            {
                noty.AddMessage(MsgTypes.Warning, "Problems saving, please try again");
                return(View("EditSupplies", EditSuppliesViewModel.FromPostData(data)));
            }
            else
            {
                Supplier existingSupplies = dataContext.Suppliers.Include(p => p.SupplierPpeTypes).Single(n => n.Id == data.Supplies.Id);
                existingSupplies.Modify(data, currentUserId);
                dataContext.SaveChanges(currentUserName);
                noty.AddMessage(MsgTypes.Success, "Successfully updated Supplier");
                return(Redirect("/suppliers"));
            }
        }
예제 #10
0
        public IActionResult EditNeeds([FromServices] DataContext dataContext, EditNeedsPost data)
        {
            SimpleNotifier noty = notifier();

            if (!ModelState.IsValid)
            {
                List <Supplier> suppliers = dataContext.Suppliers.ToList();
                noty.AddMessage(MsgTypes.Warning, "Problems saving, please try again");
                return(View("EditNeeds", EditNeedsViewModel.FromPostData(data, suppliers)));
            }
            else
            {
                Need existingNeed = dataContext.Needs.Include(p => p.NeedPpeTypes).Single(n => n.Id == data.Request.Id);
                existingNeed.Modify(data, currentUserId);
                dataContext.SaveChanges(currentUserName);
                noty.AddMessage(MsgTypes.Success, "Successfully updated the Request");
                return(Redirect("/requests"));
            }
        }
예제 #11
0
        public IActionResult RegisterSupplies([FromServices] DataContext dataContext, SuppliesViewModel data)
        {
            SimpleNotifier noty = notifier();

            if (ModelState.IsValid)
            {
                Supplier supplier = Supplier.CreateFromViewModel(data);
                dataContext.Suppliers.Add(supplier);
                List <SupplierPpeType> supplierPpeTypes = data.PpeTypes.Where(st => st.Selected).Select(st => SupplierPpeType.Create_FromViewModel(st, supplier)).ToList();
                supplierPpeTypes.ForEach(st => dataContext.SupplierPpeTypes.Add(st));
                dataContext.SaveChanges(currentUserName);
                noty.AddMessage(MsgTypes.Success, "Thanks you have been added to the database, we will be in contact in due course");
                return(Redirect("/"));
            }
            else
            {
                noty.AddMessage(MsgTypes.Warning, "Problems saving details, please fix and try again");
                return(View(data));
            }
        }
    public void OnClickNotifyAfter5seconds()
    {
        DateTime dateTime = DateTime.UtcNow.AddSeconds(5);

        SimpleNotifier.ScheduleNotification(dateTime, "test title", "test body");
    }