Exemple #1
0
        public void RecalculateSavedAndDraftCount(Guid candidateId, IList <ApprenticeshipApplicationSummary> summaries)
        {
            var apprenticeshipApplicationSummaries = summaries ?? _candidateApplicationService.GetApprenticeshipApplications(candidateId) ?? new List <ApprenticeshipApplicationSummary>();
            var savedOrDraft = apprenticeshipApplicationSummaries.Count(a => a.Status == ApplicationStatuses.Draft || a.Status == ApplicationStatuses.Saved);

            _userDataProvider.Push(UserDataItemNames.SavedAndDraftCount, savedOrDraft.ToString(CultureInfo.InvariantCulture));
        }
 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);
     }));
 }
Exemple #3
0
        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 LoginResultViewModel Login(LoginViewModel model)
        {
            _logger.Debug("Calling CandidateServiceProvider to log the user {0}",
                          model.EmailAddress);

            try
            {
                var user = _userAccountService.GetUser(model.EmailAddress, false);

                if (user == null || user.Status == UserStatuses.PendingDeletion)
                {
                    return(GetAuthenticationFailedViewModel(model));
                }

                if (user.Status == UserStatuses.Locked)
                {
                    return(GetLoginResultViewModel(model, user.Status));
                }

                var candidate = _candidateService.Authenticate(model.EmailAddress, model.Password);

                if (candidate != null)
                {
                    // User is authentic.
                    _authenticationTicketService.SetAuthenticationCookie(candidate.EntityId.ToString(), _userAccountService.GetRoleNames(candidate.EntityId));

                    _userDataProvider.Push(UserDataItemNames.LastApplicationStatusNotification,
                                           user.LastLogin.HasValue ? user.LastLogin.Value.Ticks.ToString(CultureInfo.InvariantCulture) : DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture));

                    return(new LoginResultViewModel
                    {
                        EmailAddress = candidate.RegistrationDetails.EmailAddress,
                        FullName = candidate.RegistrationDetails.FirstName + " " + candidate.RegistrationDetails.LastName,
                        UserStatus = user.Status,
                        IsAuthenticated = true,
                        AcceptedTermsAndConditionsVersion = candidate.RegistrationDetails.AcceptedTermsAndConditionsVersion,
                        PhoneNumber = candidate.RegistrationDetails.PhoneNumber,
                        MobileVerificationRequired = candidate.MobileVerificationRequired(),
                        PendingUsernameVerificationRequired = user.PendingUsernameVerificationRequired()
                    });
                }

                user = _userAccountService.GetUser(model.EmailAddress);

                if (user.Status == UserStatuses.Locked)
                {
                    // Authentication failed, user just locked their account.
                    return(GetLoginResultViewModel(model, user.Status));
                }

                return(GetAuthenticationFailedViewModel(model, user.Status));
            }
            catch (Exception e)
            {
                _logger.Error("Candidate login failed for " + model.EmailAddress, e);

                return(new LoginResultViewModel(LoginPageMessages.LoginFailedErrorText)
                {
                    EmailAddress = model.EmailAddress
                });
            }
        }
Exemple #5
0
 public static void PushLastViewedVacancy(this IUserDataProvider userData, LastViewedVacancy lastViewedVacancy)
 {
     userData.Push(CandidateDataItemNames.LastViewedVacancy, string.Format("{0}_{1}", lastViewedVacancy.Type, lastViewedVacancy.Id));
 }
Exemple #6
0
        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));
        }