예제 #1
0
        public async Task <AuthorizationResult> GetAuthorizationResult(IReadOnlyCollection <string> options, IAuthorizationContext authorizationContext)
        {
            var authorizationResult = new AuthorizationResult();

            if (options.Count > 0)
            {
                options.EnsureNoAndOptions();
                options.EnsureNoOrOptions();

                var feature       = options.Single();
                var featureToggle = _featureTogglesService.GetFeatureToggle(feature);

                if (featureToggle.EnabledByAgreementVersion.GetValueOrDefault(0) > 0)
                {
                    var(accountId, _) = authorizationContext.GetEmployerFeatureValues();

                    var agreements = await _mediator.SendAsync(new GetEmployerAgreementsByAccountIdRequest { AccountId = accountId.GetValueOrDefault(0) }).ConfigureAwait(false);

                    var minAgreementVersion = agreements.EmployerAgreements.Select(ea => ea.AccountLegalEntity.SignedAgreementVersion.GetValueOrDefault(0)).Min();

                    if (minAgreementVersion < featureToggle.EnabledByAgreementVersion)
                    {
                        authorizationResult.AddError(new EmployerFeatureAgreementNotSigned());
                    }
                }
            }

            return(authorizationResult);
        }
        public virtual AuthorizationResult Authorize(OpenAuthenticationParameters parameters)
        {
            var userFound = _openAuthenticationService.GetUser(parameters);

            var userLoggedIn = _workContext.CurrentCustomer;

            if (AccountAlreadyExists(userFound, userLoggedIn))
            {
                _authenticationService.SignIn(userFound, false);
            }
            else
            {
                #region Register user

                var currentCustomer = _workContext.CurrentCustomer;
                var details         = new Nop.Plugin.ExternalAuth.Weixin.Authentication.External.RegistrationDetails(parameters);
                var randomPassword  = CommonHelper.GenerateRandomDigitCode(20);

                var registrationRequest = new CustomerRegistrationRequest(currentCustomer, string.Empty, details.UserName, randomPassword, PasswordFormat.Clear, _storeContext.CurrentStore.Id, true);

                var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest);
                if (registrationResult.Success)
                {
                    //store other parameters (form fields)
                    if (!String.IsNullOrEmpty(details.NickName))
                    {
                        _genericAttributeService.SaveAttribute(currentCustomer, SystemCustomerAttributeNames.FirstName, details.NickName);
                    }

                    userFound = currentCustomer;
                    _openAuthenticationService.AssociateExternalAccountWithUser(currentCustomer, parameters);
                    ExternalAuthorizerHelper.RemoveParameters();

                    //authenticate
                    _authenticationService.SignIn(userFound ?? userLoggedIn, false);
                }
                else
                {
                    ExternalAuthorizerHelper.RemoveParameters();

                    var result = new AuthorizationResult(OpenAuthenticationStatus.Error);
                    foreach (var error in registrationResult.Errors)
                    {
                        result.AddError(string.Format(error));
                    }

                    return(result);
                }
                #endregion
            }

            return(new AuthorizationResult(OpenAuthenticationStatus.Authenticated));
        }
예제 #3
0
        public void Arrange()
        {
            _query = new GetTransferConnectionInvitationAuthorizationQuery();
            var authResult = new AuthorizationResult();

            authResult.AddError(new EmployerFeatureAgreementNotSigned());
            _response = new GetTransferConnectionInvitationAuthorizationResponse {
                AuthorizationResult = authResult, IsValidSender = true, TransferAllowancePercentage = .25m
            };
            _mapperConfig = new MapperConfiguration(c => c.AddProfile <TransferMappings>());
            _mapper       = _mapperConfig.CreateMapper();
            _mediator     = new Mock <IMediator>();
            _mediator.Setup(m => m.SendAsync(_query)).ReturnsAsync(_response);

            _controller = new TransfersController(null, _mapper, _mediator.Object);
        }