Discourse 인증 유효성 검사

:discourse2: Summary Discourse Authentication Validations enables the ability to add custom validations to a User Field to toggle the display of User Fields on the Signup Modal.
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-authentication-validations
:open_book: Install Guide How to install plugins in Discourse

:information_source: About

Discourse Authentication Validations adds the ability to add custom validations to a User Field.

Custom User Fields do not have any type of validation provided by core, outside of detecting an empty value on a required field. This plugin adds the ability to define a regex, per user field, that will then be checked against the provided input value.

Additionally, this plugin adds the ability to toggle the display of User Fields on the Signup Modal. This allows you to “chain” User Fields together, so that a User Field is only displayed if a previous User Field has a specific value.

:building_construction: Basic Setup

1. Enable Plugin

The Discourse Authentication Validations plugin can be enabled either by the toggle or from its settings, both accessible from your admin/plugins page.

2. Add a custom validation to a User Field

After the Discourse Authentication Validations plugin has been enabled you will see a Include a Custom Validations checkbox at the bottom of your User Field form.

When checked it will display an additional three fields:

  1. Value Validation Regex
  2. Show Values
  3. Target User Fields

:closed_lock_with_key: Adding a Custom Validation

Include a valid regex in the Value Validation Regex field:

The user field’s value on the signup form will now be tested against the regex you have included. In the case that the input does not meet the standards of your custom Regex, the signup form will not submit.

No value (relies on default form validation)

Incorrect value

Correct value

:link: Chaining User Fields

Firstly, include a Show Values value on a User Field.

When a User Field has a Show Values value included it will watch the value of the attached input until the input value matches ANY of the show values. It will then toggle the visibility of any included Target User Fields, making them visible.

Secondly, add a Target User Fields value.

In the Target User Fields dropdown you will see a list of all available User Fields. Any User Field you select will have their visibility toggled by corresponding values in Show Values.

:hammer_and_wrench: Advanced Chaining

You can chain User Fields together by adding custom validations to multiple User Fields.

For example, let’s say we have three User Fields with the given values:

Name Has Custom Validation Show Values Target User Fields
Input One true show-field-two Input Two
Input Two true show-field-three Input Three
Input Three false

Input Two and Three will be hidden by default as they are “children” of Input One. When the show value of show-field-two is added to Input One, Input Two will be displayed, but Input Three will still remain hidden. It will remain hidden until Input Two has the value of show-field-three.

With the correct combination of Show Values and Target Classes you can infinitely nest User Fields beneath each other.

18개의 좋아요

Hello @isaac.

I love this plugin, it’s exactly what I need! Is this still being maintained? I am having trouble with the “chaining” functionality.

I followed the example above using:

But it is showing all the fields by default… I apologize if I missed something in the writeup!

1개의 좋아요

My apologies for this - the plugin is working. However, it does not work if you are viewing through an “invite” sign up link. It does work if you are using a public signup page.

Could be a nice feature to have the logic work for both invite and public sign up!

Great job with the plugin!

6개의 좋아요

I very much agree. @tobiaseigen if we were to adopt this plugin as a feature more broadly, we would want to have the logic work in both places (public/invite) as @kravitsjacob has pointed out.

3개의 좋아요

Hello @isaac. Thank you once again for this amazing plugin - it really has opened up so many discourse opportunities for me.

I ran into a little bug - I noticed that question responses are saved, even if a question is hidden. This has led to a few unintended situations where users are submitting response that shouldn’t really be possible (hence why we wanted to hide the questions in the first place). This behavior also causes another situation where when a question is double nested, it still appears even though the parent response has been deselected (because it still thinks the triggering answer is selected). I know this description is a big vague, so here is a gif highlighting this behavior:

auth null bug

I think my desired fix would be to reset the responses to the null value once they are no longer visible. This could also be “opt-in” behavior that is configurable by the person setting up the form - I could see different philosophies existing on whether responses should persist when going down these trees.

Would you be able to implement this? :pray:

5개의 좋아요

Thank you for the detailed response! I will take a look at this next week :slight_smile:

4개의 좋아요

I had the opportunity to look at these issues today :slight_smile:

https://github.com/discourse/discourse-authentication-validations/pull/23

