Beispiel #1
0
        private async Task <IActionResult> Delete(int venueId)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (!Role.CanAdministerCompany)
            {
                return(RedirectToPage("/Index"));
            }

            var getResult = (await venues.FetchVenue(venueId).ConfigureAwait(false))
                            .Ensure(e => e.HasValue, "Venue found")
                            .OnSuccess(e => e.Value);

            if (!getResult.IsSuccess)
            {
                return(RedirectToPage("/Index"));
            }

            var result = await venues.DropVenue(venueId).ConfigureAwait(false);

            if (result.IsSuccess)
            {
                return(RedirectToPage("/CompanyVenues", new
                {
                    companyId = getResult.Value.CompanyId
                }));
            }
            else
            {
                return(RedirectToPage("/Index"));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> DropVenue([FromRoute(Name = "venueId")] int venueId)
        {
            var venue = await venues.FetchVenue(venueId).ConfigureAwait(false);

            if (venue.IsFailure || venue.Value.HasNoValue)
            {
                return(NotFound());
            }

            var ven = venue.Value.Value;

            if (this.GetAuthContext().Employee.Value.CompanyId != ven.CompanyId && !this.GetAuthContext().EmployeeRole.Value.CanAdministerSystem)
            {
                return(Unauthorized());
            }

            return(await venues.DropVenue(venueId)
                   .OnBoth(v => v.IsFailure ? StatusCode(404) : StatusCode(200))
                   .ConfigureAwait(false));
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            ViewData["HideNavigation"] = true;

            returnUrl ??= Url.Content("~/");

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var company = await companies.CreateCompany(new Company
            {
                CompanyName     = Input.CompanyName,
                CompanyPhone    = Input.CompanyPhone,
                CompanyPostcode = Input.CompanyPostcode,
                CompanyContact  = Input.CompanyContact,
                CompanyEmail    = Input.CompanyEmail,
                CompanyAddress  = Input.CompanyAddress
            }).Ensure(c => c.HasValue, "Company created")
                          .OnSuccess(c => c.Value)
                          .ConfigureAwait(false);

            if (company.IsFailure)
            {
                ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup.");
                return(Page());
            }

            var venue = await venues.CreateVenue(new Venue {
                CompanyId        = company.Value,
                VenueCode        = "",
                VenueName        = Input.VenueName,
                VenueAddress     = "",
                VenuePostCode    = "",
                VenuePhone       = "",
                VenueContact     = "",
                VenueDescription = "",
                VenueNotes       = "Created via onboarding",
            }).Ensure(c => c.HasValue, "Venue created")
                        .OnSuccess(c => c.Value)
                        .ConfigureAwait(false);

            if (venue.IsFailure)
            {
                ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup.");
                return(Page());
            }

            var user = new Employee {
                Username = Input.EmployeeEmail, EmployeeName = Input.EmployeeName, CompanyId = company.Value, VenueId = venue.Value, RoleId = 5
            };
            var result = await _userManager.CreateAsync(user, Input.EmployeePassword).ConfigureAwait(false);

            if (result.Succeeded)
            {
                result = await _userManager.UpdateSecurityStampAsync(user).ConfigureAwait(false);

                if (result.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user).ConfigureAwait(false);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

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

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

                    await _emailSender.SendEmailAsync(Input.EmployeeEmail, "Welcome to Koasta!",
                                                      $@"
                            <p>Thanks for choosing Koasta. You're on your way to accepting digital payments with ease.</p>
                            <p>Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>. After confirming, you'll have access to your Koasta dashboard and can begin your onboarding process.</p>
                            <p>Further information about how to get started with Koasta can be found <a href='https://support.koasta.com'>here</a>.</p>
                        ").ConfigureAwait(false);

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

                        return(LocalRedirect(returnUrl));
                    }
                }
            }

            try
            {
                await venues.DropVenue(venue.Value).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }

            try
            {
                await companies.DropCompany(company.Value).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }

            if (!result.Errors.Any(e => e.Code.Equals("TOOCOMMON", StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup.");
            }

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

            // If we got this far, something failed, redisplay form
            return(Page());
        }