Custom User Fields - Field Verification

Unsure if I’ve missed it, but the custom User Fields, you can set a field type, bu is their anyway to verify on these fields, such as for a mobile number or via regex so we can verify against any data?

If not currently, could this be added?

2 лайка

There isn’t much point in adding phone number verification. It’s easy for a bad actor to generate a bogus phone number with the right number of digits and highly annoying when a legitimate user has to guess what phone number format someone thinks is the right one.

1 лайк

That was just an example of one field, we have multiple fields to store such as memberships. And it we need some sort of verification that the information is even remotely correct. Currently for a phone number you can enter text.

We should be able to use regex to verify these fields or they are pretty useless.

2 лайка

Also, on the point of mobile numbers, yes they can be fake, but for our use case of the forum, its for their benefit that is correct. And being able to perform some sort of verification means that our scripts that would use them wouldn’t be affected by entering letters instead of numbers for example.

One the second point of different formats, that easy enough where you give the field a description field so you can let them know that. Verification of custom fields is a very basic requirement.

2 лайка

If you want that kind of detail consider an external membership platform and IdM.

This isn’t the kind of thing that discussion software should be doing.

1 лайк

Again, the point isn’t what I want to do with it, but more the fact that custom fields should be able to be verified.

There is no point in them if you can’t somehow verify the data going into them.

How much do you verify the name and identity of your users?

A lot, we’re a closed community. We are only able to verify on email at the moment compared to our current system, but as this can change on both sides, we want them to be able to enter a membership number and mobile and verify on both of those as well. At least if the verification of the field allows us to ensure the info entered is of the right type and length, our scripts using the API can handle the rest.

So you’re not talking about verifying anything, just validating that the data meets an expected format.

Discourse isn’t going to do this for you, you might be able to achieve validation with a plugin, but even then there’s nothing to prevent someone entering bad data in an expected format just to bypass said validation.

Your only real option is to look at something off-site or create a genuine incentive for users to provide real data. Right now you’re fixating on a symptom (not getting the data you want), not the root of the problem (giving users a real and compelling reason to provide it).

Наличие валидации было бы невероятно полезным — особенно для телефонных номеров, которые люди просто не могут ввести правильно из-за знака «+» в начале. Да, мы могли бы просто привести базу данных в порядок, но это крайне неудобно.

2 лайка

Согласен полностью. Пока вы можете проверять поля по формату, длине, количеству символов и даже разрешать регулярное выражение, которому поле должно соответствовать, это означает, что вы уверены в получении данных правильного типа, и скрипты API смогут обрабатывать их без ошибок.

Приношу извинения за позднее сообщение, но для тех, кто ищет в Meta информацию о том, как валидировать добавленные вами пользовательские поля, стоит упомянуть, как это сделать с помощью плагина.

В вашем файле plugin.rb используйте метод validate для модели User. Затем вы можете проверить свои пользовательские поля и установить ошибку, если какие-либо из них некорректны:

require_dependency 'user'

validate User, :my_cool_validation_method do
  field = self.custom_fields['cool_tapes']
  if ! field.blank? && field.include?("bag of four grapes")
    self.errors[:cool_tapes] << "No rhymes allowed."
  end
end

Примечание: символ :my_cool_validation_method может быть любым, но должен быть уникальным в контексте модели User.

10 лайков

Можно ли использовать это для валидации пользовательских пользовательских полей при регистрации и при их редактировании в профиле пользователя?

Также можно ли как-то разместить это в компоненте темы?

1 лайк