decidim-friendly_signup 0.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +35 -0
- data/app/packs/src/decidim/friendly_signup/lib/instant_validator.js +7 -1
- data/app/views/decidim/devise/invitations/edit.html.erb +8 -6
- data/app/views/decidim/devise/passwords/edit.html.erb +2 -2
- data/app/views/decidim/devise/registrations/new.html.erb +5 -5
- data/app/views/decidim/devise/sessions/new.html.erb +58 -0
- data/app/views/decidim/friendly_signup/confirmation_codes/index.html.erb +1 -1
- data/app/views/decidim/friendly_signup/confirmation_codes_mailer/confirmation_instructions.html.erb +3 -3
- data/config/locales/en.yml +20 -0
- data/lib/decidim/friendly_signup/engine.rb +4 -2
- data/lib/decidim/friendly_signup/user_attribute_validator.rb +34 -5
- data/lib/decidim/friendly_signup/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4759703c0e6890c53f828d2db7be0ab349ca526cbe6d064d9d5b809e9429aea7
|
4
|
+
data.tar.gz: 6854425281b3d148d6cba8e8ed8d3b91ba3ae462a32b08d4b51540ac995c676f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aca757d63345ea7c3e0207809ccbe744dc976d056ff8f2c860b49af82842f7610ec5f4e5b381d1fd3e8355b0c461995c3f4dc054d5adb1f9fae987fd994fb409
|
7
|
+
data.tar.gz: 975dae306e8db7c651e597c7c83aa2bc59c5ae7b16109cc2e0969a307aa9bc575e01a17fe35249cfe772b97e01115871539688e6e9059db5bfdbdc5e1bf89c98
|
data/README.md
CHANGED
@@ -90,6 +90,41 @@ Decidim::FriendlySignup.configure do |config|
|
|
90
90
|
end
|
91
91
|
```
|
92
92
|
|
93
|
+
### Customize error messages in instant validation
|
94
|
+
|
95
|
+
You can customize any message either overriding in your application the files in `config/locales/*.yml` or by using a module like Term Customizer.
|
96
|
+
|
97
|
+
This plugin uses a cascade-style fallback looking for a series of I18n keys and returns the first available. For instance, for the attribute `email` and the validation key `blank` it will look for these 3 possibilities, returning the first matching one:
|
98
|
+
|
99
|
+
Specific attribute error:
|
100
|
+
```yaml
|
101
|
+
en:
|
102
|
+
decidim:
|
103
|
+
friendly_signup:
|
104
|
+
errors:
|
105
|
+
messages:
|
106
|
+
email:
|
107
|
+
blank: Please enter an email address
|
108
|
+
```
|
109
|
+
|
110
|
+
Generic error:
|
111
|
+
```yaml
|
112
|
+
en:
|
113
|
+
decidim:
|
114
|
+
friendly_signup:
|
115
|
+
errors:
|
116
|
+
messages:
|
117
|
+
blank: Looks like you haven’t entered anything in this field
|
118
|
+
```
|
119
|
+
|
120
|
+
Rails' default error:
|
121
|
+
```yaml
|
122
|
+
en:
|
123
|
+
errors:
|
124
|
+
messages:
|
125
|
+
blank: can't be blank
|
126
|
+
```
|
127
|
+
|
93
128
|
## Contributing
|
94
129
|
|
95
130
|
Bug reports and pull requests are welcome on GitHub at https://github.com/OpenSourcePolitics/decidim-module-friendly_signup.
|
@@ -53,10 +53,15 @@ export default class InstantValidator {
|
|
53
53
|
}
|
54
54
|
|
55
55
|
validate($input) {
|
56
|
+
let $recheck = $($input.data("instantRecheck"));
|
56
57
|
this.tamper($input);
|
57
58
|
this.post($input).done((response) => {
|
58
59
|
this.setFeedback(response, $input);
|
59
60
|
});
|
61
|
+
|
62
|
+
if ($recheck.length && this.isTampered($recheck)) {
|
63
|
+
this.validate($recheck)
|
64
|
+
}
|
60
65
|
}
|
61
66
|
|
62
67
|
setFeedback(data, $input) {
|
@@ -76,13 +81,14 @@ export default class InstantValidator {
|
|
76
81
|
}
|
77
82
|
|
78
83
|
addErrors($dest, msg) {
|
84
|
+
console.log("$dest", $dest, "%form", this.$form)
|
79
85
|
if ($dest.closest("label").find(".form-error").length > 1) {
|
80
86
|
// Decidim may add and additional error class that does not play well with abide
|
81
87
|
$dest.closest("label").find(".form-error:last").remove();
|
82
88
|
}
|
83
89
|
this.$form.foundation("addErrorClasses", $dest);
|
84
90
|
if (msg) {
|
85
|
-
$dest.closest("label").find(".form-error").
|
91
|
+
$dest.closest("label").find(".form-error").html(msg);
|
86
92
|
}
|
87
93
|
}
|
88
94
|
|
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
<div class="row">
|
12
12
|
<div class="columns large-6 medium-10 medium-centered">
|
13
|
-
<%= decidim_form_for
|
13
|
+
<%= decidim_form_for(resource, namespace: "invitation", as: resource_name, url: invitation_path(resource_name, invite_redirect: params[:invite_redirect]), html: { method: :put, class: "register-form new_user#{friendly_override_activated?(:use_instant_validation) ? ' instant-validation' : ''}" } , data: { "validation-url" => decidim_friendly_signup.validate_path }) do |f| %>
|
14
14
|
<div class="card">
|
15
15
|
<div class="card__content">
|
16
16
|
<legend><%= t("sign_up_as.legend", scope: "decidim.devise.registrations.new") %></legend>
|
@@ -19,14 +19,16 @@
|
|
19
19
|
|
20
20
|
<%= f.hidden_field :invitation_token %>
|
21
21
|
|
22
|
-
|
23
|
-
<div class="
|
24
|
-
|
22
|
+
<% unless friendly_override_activated?(:hide_nickname) %>
|
23
|
+
<div class="user-nickname">
|
24
|
+
<div class="field">
|
25
|
+
<%= f.text_field :nickname, help_text: t("devise.invitations.edit.nickname_help", organization: current_organization.name), required: "required", prefix: { value: "@", small: 1, large: 1 }, data: { "instant-attribute" => "nickname", "instant-recheck" => "password" } %>
|
26
|
+
</div>
|
25
27
|
</div>
|
26
|
-
|
28
|
+
<% end %>
|
27
29
|
|
28
30
|
<% if f.object.class.require_password_on_accepting %>
|
29
|
-
<%= render("decidim/friendly_signup/shared/password_fields", form: f, options: { required: "
|
31
|
+
<%= render("decidim/friendly_signup/shared/password_fields", form: f, options: { required: true, autocomplete: "off", help_text: t("devise.passwords.edit.password_help", minimun_characters: ::PasswordValidator::MINIMUM_LENGTH), minlength: ::PasswordValidator::MINIMUM_LENGTH, maxlength: ::PasswordValidator::MAX_LENGTH, data: { "instant-attribute" => "password" } }) %>
|
30
32
|
<% end %>
|
31
33
|
</div>
|
32
34
|
</div>
|
@@ -10,12 +10,12 @@
|
|
10
10
|
<div class="columns medium-7 large-5 medium-centered">
|
11
11
|
<div class="card">
|
12
12
|
<div class="card__content">
|
13
|
-
<%= decidim_form_for(resource, namespace: "password", as: resource_name, url: password_path(resource_name), html: { method: :put, class: "register-form new_user" }) do |f| %>
|
13
|
+
<%= decidim_form_for(resource, namespace: "password", as: resource_name, url: password_path(resource_name), html: { method: :put, class: "register-form new_user#{friendly_override_activated?(:use_instant_validation) ? ' instant-validation' : ''}" } , data: { "validation-url" => decidim_friendly_signup.validate_path }) do |f| %>
|
14
14
|
<%= form_required_explanation %>
|
15
15
|
|
16
16
|
<%= f.hidden_field :reset_password_token %>
|
17
17
|
|
18
|
-
<%= render("decidim/friendly_signup/shared/password_fields", form: f, options: { autocomplete: "off", help_text: t("devise.passwords.edit.password_help", minimun_characters: ::PasswordValidator::MINIMUM_LENGTH) }) %>
|
18
|
+
<%= render("decidim/friendly_signup/shared/password_fields", form: f, options: { required: true, autocomplete: "off", help_text: t("devise.passwords.edit.password_help", minimun_characters: ::PasswordValidator::MINIMUM_LENGTH), minlength: ::PasswordValidator::MINIMUM_LENGTH, maxlength: ::PasswordValidator::MAX_LENGTH, data: { "instant-attribute" => "password" } }) %>
|
19
19
|
|
20
20
|
<div class="actions">
|
21
21
|
<%= f.submit t("devise.passwords.edit.change_my_password"), class: "button expanded" %>
|
@@ -26,7 +26,7 @@
|
|
26
26
|
<div class="row">
|
27
27
|
<div class="columns large-6 medium-10 medium-centered">
|
28
28
|
|
29
|
-
<%= decidim_form_for(@form, namespace: "registration", as: resource_name, url: registration_path(resource_name), html: { class: "register-form new_user#{friendly_override_activated?(:use_instant_validation)
|
29
|
+
<%= decidim_form_for(@form, namespace: "registration", as: resource_name, url: registration_path(resource_name), html: { class: "register-form new_user#{friendly_override_activated?(:use_instant_validation) ? ' instant-validation' : ''}", id: "register-form" }, data: { "validation-url" => decidim_friendly_signup.validate_path }) do |f| %>
|
30
30
|
<%= invisible_captcha %>
|
31
31
|
<div class="card">
|
32
32
|
<div class="card__content">
|
@@ -34,23 +34,23 @@
|
|
34
34
|
|
35
35
|
<div class="user-person">
|
36
36
|
<div class="field">
|
37
|
-
<%= f.text_field :name, help_text: t(".username_help"), autocomplete: "off", data: { "instant-attribute"
|
37
|
+
<%= f.text_field :name, help_text: t(".username_help"), autocomplete: "off", data: { "instant-attribute" => "name", "instant-recheck" => "#registration_user_password" } %>
|
38
38
|
</div>
|
39
39
|
</div>
|
40
40
|
|
41
41
|
<% unless friendly_override_activated?(:hide_nickname) %>
|
42
42
|
<div class="user-nickname">
|
43
43
|
<div class="field">
|
44
|
-
<%= f.text_field :nickname, help_text: t(".nickname_help", organization: current_organization.name), prefix: { value: "@", small: 1, large: 1 }, autocomplete: "off", data: { "instant-attribute"
|
44
|
+
<%= f.text_field :nickname, help_text: t(".nickname_help", organization: current_organization.name), prefix: { value: "@", small: 1, large: 1 }, autocomplete: "off", data: { "instant-attribute" => "nickname", "instant-recheck" => "#registration_user_password" } %>
|
45
45
|
</div>
|
46
46
|
</div>
|
47
47
|
<% end %>
|
48
48
|
|
49
49
|
<div class="field">
|
50
|
-
<%= f.email_field :email, autocomplete: "email", data: { "instant-attribute"
|
50
|
+
<%= f.email_field :email, autocomplete: "email", data: { "instant-attribute" => "email", "instant-recheck" => "#registration_user_password" } %>
|
51
51
|
</div>
|
52
52
|
|
53
|
-
<%= render("decidim/friendly_signup/shared/password_fields", form: f, options: { required: true, help_text: t(".password_help", minimun_characters: ::PasswordValidator::MINIMUM_LENGTH), autocomplete: "off", data: { "instant-attribute"
|
53
|
+
<%= render("decidim/friendly_signup/shared/password_fields", form: f, options: { required: true, help_text: t(".password_help", minimun_characters: ::PasswordValidator::MINIMUM_LENGTH), autocomplete: "off", data: { "instant-attribute" => "password" } }) %>
|
54
54
|
</div>
|
55
55
|
</div>
|
56
56
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<% add_decidim_page_title(t("devise.sessions.new.sign_in")) %>
|
2
|
+
|
3
|
+
<div class="wrapper">
|
4
|
+
<div class="row collapse">
|
5
|
+
<div class="row collapse">
|
6
|
+
<div class="columns large-8 large-centered text-center page-title">
|
7
|
+
<h1><%= t("devise.sessions.new.sign_in") %></h1>
|
8
|
+
<% if current_organization.sign_up_enabled? %>
|
9
|
+
<p>
|
10
|
+
<%= t(".are_you_new?") %>
|
11
|
+
<%= link_to t(".register"), new_user_registration_path %>
|
12
|
+
</p>
|
13
|
+
<% elsif current_organization.sign_in_enabled? %>
|
14
|
+
<p>
|
15
|
+
<%= t(".sign_up_disabled") %>
|
16
|
+
</p>
|
17
|
+
<% else %>
|
18
|
+
<p>
|
19
|
+
<%= t(".sign_in_disabled") %>
|
20
|
+
</p>
|
21
|
+
<% end %>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
<% cache current_organization do %>
|
25
|
+
<%= render "decidim/devise/shared/omniauth_buttons" %>
|
26
|
+
<% end %>
|
27
|
+
|
28
|
+
<% if current_organization.sign_in_enabled? %>
|
29
|
+
<div class="row">
|
30
|
+
<div class="columns large-6 medium-centered">
|
31
|
+
<div class="card">
|
32
|
+
<div class="card__content">
|
33
|
+
<%= decidim_form_for(resource, namespace: "session", as: resource_name, url: session_path(resource_name), html: { class: "register-form new_user" }) do |f| %>
|
34
|
+
<div>
|
35
|
+
<div class="field">
|
36
|
+
<%= f.email_field :email %>
|
37
|
+
</div>
|
38
|
+
<div class="field">
|
39
|
+
<%= render("decidim/friendly_signup/shared/password_fields", form: f, options: { autocomplete: "off" }) %>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
<% if devise_mapping.rememberable? %>
|
43
|
+
<div class="field">
|
44
|
+
<%= f.check_box :remember_me %>
|
45
|
+
</div>
|
46
|
+
<% end %>
|
47
|
+
<div class="actions">
|
48
|
+
<%= f.submit t("devise.sessions.new.sign_in"), class: "button expanded" %>
|
49
|
+
</div>
|
50
|
+
<% end %>
|
51
|
+
<%= render "decidim/devise/shared/links" %>
|
52
|
+
</div>
|
53
|
+
</div>
|
54
|
+
</div>
|
55
|
+
</div>
|
56
|
+
<% end %>
|
57
|
+
</div>
|
58
|
+
</div>
|
@@ -28,7 +28,7 @@
|
|
28
28
|
<% end %>
|
29
29
|
|
30
30
|
<p class="text-center">
|
31
|
-
<%= link_to t(".code_not_received"), decidim.user_confirmation_path(confirmation_token: confirmation_form.confirmation_token, "user[email]"
|
31
|
+
<%= link_to t(".code_not_received"), decidim.user_confirmation_path(confirmation_token: confirmation_form.confirmation_token, "user[email]" => user.email), method: :post, data: { confirm: t(".confirm_send_code", email: user.email) } %>
|
32
32
|
</p>
|
33
33
|
</div>
|
34
34
|
</div>
|
data/app/views/decidim/friendly_signup/confirmation_codes_mailer/confirmation_instructions.html.erb
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
<h3 class="email-instruction text-center" style="margin:1em 0 0.2em 0;"><%= t(".copy") %></h3>
|
6
6
|
|
7
|
+
<p class="stat text-center" style="margin:1em 0 0.5em 0;"><b style="font-size: 2em"><%= @code %></b></p>
|
8
|
+
|
7
9
|
<% if @expires_at %>
|
8
|
-
<p class="email-small text-center"><%= t(".expires_in", time: distance_of_time_in_words(Time.now, @expires_at, scope: "decidim.friendly_signup.datetime.distance_in_words")) %></p>
|
10
|
+
<p class="email-small text-center" style="margin-bottom: 2em;"><%= t(".expires_in", time: distance_of_time_in_words(Time.now, @expires_at, scope: "decidim.friendly_signup.datetime.distance_in_words")) %></p>
|
9
11
|
<% end %>
|
10
12
|
|
11
|
-
<p class="stat text-center" style="margin:1em 0;"><b style="font-size: 2em"><%= @code %></b></p>
|
12
|
-
|
13
13
|
<p class="email-small email-closing text-center"><%= t(".ignore").html_safe %></p>
|
data/config/locales/en.yml
CHANGED
@@ -74,6 +74,26 @@ en:
|
|
74
74
|
x_seconds:
|
75
75
|
one: 1 second
|
76
76
|
other: "%{count} seconds"
|
77
|
+
errors:
|
78
|
+
messages:
|
79
|
+
blank: Looks like you haven’t entered anything in this field
|
80
|
+
email:
|
81
|
+
blank: Please enter an email address
|
82
|
+
invalid: The email address looks incomplete
|
83
|
+
taken: This email is already in use for another account. Try signing in
|
84
|
+
or use another email
|
85
|
+
password:
|
86
|
+
email_included_in_password: The password you have entered is too similar
|
87
|
+
to your email
|
88
|
+
name_included_in_password: The password you have entered is too similar
|
89
|
+
to your name
|
90
|
+
nickname_included_in_password: The password you have entered is too similar
|
91
|
+
to your nickname
|
92
|
+
not_enough_unique_characters: The password you have entered does not have
|
93
|
+
enough different characters
|
94
|
+
password_too_common: The password you have entered is very common - we
|
95
|
+
suggest using a different password
|
96
|
+
password_too_short: The password you have entered is too short
|
77
97
|
shared:
|
78
98
|
password_fields:
|
79
99
|
hidden_password: Your password is hidden
|
@@ -15,17 +15,19 @@ module Decidim
|
|
15
15
|
resources :confirmation_codes, only: [:index, :create]
|
16
16
|
end
|
17
17
|
post :validate, to: "validator#validate"
|
18
|
+
put :validate, to: "validator#validate"
|
18
19
|
end
|
19
20
|
|
20
21
|
# Prepare a zone to create overrides
|
21
22
|
# https://edgeguides.rubyonrails.org/engines.html#overriding-models-and-controllers
|
22
23
|
# overrides
|
23
24
|
config.after_initialize do
|
25
|
+
Decidim::Devise::SessionsController.include(Decidim::FriendlySignup::NeedsHeaderSnippets)
|
24
26
|
Decidim::Devise::RegistrationsController.include(Decidim::FriendlySignup::NeedsHeaderSnippets)
|
27
|
+
Decidim::Devise::PasswordsController.include(Decidim::FriendlySignup::NeedsHeaderSnippets)
|
28
|
+
Decidim::Devise::InvitationsController.include(Decidim::FriendlySignup::NeedsHeaderSnippets)
|
25
29
|
Decidim::Devise::RegistrationsController.include(Decidim::FriendlySignup::RegistrationsRedirect)
|
26
30
|
Decidim::Devise::ConfirmationsController.include(Decidim::FriendlySignup::RegistrationsRedirect)
|
27
|
-
Decidim::Devise::InvitationsController.include(Decidim::FriendlySignup::NeedsHeaderSnippets)
|
28
|
-
Decidim::Devise::PasswordsController.include(Decidim::FriendlySignup::NeedsHeaderSnippets)
|
29
31
|
Decidim::AccountController.include(Decidim::FriendlySignup::NeedsHeaderSnippets)
|
30
32
|
Decidim::RegistrationForm.include(Decidim::FriendlySignup::AutoNickname)
|
31
33
|
Decidim::User.include(Decidim::FriendlySignup::NeedsRegistrationCodes)
|
@@ -28,11 +28,44 @@ module Decidim
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def error
|
31
|
-
|
31
|
+
return if valid?
|
32
|
+
|
33
|
+
errors.map do |msg|
|
34
|
+
key = find_key(msg)
|
35
|
+
next if key == :nickname_included_in_password && FriendlySignup.hide_nickname.present?
|
36
|
+
|
37
|
+
custom_error(key).presence || msg.upcase_first
|
38
|
+
end.join(".<br>")
|
32
39
|
end
|
33
40
|
|
34
41
|
private
|
35
42
|
|
43
|
+
def custom_error(key)
|
44
|
+
return if key.blank?
|
45
|
+
|
46
|
+
generic = I18n.t(key, scope: "decidim.friendly_signup.errors.messages", default: "")
|
47
|
+
I18n.t("#{attribute}.#{key}", scope: "decidim.friendly_signup.errors.messages", default: generic)
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_key(msg)
|
51
|
+
case attribute
|
52
|
+
when "password"
|
53
|
+
[:blacklisted,
|
54
|
+
:domain_included_in_password,
|
55
|
+
:email_included_in_password,
|
56
|
+
:fallback,
|
57
|
+
:name_included_in_password,
|
58
|
+
:nickname_included_in_password,
|
59
|
+
:not_enough_unique_characters,
|
60
|
+
:password_not_allowed,
|
61
|
+
:password_too_common,
|
62
|
+
:password_too_long,
|
63
|
+
:password_too_short].find { |key| msg == I18n.t(key, scope: "password_validator") }
|
64
|
+
else
|
65
|
+
[:blank, :invalid, :taken].find { |key| msg == I18n.t(key, scope: "errors.messages") }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
36
69
|
def valid_attribute?
|
37
70
|
%w(nickname email name password).include? attribute.to_s
|
38
71
|
end
|
@@ -40,10 +73,6 @@ module Decidim
|
|
40
73
|
def valid_suggestor?
|
41
74
|
["nickname"].include? attribute.to_s
|
42
75
|
end
|
43
|
-
|
44
|
-
def valid_users
|
45
|
-
Decidim::UserBaseEntity.where(invitation_token: nil, organization: current_organization)
|
46
|
-
end
|
47
76
|
end
|
48
77
|
end
|
49
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decidim-friendly_signup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Vergés
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: decidim-core
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- app/views/decidim/devise/invitations/edit.html.erb
|
72
72
|
- app/views/decidim/devise/passwords/edit.html.erb
|
73
73
|
- app/views/decidim/devise/registrations/new.html.erb
|
74
|
+
- app/views/decidim/devise/sessions/new.html.erb
|
74
75
|
- app/views/decidim/friendly_signup/confirmation_codes/index.html.erb
|
75
76
|
- app/views/decidim/friendly_signup/confirmation_codes_mailer/confirmation_instructions.html.erb
|
76
77
|
- app/views/decidim/friendly_signup/shared/_password_fields.html.erb
|