mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Add full name to users
This commit is contained in:
@@ -1,2 +1,10 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def configure_permitted_parameters
|
||||||
|
devise_parameter_sanitizer.permit(:sign_up, keys: [:full_name])
|
||||||
|
devise_parameter_sanitizer.permit(:account_update, keys: [:full_name])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ class User < ApplicationRecord
|
|||||||
enum role: [:user, :moderator, :admin]
|
enum role: [:user, :moderator, :admin]
|
||||||
after_initialize :set_default_role, if: :new_record?
|
after_initialize :set_default_role, if: :new_record?
|
||||||
|
|
||||||
|
validates :full_name, presence: true
|
||||||
|
|
||||||
def set_default_role
|
def set_default_role
|
||||||
self.role ||= :user
|
self.role ||= :user
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,41 +3,46 @@
|
|||||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
|
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
|
||||||
<%= render "devise/shared/error_messages", resource: resource %>
|
<%= render "devise/shared/error_messages", resource: resource %>
|
||||||
|
|
||||||
<div class="field">
|
<div class="form-group">
|
||||||
|
<%= f.label :full_name %><br />
|
||||||
|
<%= f.text_field :full_name, autofocus: true, autocomplete: "full-name", class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
<%= f.label :email %><br />
|
<%= f.label :email %><br />
|
||||||
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
|
<%= f.email_field :email, autocomplete: "email", class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
|
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
|
||||||
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
|
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="field">
|
<div class="form-group">
|
||||||
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
||||||
<%= f.password_field :password, autocomplete: "new-password" %>
|
<%= f.password_field :password, autocomplete: "new-password", class: "form-control" %>
|
||||||
<% if @minimum_password_length %>
|
<% if @minimum_password_length %>
|
||||||
<br />
|
<br />
|
||||||
<em><%= @minimum_password_length %> characters minimum</em>
|
<em><%= @minimum_password_length %> characters minimum</em>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="form-group">
|
||||||
<%= f.label :password_confirmation %><br />
|
<%= f.label :password_confirmation %><br />
|
||||||
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
|
<%= f.password_field :password_confirmation, autocomplete: "new-password", class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="form-group">
|
||||||
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
||||||
<%= f.password_field :current_password, autocomplete: "current-password" %>
|
<%= f.password_field :current_password, autocomplete: "current-password", class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<%= f.submit "Update" %>
|
<%= f.submit "Update", class: "btn btn-primary" %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<h3>Cancel my account</h3>
|
<h3>Cancel my account</h3>
|
||||||
|
|
||||||
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
|
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete, class: "btn btn-danger" %></p>
|
||||||
|
|
||||||
<%= link_to "Back", :back %>
|
<%= link_to "Back", :back %>
|
||||||
|
|||||||
@@ -3,26 +3,31 @@
|
|||||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
||||||
<%= render "devise/shared/error_messages", resource: resource %>
|
<%= render "devise/shared/error_messages", resource: resource %>
|
||||||
|
|
||||||
<div class="field">
|
<div class="form-group">
|
||||||
|
<%= f.label :full_name %><br />
|
||||||
|
<%= f.text_field :full_name, autofocus: true, autocomplete: "full-name", class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
<%= f.label :email %><br />
|
<%= f.label :email %><br />
|
||||||
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
|
<%= f.email_field :email, autocomplete: "email", class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="form-group">
|
||||||
<%= f.label :password %>
|
<%= f.label :password %>
|
||||||
<% if @minimum_password_length %>
|
<% if @minimum_password_length %>
|
||||||
<em>(<%= @minimum_password_length %> characters minimum)</em>
|
<em>(<%= @minimum_password_length %> characters minimum)</em>
|
||||||
<% end %><br />
|
<% end %><br />
|
||||||
<%= f.password_field :password, autocomplete: "new-password" %>
|
<%= f.password_field :password, autocomplete: "new-password", class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="form-group">
|
||||||
<%= f.label :password_confirmation %><br />
|
<%= f.label :password_confirmation %><br />
|
||||||
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
|
<%= f.password_field :password_confirmation, autocomplete: "new-password", class: "form-control" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<%= f.submit "Sign up" %>
|
<%= f.submit "Sign up", class: "btn btn-primary" %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
5
db/migrate/20190819131723_add_fullname_to_users.rb
Normal file
5
db/migrate/20190819131723_add_fullname_to_users.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class AddFullnameToUsers < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
add_column :users, :full_name, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2019_08_18_191513) do
|
ActiveRecord::Schema.define(version: 2019_08_19_131723) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -28,6 +28,7 @@ ActiveRecord::Schema.define(version: 2019_08_18_191513) do
|
|||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
t.integer "role"
|
t.integer "role"
|
||||||
|
t.string "full_name"
|
||||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||||
t.index ["email"], name: "index_users_on_email", unique: true
|
t.index ["email"], name: "index_users_on_email", unique: true
|
||||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||||
|
|||||||
Reference in New Issue
Block a user