private async Task <AdminRegistrationViewModel> GetModelData(AdminRegistrationViewModel model) { var competentAuthorities = EnumHelper.GetValues(typeof(UKCompetentAuthority)) .Select(p => new SelectListItem() { Text = p.Value, Value = p.Key.ToString() }); model.CompetentAuthorities = new SelectList(competentAuthorities, "Value", "Text"); string token = User.GetAccessToken(); if (string.IsNullOrWhiteSpace(token)) { var tokenResponse = await oauthClientCredentialClient().GetClientCredentialsAsync(); token = tokenResponse.AccessToken; } var result = await client.SendAsync(token, new GetLocalAreas()); model.Areas = new SelectList(result.Select(area => new SelectListItem { Text = area.Name, Value = area.Id.ToString() }), "Value", "Text"); return(model); }
public async Task <ActionResult> ApplicantRegistration(ApplicantRegistrationViewModel model) { var response = await oauthClientCredentialClient().GetClientCredentialsAsync(); if (ModelState.IsValid) { var applicantRegistrationData = new ApplicantRegistrationData { Email = model.Email, FirstName = model.Name, Surname = model.Surname, Phone = model.PhoneNumber, Password = model.Password, ConfirmPassword = model.ConfirmPassword }; try { var userId = await client.Registration.RegisterApplicantAsync(response.AccessToken, applicantRegistrationData); var signInResponse = await oauthClient().GetAccessTokenAsync(model.Email, model.Password); authenticationManager.SignIn(signInResponse.GenerateUserIdentity()); var emailSent = await client.Registration.SendEmailVerificationAsync(signInResponse.AccessToken, new EmailVerificationData { Url = Url.Action("VerifyEmail", "Account", null, Request.Url.Scheme) }); var addressId = await client.SendAsync(signInResponse.AccessToken, new CreateAddress { Address = model.Address, UserId = userId }); applicantRegistrationData.AddressId = addressId; return(RedirectToAction("SelectOrganisation", new { organisationName = model.OrganisationName })); } catch (ApiBadRequestException ex) { this.HandleBadRequest(ex); if (ModelState.IsValid) { throw; } } await this.BindCountryList(client, response.AccessToken); return(View(model)); } await this.BindCountryList(client, response.AccessToken); return(View(model)); }
public async Task <TResponse> SendAsync <TResponse>(IRequest <TResponse> request) { var allowUnauthorized = request.GetType().GetCustomAttributes(typeof(AllowUnauthorizedUserAttribute)).SingleOrDefault(); if (allowUnauthorized != null) { return(await client.SendAsync(await GetAccessToken(), request).ConfigureAwait(false)); } var accessToken = await GetAccessToken(); if (string.IsNullOrWhiteSpace(accessToken) && !httpContext.User.Identity.IsAuthenticated) { throw new SecurityException("Unauthenticated user"); } return(await client.SendAsync(accessToken, request).ConfigureAwait(false)); }
public static async Task BindCountryList(this Controller controller, IIwsClient client, string accessToken, bool setDefaultAsUnitedKingdom = true) { var response = await client.SendAsync(accessToken, new GetCountries()); BindCountriesToViewBag(controller, response, setDefaultAsUnitedKingdom); }
public static async Task BindCountryList(this Controller controller, IIwsClient client, bool setDefaultAsUnitedKingdom = true) { var response = await client.SendAsync(new GetCountries()); BindCountriesToViewBag(controller, response, setDefaultAsUnitedKingdom); }