mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 01:56:58 +08:00
FIX: display email validation error messages
This commit is contained in:
@ -372,14 +372,21 @@ class UsersController < ApplicationController
|
|||||||
user_id: user.id
|
user_id: user.id
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
errors = user.errors.to_hash
|
||||||
|
errors[:email] = errors.delete(:primary_email) if errors[:primary_email]
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
success: false,
|
success: false,
|
||||||
message: I18n.t(
|
message: I18n.t(
|
||||||
'login.errors',
|
'login.errors',
|
||||||
errors: user.errors.full_messages.join("\n")
|
errors: user.errors.full_messages.join("\n")
|
||||||
),
|
),
|
||||||
errors: user.errors.to_hash,
|
errors: errors,
|
||||||
values: user.attributes.slice('name', 'username', 'email'),
|
values: {
|
||||||
|
name: user.name,
|
||||||
|
username: user.username,
|
||||||
|
email: user.primary_email&.email
|
||||||
|
},
|
||||||
is_developer: UsernameCheckerService.is_developer?(user.email)
|
is_developer: UsernameCheckerService.is_developer?(user.email)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -83,7 +83,7 @@ class User < ActiveRecord::Base
|
|||||||
validates :name, user_full_name: true, if: :name_changed?, length: { maximum: 255 }
|
validates :name, user_full_name: true, if: :name_changed?, length: { maximum: 255 }
|
||||||
validates :ip_address, allowed_ip_address: { on: :create, message: :signup_not_allowed }
|
validates :ip_address, allowed_ip_address: { on: :create, message: :signup_not_allowed }
|
||||||
validates :primary_email, presence: true
|
validates :primary_email, presence: true
|
||||||
validates_associated :primary_email
|
validates_associated :primary_email, message: -> (_, user_email) { user_email[:value]&.errors[:email]&.first }
|
||||||
|
|
||||||
after_initialize :add_trust_level
|
after_initialize :add_trust_level
|
||||||
|
|
||||||
|
@ -621,7 +621,7 @@ describe Admin::UsersController do
|
|||||||
|
|
||||||
xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload)
|
xhr :post, :sync_sso, Rack::Utils.parse_query(sso.payload)
|
||||||
expect(response.status).to eq(403)
|
expect(response.status).to eq(403)
|
||||||
expect(JSON.parse(response.body)["message"]).to include("Primary email is invalid")
|
expect(JSON.parse(response.body)["message"]).to include("Primary email can't be blank")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -584,7 +584,9 @@ describe User do
|
|||||||
|
|
||||||
it 'whitelist should reject some emails based on the email_domains_whitelist site setting' do
|
it 'whitelist should reject some emails based on the email_domains_whitelist site setting' do
|
||||||
SiteSetting.email_domains_whitelist = 'vaynermedia.com'
|
SiteSetting.email_domains_whitelist = 'vaynermedia.com'
|
||||||
expect(Fabricate.build(:user, email: 'notgood@mailinator.com')).not_to be_valid
|
user = Fabricate.build(:user, email: 'notgood@mailinator.com')
|
||||||
|
expect(user).not_to be_valid
|
||||||
|
expect(user.errors.messages[:primary_email]).to include(I18n.t('user.email.not_allowed'))
|
||||||
expect(Fabricate.build(:user, email: 'sbauch@vaynermedia.com')).to be_valid
|
expect(Fabricate.build(:user, email: 'sbauch@vaynermedia.com')).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user