public MediatorResponse AcceptTermsAndConditions(Guid candidateId) { try { var candidate = _candidateServiceProvider.GetCandidate(candidateId); var currentTsAndCsVersion = _configurationService.Get <CommonWebConfiguration>().TermsAndConditionsVersion; if (candidate.RegistrationDetails.AcceptedTermsAndConditionsVersion == currentTsAndCsVersion) { return(GetMediatorResponse(AccountMediatorCodes.AcceptTermsAndConditions.AlreadyAccepted)); } var success = _candidateServiceProvider.AcceptTermsAndConditions(candidateId, currentTsAndCsVersion); if (success) { return(GetMediatorResponse(AccountMediatorCodes.AcceptTermsAndConditions.SuccessfullyAccepted)); } } // ReSharper disable once EmptyGeneralCatchClause catch { // returns ErrorAccepting } return(GetMediatorResponse(AccountMediatorCodes.AcceptTermsAndConditions.ErrorAccepting)); }
public async Task <ActionResult> Activate(ActivationViewModel model) { return(await Task.Run <ActionResult>(() => { var response = _registerMediator.Activate(UserContext.CandidateId, model); switch (response.Code) { case RegisterMediatorCodes.Activate.SuccessfullyActivated: SetUserMessage(response.Message.Text); var candidate = _candidateServiceProvider.GetCandidate(model.EmailAddress); UserData.SetUserContext(candidate.RegistrationDetails.EmailAddress, candidate.RegistrationDetails.FirstName + " " + candidate.RegistrationDetails.LastName, candidate.RegistrationDetails.AcceptedTermsAndConditionsVersion); return RedirectToRoute(RouteNames.MonitoringInformation); case RegisterMediatorCodes.Activate.InvalidActivationCode: case RegisterMediatorCodes.Activate.FailedValidation: response.ValidationResult.AddToModelState(ModelState, string.Empty); break; case RegisterMediatorCodes.Activate.ErrorActivating: SetUserMessage(response.Message.Text, response.Message.Level); break; default: throw new InvalidMediatorCodeException(response.Code); } return View("Activation", model); })); }
public MediatorResponse AcceptTermsAndConditions(Guid candidateId) { try { var candidate = _candidateServiceProvider.GetCandidate(candidateId); var currentTsAndCsVersion = _configurationManager.GetAppSetting <string>(Constants.Settings.TermsAndConditionsVersion); if (candidate.RegistrationDetails.AcceptedTermsAndConditionsVersion == currentTsAndCsVersion) { return(GetMediatorResponse(AccountMediatorCodes.AcceptTermsAndConditions.AlreadyAccepted)); } var success = _candidateServiceProvider.AcceptTermsAndConditions(candidateId, currentTsAndCsVersion); if (success) { return(GetMediatorResponse(AccountMediatorCodes.AcceptTermsAndConditions.SuccessfullyAccepted)); } } catch { // returns ErrorAccepting } return(GetMediatorResponse(AccountMediatorCodes.AcceptTermsAndConditions.ErrorAccepting)); }
private ActionResult SetAuthenticationCookieAndRedirectToAction(string candidateEmail) { var candidate = _candidateServiceProvider.GetCandidate(candidateEmail); //todo: refactor - similar to stuff in login controller... move to ILoginServiceProvider //todo: test this _authenticationTicketService.SetAuthenticationCookie(HttpContext.Response.Cookies, candidate.EntityId.ToString(), UserRoleNames.Activated); UserData.SetUserContext(candidate.RegistrationDetails.EmailAddress, candidate.RegistrationDetails.FirstName + " " + candidate.RegistrationDetails.LastName, candidate.RegistrationDetails.AcceptedTermsAndConditionsVersion); // ReturnUrl takes precedence over last view vacnacy id. var returnUrl = UserData.Pop(UserDataItemNames.ReturnUrl); // Clear last viewed vacancy and distance (if any). var lastViewedVacancyId = UserData.Pop(CandidateDataItemNames.LastViewedVacancyId); UserData.Pop(CandidateDataItemNames.VacancyDistance); if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(Server.UrlDecode(returnUrl))); } if (lastViewedVacancyId != null) { return(RedirectToRoute(CandidateRouteNames.ApprenticeshipDetails, new { id = int.Parse(lastViewedVacancyId) })); } return(RedirectToRoute(CandidateRouteNames.ApprenticeshipSearch)); }
private ContactMessageViewModel InternalGetContactMessageViewModel(Guid?candidateId) { var viewModel = new ContactMessageViewModel(); PopulateContactMessageViewModelEnquiries(viewModel); if (candidateId.HasValue) { try { var candidate = _candidateServiceProvider.GetCandidate(candidateId.Value); viewModel.Email = candidate.RegistrationDetails.EmailAddress; viewModel.Name = string.Format("{0} {1}", candidate.RegistrationDetails.FirstName, candidate.RegistrationDetails.LastName); } catch (Exception ex) { _logService.Error("Failed to created view model (ignoring)", ex); } } return(viewModel); }
public ActionResult Index() { var statusTasks = new[] { new Task(() => _apprenticeshipApplicationProvider.GetApplicationViewModel(Guid.NewGuid(), 123456)), new Task(() => _candidateServiceProvider.GetCandidate(Guid.NewGuid())), new Task(() => _searchProvider.FindLocation("London")) }; Parallel.ForEach(statusTasks, task => task.Start()); Task.WaitAll(statusTasks); // GDS Performance platform (Pingdom) is configured to look for the following text // in a 200 response. Anything other than this will register the site as down. return(Content("System healthy.")); }
public MediatorResponse <ApprenticeshipSearchViewModel> Index(Guid?candidateId, ApprenticeshipSearchMode searchMode, bool reset) { var lastSearchedLocation = UserDataProvider.Get(UserDataItemNames.LastSearchedLocation); if (string.IsNullOrWhiteSpace(lastSearchedLocation) && candidateId.HasValue) { var candidate = _candidateServiceProvider.GetCandidate(candidateId.Value); UserDataProvider.Push(UserDataItemNames.LastSearchedLocation, lastSearchedLocation = candidate.RegistrationDetails.Address.Postcode); } if (!candidateId.HasValue && searchMode == ApprenticeshipSearchMode.SavedSearches) { searchMode = ApprenticeshipSearchMode.Keyword; } var distances = GetDistances(true); var sortTypes = GetSortTypes(); var resultsPerPage = GetResultsPerPage(); var apprenticeshipLevels = GetApprenticeshipLevels(); var apprenticeshipLevel = GetApprenticeshipLevel(reset); var searchFields = GetSearchFields(); var categories = GetCategories(); var savedSearches = GetSavedSearches(candidateId); var viewModel = new ApprenticeshipSearchViewModel { WithinDistance = 5, LocationType = ApprenticeshipLocationType.NonNational, Location = SplitSearchLocation(lastSearchedLocation, 0), Latitude = SplitSearchLocation(lastSearchedLocation, 1).GetValueOrNull <double>(), Longitude = SplitSearchLocation(lastSearchedLocation, 2).GetValueOrNull <double>(), Distances = distances, SortTypes = sortTypes, ResultsPerPage = resultsPerPage, ApprenticeshipLevels = apprenticeshipLevels, ApprenticeshipLevel = apprenticeshipLevel, SearchFields = searchFields, Categories = categories, SavedSearches = savedSearches, SearchMode = searchMode }; return(GetMediatorResponse(ApprenticeshipSearchMediatorCodes.Index.Ok, viewModel)); }
private ContactMessageViewModel GetViewModel(Guid?candidateId) { var viewModel = new ContactMessageViewModel(); PopulateEnquiries(viewModel); if (candidateId.HasValue) { try { var candidate = _candidateServiceProvider.GetCandidate(candidateId.Value); viewModel.Email = candidate.RegistrationDetails.EmailAddress; viewModel.Name = string.Format("{0} {1}", candidate.RegistrationDetails.FirstName, candidate.RegistrationDetails.LastName); } catch { } } return(viewModel); }
private ActionResult SetUserContextAndRedirectToAction(string candidateEmail) { var candidate = _candidateServiceProvider.GetCandidate(candidateEmail); //todo: refactor - similar to stuff in login controller... move to ILoginServiceProvider //todo: test this UserData.SetUserContext(candidate.RegistrationDetails.EmailAddress, candidate.RegistrationDetails.FirstName + " " + candidate.RegistrationDetails.LastName, candidate.RegistrationDetails.AcceptedTermsAndConditionsVersion); // ReturnUrl takes precedence over last view vacnacy id. var returnUrl = UserData.Pop(UserDataItemNames.ReturnUrl); // Clear last viewed vacancy and distance (if any). var lastViewedVacancy = UserData.PopLastViewedVacancy(); UserData.Pop(CandidateDataItemNames.VacancyDistance); if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(Server.UrlDecode(returnUrl))); } if (lastViewedVacancy != null) { switch (lastViewedVacancy.Type) { case VacancyType.Apprenticeship: return(RedirectToRoute(CandidateRouteNames.ApprenticeshipDetails, new { id = lastViewedVacancy.Id })); case VacancyType.Traineeship: return(RedirectToRoute(CandidateRouteNames.TraineeshipDetails, new { id = lastViewedVacancy.Id })); } } return(RedirectToRoute(CandidateRouteNames.ApprenticeshipSearch)); }
public MediatorResponse <TraineeshipSearchViewModel> Index(Guid?candidateId) { var lastSearchedLocation = UserDataProvider.Get(UserDataItemNames.LastSearchedLocation); if (string.IsNullOrWhiteSpace(lastSearchedLocation) && candidateId.HasValue) { var candidate = _candidateServiceProvider.GetCandidate(candidateId.Value); UserDataProvider.Push(UserDataItemNames.LastSearchedLocation, lastSearchedLocation = candidate.RegistrationDetails.Address.Postcode); } var traineeshipSearchViewModel = new TraineeshipSearchViewModel { WithinDistance = 40, Distances = GetDistances(false), SortTypes = GetSortTypes(), SortType = VacancySearchSortType.Distance, ResultsPerPage = GetResultsPerPage(), Location = SplitSearchLocation(lastSearchedLocation, 0), Latitude = SplitSearchLocation(lastSearchedLocation, 1).GetValueOrNull <double>(), Longitude = SplitSearchLocation(lastSearchedLocation, 2).GetValueOrNull <double>(), }; return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Index.Ok, traineeshipSearchViewModel)); }
public MediatorResponse <LoginResultViewModel> Index(LoginViewModel viewModel) { var validationResult = _loginViewModelServerValidator.Validate(viewModel); if (!validationResult.IsValid) { return(GetMediatorResponse <LoginResultViewModel>(LoginMediatorCodes.Index.ValidationError, null, validationResult)); } var result = _candidateServiceProvider.Login(viewModel); if (result.UserStatus.HasValue) { if (result.UserStatus == UserStatuses.Locked) { _userDataProvider.Push(UserDataItemNames.UnlockEmailAddress, result.EmailAddress); return(GetMediatorResponse(LoginMediatorCodes.Index.AccountLocked, result)); } if (result.IsAuthenticated) { _userDataProvider.SetUserContext(result.EmailAddress, result.FullName, result.AcceptedTermsAndConditionsVersion); if (result.UserStatus == UserStatuses.PendingActivation) { return(GetMediatorResponse(LoginMediatorCodes.Index.PendingActivation, result)); } // Redirect to session return URL (if any). var returnUrl = _userDataProvider.Pop(UserDataItemNames.SessionReturnUrl) ?? _userDataProvider.Pop(UserDataItemNames.ReturnUrl); result.ReturnUrl = returnUrl; if (result.AcceptedTermsAndConditionsVersion != _configurationManager.GetAppSetting <string>(Settings.TermsAndConditionsVersion)) { return(!string.IsNullOrEmpty(returnUrl) ? GetMediatorResponse(LoginMediatorCodes.Index.TermsAndConditionsNeedAccepted, result, parameters: returnUrl) : GetMediatorResponse(LoginMediatorCodes.Index.TermsAndConditionsNeedAccepted, result)); } if (!string.IsNullOrWhiteSpace(returnUrl)) { return(GetMediatorResponse(LoginMediatorCodes.Index.ReturnUrl, result, parameters: returnUrl)); } // Redirect to last viewed vacancy (if any). var lastViewedVacancyId = _userDataProvider.Pop(CandidateDataItemNames.LastViewedVacancyId); if (lastViewedVacancyId != null) { var candidate = _candidateServiceProvider.GetCandidate(result.EmailAddress); var applicationStatus = _candidateServiceProvider.GetApplicationStatus(candidate.EntityId, int.Parse(lastViewedVacancyId)); if (applicationStatus.HasValue && applicationStatus.Value == ApplicationStatuses.Draft) { return(GetMediatorResponse(LoginMediatorCodes.Index.ApprenticeshipApply, result, parameters: lastViewedVacancyId)); } return(GetMediatorResponse(LoginMediatorCodes.Index.ApprenticeshipDetails, result, parameters: lastViewedVacancyId)); } return(GetMediatorResponse(LoginMediatorCodes.Index.Ok, result)); } } return(GetMediatorResponse(LoginMediatorCodes.Index.LoginFailed, result, parameters: result.ViewModelMessage)); }
public MediatorResponse <LoginResultViewModel> Index(LoginViewModel viewModel) { var validationResult = _loginViewModelServerValidator.Validate(viewModel); if (!validationResult.IsValid) { return(GetMediatorResponse <LoginResultViewModel>(LoginMediatorCodes.Index.ValidationError, null, validationResult)); } var result = _candidateServiceProvider.Login(viewModel); if (result.UserStatus.HasValue) { if (result.UserStatus == UserStatuses.Locked) { _userDataProvider.Push(UserDataItemNames.UnlockEmailAddress, result.EmailAddress); return(GetMediatorResponse(LoginMediatorCodes.Index.AccountLocked, result)); } if (result.IsAuthenticated) { _logService.Info("User {0} successfully logged in. User Status: {1}", result.EmailAddress, result.UserStatus); _userDataProvider.SetUserContext(result.EmailAddress, result.FullName, result.AcceptedTermsAndConditionsVersion); if (result.UserStatus == UserStatuses.PendingActivation) { return(GetMediatorResponse(LoginMediatorCodes.Index.PendingActivation, result)); } var candidate = _candidateServiceProvider.GetCandidate(result.EmailAddress); SetUsersApplicationContext(candidate.EntityId); // Redirect to session return URL (if any). var returnUrl = _userDataProvider.Pop(UserDataItemNames.SessionReturnUrl) ?? _userDataProvider.Pop(UserDataItemNames.ReturnUrl); result.ReturnUrl = returnUrl; if (result.AcceptedTermsAndConditionsVersion != _configurationService.Get <CommonWebConfiguration>().TermsAndConditionsVersion) { return(returnUrl.IsValidReturnUrl() ? GetMediatorResponse(LoginMediatorCodes.Index.TermsAndConditionsNeedAccepted, result, parameters: returnUrl) : GetMediatorResponse(LoginMediatorCodes.Index.TermsAndConditionsNeedAccepted, result)); } if (returnUrl.IsValidReturnUrl()) { return(GetMediatorResponse(LoginMediatorCodes.Index.ReturnUrl, result, parameters: returnUrl)); } // Redirect to last viewed vacancy (if any). var lastViewedVacancy = _userDataProvider.PopLastViewedVacancy(); if (lastViewedVacancy != null) { switch (lastViewedVacancy.Type) { case VacancyType.Apprenticeship: { var applicationStatus = _candidateServiceProvider.GetApplicationStatus(candidate.EntityId, lastViewedVacancy.Id); if (applicationStatus.HasValue && applicationStatus.Value == ApplicationStatuses.Draft) { return(GetMediatorResponse(LoginMediatorCodes.Index.ApprenticeshipApply, result, parameters: lastViewedVacancy.Id)); } return(GetMediatorResponse(LoginMediatorCodes.Index.ApprenticeshipDetails, result, parameters: lastViewedVacancy.Id)); } case VacancyType.Traineeship: return(GetMediatorResponse(LoginMediatorCodes.Index.TraineeshipDetails, result, parameters: lastViewedVacancy.Id)); } } return(GetMediatorResponse(LoginMediatorCodes.Index.Ok, result)); } } return(GetMediatorResponse(LoginMediatorCodes.Index.LoginFailed, result, parameters: result.ViewModelMessage)); }