Please read the PR description for details!

3개의 좋아요

It is currently impossible to have an optional required field.

I have a field “Industry” and whenever “Other” is being selected, it unhides the “Other Industry” field.

But when I make the “Other Industry” field required, I am unable to submit the form when that field is hidden.

When I manually unhide the div you can see that it is requiring this input, even though the form is hidden.

When I select “Other”, fill in a value, and then select another industry so the input becomes hidden again, I can submit the form. And then also the same situation happens as @kravitsjacob pointed out: the value of the “Other Industry” field is saved to the users profile, even though “Industry” is not set to “Other”.

User Admin:

3개의 좋아요

안녕하세요 @RGJ, 필수 필드 관련 문제를 해결하셨나요? 저도 같은 문제를 겪고 있습니다.
@isaac 이 문제에 대한 우회 방법이 있을까요? 표시 조건이 충족될 때 필수로 설정해야 하는 필드가 있습니다.

1개의 좋아요

아니요, 아직 이 건에 대해 답변을 받지 못했고, 나 역시 시간을 들여 확인해 보지 않았습니다.

@RGJ, 빠른 답변 감사합니다.

원본 저장소에 문제를 해결할 수 있는 수정이 포함된 PR을 방금 생성했습니다.

여기서 가장 큰 도전 과제는 검증이 프론트엔드와 백엔드라는 두 곳에서 실행된다는 점이었습니다. 따라서 각각에 대한 솔루션을 별도로 구현하고, 예상대로 작동하는지 확인해야 했습니다.

이 내용이 향후 누군가에게 도움이 되기를 바랍니다.

1개의 좋아요

각 필드별로 하나의 값이 아닌 필드 값마다 조건부 필드 로직을 추가하는 추가 PR을 추가했습니다. 이는 보유 중인 필드의 값에 따라 다른 필드를 숨기거나 표시할 수 있음을 의미합니다.

JSONB를 저장하는 새 컬럼에 대해 데이터베이스에 저장되는 방식을 미리 볼 수도 있습니다.

2개의 좋아요

이것이 검색 가능한 필드에 어떤 영향을 미치나요?

검색 대상으로 설정한 사용자 정의 필드가 사이트의 사용자 디렉터리 설정 메뉴에 표시되지 않습니다. 대신 해당 필드에 연결된 세 개의 조건부 필드만 표시됩니다. 이 세 필드는 자체적으로 검색 대상으로 설정되어 있지 않습니다.

안녕하세요.
죄송합니다만, 아직 사용자 사용자 정의 필드와 관련된 Discourse의 모든 로직을 파악하지 못해 질문을 정확히 이해했는지 확신이 서지 않습니다.

제가 알고 있는 바로는 Searchable은 필드가 인덱싱되도록 표시하고 포털의 다른 부분에서 사용할 수 있으며, 아직 이 부분을 다루어 본 적 없고 올바르게 구성하는 방법에 대해 잘 모르겠습니다.

이론적으로 조건부 필드는 Searchable 필드에 어떤 영향도 주지 않아야 하며, Autocomplete를 사용하여 값을 붙여 넣을 때도 UserField 요소에 값을 연결하기 때문에 로직이 여전히 작동해야 합니다.

질문에 대해 좀 더 자세한 내용을 추가해 주시거나 스크린샷을 첨부해 주시면 도움이 될 것 같습니다.

말씀을 명확히 하지 못했나 봅니다. 제 질문은 OP와 플러그인 전체에 대한 것이었습니다. 혼란을 드려 죄송합니다.

플러그인의 나머지 로직은 정상적으로 작동하지만, 아래 첫 번째 스크린샷의 상단 필드 값에 따라 표시되는 3개의 필드가 있습니다. 그런데 사용자 디렉터리 설정에서는 원래 검색 대상으로 지정된 필드 대신 이 3개의 종속 필드만 표시됩니다:

스크린샷


1개의 좋아요

이 기능을 사용하여 연령 검증을 하고 18세 미만 사용자의 가입을 차단할 수 있을까요? 사용자가 생년월일을 거짓으로 입력할 수 있다는 점은 알고 있지만, 일단 검증 자체가 가능한지 궁금합니다.