示例#1
0
        public async Task <JwtAdto> PasswordAsync(PasswordAdto passwordAdto)
        {
            using (ITransaction transaction = _transactionManager.Create())
            {
                try
                {
                    if (!(await _authenticationServiceCommandRepository.GetSingleAsync(s => s is AuthenticationGrantTypePassword) is AuthenticationGrantTypePassword))
                    {
                        throw new BusinessApplicationException(ExceptionType.BadRequest, ErrorCodes.PasswordLoginNotConfigured, "Password logins are not configured");
                    }

                    Identity identity = await _passwordLoginCommand.ExecuteAsync(new PasswordLoginCommandDdto
                    {
                        Identifier = passwordAdto.Identifier,
                        Password   = passwordAdto.Password
                    });

                    await _identityCommandRepository.UpdateAsync(identity);

                    JwtAdto jwtAdto = await _jwtFactory.GenerateJwtAsync <JwtAdto>(GetClaimsIdentity(identity), identity.Session.Id);

                    transaction.Commit();

                    return(jwtAdto);
                }
                catch (InvalidLoginDomainException)
                {
                    throw new BusinessApplicationException(ExceptionType.BadRequest, ErrorCodes.InvalidLogin, "Your login details are incorrect");
                }
                catch (DomainValidationRuleException e)
                {
                    throw new BusinessValidationRuleApplicationException(e.ValidationResult);
                }
            }
        }
        public async Task <IActionResult> RegisterPassword(RegisterPasswordIdentityTemplate template)
        {
            PasswordAdto passwordAdto = await _identityApplicationService.RegisterPasswordAsync(new RegisterPasswordAdto
            {
                Identifier      = template.Identifier,
                Password        = template.Password,
                ConfirmPassword = template.ConfirmPassword,
                EmailAddress    = template.EmailAddress
            });

            return(Accepted(_resourceBuilder.Build(new RegisterPasswordResource
            {
                Id = passwordAdto.IdentityId
            })));
        }
        public async Task <IActionResult> ChangePassword(ChangePasswordIdentityTemplate template)
        {
            Guid identityId = _currentIdentityProvider.Id;

            PasswordAdto passwordAdto = await _identityApplicationService.ChangePasswordAsync(new ChangePasswordAdto
            {
                IdentityId      = identityId,
                Password        = template.Password,
                ConfirmPassword = template.ConfirmPassword,
                Version         = template.Version
            });

            return(Accepted(_resourceBuilder.Build(new ChangePasswordResource
            {
                Id = passwordAdto.IdentityId
            })));
        }
示例#4
0
 public Task <JwtAdto> PasswordAsync(PasswordAdto passwordAdto)
 {
     return(_securityApplicationService.SecureAsync(() => _authenticationApplicationService.PasswordAsync(passwordAdto),
                                                    DefaultAuthorisationContext.Create(AuthorisationResource.Authenticate, AuthorisationAction.Create)));
 }