FEATURE: Use translated name for 'your email has been authenticated by' (#6649)

This commit is contained in:
David Taylor 2018-11-22 19:12:04 +00:00 committed by GitHub
parent 7e20a0b917
commit f645cb9c14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 13 deletions

View File

@ -147,13 +147,13 @@ export default Ember.Controller.extend(
); );
}.property("accountEmail", "authOptions.email", "authOptions.email_valid"), }.property("accountEmail", "authOptions.email", "authOptions.email_valid"),
authProviderDisplayName(provider) { authProviderDisplayName(providerName) {
switch (provider) { const matchingProvider = findAll().find(provider => {
case "Google_oauth2": return provider.name === providerName;
return "Google"; });
default: return matchingProvider
return provider; ? matchingProvider.get("prettyName")
} : providerName;
}, },
prefillUsername: function() { prefillUsername: function() {

View File

@ -64,8 +64,7 @@ class Auth::Result
else else
result = { email: email, result = { email: email,
username: UserNameSuggester.suggest(username || name || email), username: UserNameSuggester.suggest(username || name || email),
# this feels a tad wrong auth_provider: authenticator_name,
auth_provider: authenticator_name.capitalize,
email_valid: !!email_valid, email_valid: !!email_valid,
omit_username: !!omit_username } omit_username: !!omit_username }

View File

@ -125,7 +125,7 @@ RSpec.describe Users::OmniauthCallbacksController do
expect(response_body["email"]).to eq(email) expect(response_body["email"]).to eq(email)
expect(response_body["username"]).to eq("Some_name") expect(response_body["username"]).to eq("Some_name")
expect(response_body["auth_provider"]).to eq("Google_oauth2") expect(response_body["auth_provider"]).to eq("google_oauth2")
expect(response_body["email_valid"]).to eq(true) expect(response_body["email_valid"]).to eq(true)
expect(response_body["omit_username"]).to eq(false) expect(response_body["omit_username"]).to eq(false)
expect(response_body["name"]).to eq("Some Name") expect(response_body["name"]).to eq("Some Name")

View File

@ -33,9 +33,7 @@ describe "users/omniauth_callbacks/complete.html.erb" do
render render
expect(rendered_data["email"]).to eq(result.email) expect(rendered_data["email"]).to eq(result.email)
# TODO this is a bit weird, the upcasing is confusing, expect(rendered_data["auth_provider"]).to eq("CAS")
# clean it up throughout
expect(rendered_data["auth_provider"]).to eq("Cas")
end end
end end

View File

@ -84,3 +84,18 @@ QUnit.test("passwordValidation", function(assert) {
testInvalidPassword("porkchops", I18n.t("user.password.same_as_username")); testInvalidPassword("porkchops", I18n.t("user.password.same_as_username"));
testInvalidPassword("pork@chops.com", I18n.t("user.password.same_as_email")); testInvalidPassword("pork@chops.com", I18n.t("user.password.same_as_email"));
}); });
QUnit.test("authProviderDisplayName", function(assert) {
const controller = this.subject({ siteSettings: Discourse.SiteSettings });
assert.equal(
controller.authProviderDisplayName("facebook"),
I18n.t("login.facebook.name"),
"provider name is translated correctly"
);
assert.equal(
controller.authProviderDisplayName("idontexist"),
"idontexist",
"provider name falls back if not found"
);
});