From dbaa9a85cbc5b17cdf64bcc8ce99c3e9bcf51ccc Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Mon, 20 Jul 2020 18:41:10 +0300 Subject: [PATCH] Add a field for user email address --- app/controllers/preferences_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/models/user.rb | 1 + app/views/preferences/_profile.html.erb | 3 +++ app/views/users/new.html.erb | 4 ++++ config/locales/en.yml | 4 +++- db/migrate/20200720151220_add_email_to_user.rb | 5 +++++ 7 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20200720151220_add_email_to_user.rb diff --git a/app/controllers/preferences_controller.rb b/app/controllers/preferences_controller.rb index 4781f121..3becc7d0 100644 --- a/app/controllers/preferences_controller.rb +++ b/app/controllers/preferences_controller.rb @@ -44,7 +44,7 @@ private end def user_params - params.require(:user).permit(:login, :first_name, :last_name, :password_confirmation, :password, :auth_type, :open_id_url) + params.require(:user).permit(:login, :first_name, :last_name, :email, :password_confirmation, :password, :auth_type, :open_id_url) end # Display notification if preferences are successful updated diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 12c37c5e..059a1f74 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -187,7 +187,7 @@ class UsersController < ApplicationController private def user_params - params.require(:user).permit(:login, :first_name, :last_name, :password_confirmation, :password, :auth_type, :open_id_url) + params.require(:user).permit(:login, :first_name, :last_name, :email, :password_confirmation, :password, :auth_type, :open_id_url) end def get_new_user diff --git a/app/models/user.rb b/app/models/user.rb index 736db95e..ad38279c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -107,6 +107,7 @@ class User < ApplicationRecord validates_length_of :login, within: 3..80 validates_uniqueness_of :login, on: :create validate :validate_auth_type + validates :email, format: { with: URI::MailTo::EMAIL_REGEXP } before_create :crypt_password, :generate_token before_update :crypt_password diff --git a/app/views/preferences/_profile.html.erb b/app/views/preferences/_profile.html.erb index b2f67ace..447eeb57 100644 --- a/app/views/preferences/_profile.html.erb +++ b/app/views/preferences/_profile.html.erb @@ -4,6 +4,9 @@
<%= pref_with_text_field 'user', 'last_name' %>
+
+ <%= pref_with_text_field 'user', 'email' %> +
<%= pref_with_select_field('prefs', 'locale', I18n.available_locales.map {|l| l.to_s}) %>
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 4450011e..a46b87af 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -22,6 +22,10 @@ <%= label_tag "user_login", t('users.desired_login') %> <%= text_field "user", "login", class: "form-control" %> +
+ <%= label_tag "user_email", t('users.email_address') %> + <%= text_field "user", "email", class: "form-control" %> +
<%= label_tag "user_password", t('users.choose_password') %> <%= password_field "user", "password", class: "form-control" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 97626fd2..5ef1aa96 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -51,6 +51,7 @@ en: user: auth_type: Auth type display_name: Display name + email: Email address first_name: First name last_name: Last name login: Login @@ -87,7 +88,7 @@ en: confirmation: doesn't match confirmation less_than_or_equal_to: must be less than or equal to %{count} blank: can't be blank - invalid: "cannot contain the comma (',') character" + invalid: "is not valid" exclusion: is reserved odd: must be odd even: must be even @@ -961,6 +962,7 @@ en: change_password_prompt: Enter your new password in the fields below and click 'Change password' to replace your current password with your new one. password_confirmation_label: Confirm password destroy_error: There was an error deleting the user %{login} + email_address: Email address choose_password: Choose password register_with_cas: With your CAS username label_auth_type: Authentication type diff --git a/db/migrate/20200720151220_add_email_to_user.rb b/db/migrate/20200720151220_add_email_to_user.rb new file mode 100644 index 00000000..0f5627ee --- /dev/null +++ b/db/migrate/20200720151220_add_email_to_user.rb @@ -0,0 +1,5 @@ +class AddEmailToUser < ActiveRecord::Migration[5.2] + def change + add_column :users, :email, :string + end +end