public MediatorResponse <AgencyUserViewModel> Authorize(ClaimsPrincipal principal) { var viewModel = new AgencyUserViewModel(); if (string.IsNullOrEmpty(principal?.Identity?.Name)) { return(GetMediatorResponse(AgencyUserMediatorCodes.Authorize.EmptyUsername, viewModel, AuthorizeMessages.EmptyUsername, UserMessageLevel.Error)); } var authorisationGroupClaim = _configurationService.Get <ManageWebConfiguration>().AuthorisationGroupClaim; if (!principal.IsInGroup(authorisationGroupClaim)) { return(GetMediatorResponse(AgencyUserMediatorCodes.Authorize.MissingServicePermission, viewModel, AuthorizeMessages.MissingServicePermission, UserMessageLevel.Error)); } var username = principal.Identity.Name; viewModel = _agencyUserProvider.GetOrCreateAgencyUser(username); // Redirect to session return URL (if any). var returnUrl = _userDataProvider.Pop(UserDataItemNames.ReturnUrl); if (returnUrl.IsValidReturnUrl()) { return(GetMediatorResponse(AgencyUserMediatorCodes.Authorize.ReturnUrl, viewModel, parameters: returnUrl)); } return(GetMediatorResponse(AgencyUserMediatorCodes.Authorize.Ok, viewModel)); }
public async Task <ActionResult> DismissApplicationNotifications(long lastupdated) { return(await Task.Run <ActionResult>(() => { var utcDateTime = new DateTime(lastupdated + 1, DateTimeKind.Utc); _userDataProvider.Push(UserDataItemNames.LastApplicationStatusNotification, utcDateTime.Ticks.ToString(CultureInfo.InvariantCulture)); _userDataProvider.Pop(UserDataItemNames.ApplicationStatusChangeCount); return RedirectToRoute(CandidateRouteNames.MyApplications); })); }
public static LastViewedVacancy PopLastViewedVacancy(this IUserDataProvider userData) { var lastViewedVacancyId = userData.Pop(CandidateDataItemNames.LastViewedVacancy); if (string.IsNullOrEmpty(lastViewedVacancyId) || !lastViewedVacancyId.Contains("_")) { return(null); } var lastViewedVacancyComponents = lastViewedVacancyId.Split('_'); var vacancyType = (VacancyType)Enum.Parse(typeof(VacancyType), lastViewedVacancyComponents[0]); var vacancyId = int.Parse(lastViewedVacancyComponents[1]); return(new LastViewedVacancy { Type = vacancyType, Id = vacancyId }); }
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)); }