public async Task <ApiResponse <RegisterResponse> > Register(RegisterRequest registerRequest) { var existingTenant = await _tenantService.GetTenantByHostname(registerRequest.Appname); if (existingTenant != null) { return(ApiResponse <RegisterResponse> .Error(ErrorProvider.GetErrorMessage("no_tenant"))); } if (registerRequest.Password != registerRequest.PasswordAgain) { return(ApiResponse <RegisterResponse> .Error()); //ErrorProvider.GetError("register_password_mismatch") } var existingUser = _hostRepository.Get <Tenant>(t => t.Responsibles.Any(r => r.Email == registerRequest.Email) , includeProperties: "Responsibles").FirstOrDefault(); if (existingUser != null) { return(ApiResponse <RegisterResponse> .Error()); //ErrorProvider.GetError("register_email_in_use") } Tenant tenant = await CreatePoteantialTenant(registerRequest); await ComposeEmailVerificationEmail(tenant); return(ApiResponse <RegisterResponse> .Success()); }
public sealed override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (ValidationPipe != null) { // Pass if another validator has already reported an error. if (ValidationPipe.Error != null) { return(ValidationResult.ValidResult); } // Checking this later might be a tiny bit faster. if (!IsEnforced.Value) { return(ValidationResult.ValidResult); } var isValid = ValidateValue(ValueConverter != null ? ValueConverter.Convert(value, typeof(object), null, cultureInfo) : value, cultureInfo); if (!isValid) { var error = ErrorProvider.GetErrorMessage(value); if (StrictValidation) { // If we're going to stop propagation, we need to make sure // that the pipe is clean for the next turn. ValidationPipe.Error = null; return(new ValidationResult(false, error)); } ValidationPipe.Error = error; } return(ValidationResult.ValidResult); } else { if (!IsEnforced.Value) { return(ValidationResult.ValidResult); } // When there's no pipe validation must return eagerly. // Properties will not be updated this way as validation will stop binding. var isValid = ValidateValue(ValueConverter != null ? ValueConverter.Convert(value, typeof(object), null, cultureInfo) : value, cultureInfo); return(isValid ? ValidationResult.ValidResult : new ValidationResult(false, ErrorProvider.GetErrorMessage(value))); } }
public async Task <ApiResponse <LoginResponse> > Authenticate(LoginRequest loginRequest) { var user = await _userManager.FindByEmailAsync(loginRequest.Username); if (user != null) { var result = await _signInManager.PasswordSignInAsync(user, loginRequest.Password, true, false); if (result.Succeeded) { var roles = await _userManager.GetRolesAsync(user); var permissions = await _roleService.GetRolesPermissions(roles.ToArray(), user.TenantId); var tenant = await _tenantService.GetTenantById(user.TenantId); user.Tenant = tenant; var authResponse = await _jwtTokenFactory.GenerateAuthResponseForUser(user); var userDto = Mapper.Map <UserDto>(user); userDto.PermittedPages = Mapper.Map <List <PageDto> >(permissions.Value.SelectMany(m => m.Pages)); userDto.Tenant = Mapper.Map <TenantDto>(user.Tenant); var loginResponse = new LoginResponse { AccessToken = authResponse.AccessToken.Token, RefreshToken = authResponse.RefreshToken, User = userDto }; return(ApiResponse <LoginResponse> .Success(loginResponse)); } else { return(ApiResponse <LoginResponse> .Error()); //ErrorProvider.GetError("auth_invalid_user_pass") } } else { return(ApiResponse <LoginResponse> .Error(ErrorProvider.GetErrorMessage("auth_user_not_found"))); } }