Browse Source

add name fields to devise registrations (#15)

* add name fields to devise registrations

* add name fields to devise registrations

* added application controller to customize devise params
Scott Christensen 7 years ago
parent
commit
9146494bae

+ 12 - 0
app/controllers/application_controller.rb

@@ -0,0 +1,12 @@
+class ApplicationController < ActionController::Base
+  protect_from_forgery with: :exception
+
+  before_action :configure_permitted_parameters, if: :devise_controller?
+
+  protected
+
+    def configure_permitted_parameters
+      devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name])
+      devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name])
+    end
+end

+ 46 - 0
app/views/devise/registrations/edit.html.erb

@@ -0,0 +1,46 @@
+<div class="row">
+  <div class="col-lg-4 col-md-6 ml-auto mr-auto">
+    <h1 class="text-center">Account</h1>
+
+    <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
+      <%= devise_error_messages! %>
+
+      <div class="form-group">
+        <%= f.text_field :first_name, autofocus: false, class: 'form-control', placeholder: "First Name" %>
+      </div>
+
+      <div class="form-group">
+        <%= f.text_field :last_name, autofocus: false, class: 'form-control', placeholder: "Last Name" %>
+      </div>
+
+      <div class="form-group">
+        <%= f.email_field :email, class: 'form-control', placeholder: 'Email Address' %>
+      </div>
+
+      <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
+        <div class="alert alert-warning">Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
+      <% end %>
+
+      <div class="form-group">
+        <%= f.password_field :password, autocomplete: "off", class: 'form-control', placeholder: 'Password'  %>
+        <p class="form-text text-muted"><small>Leave password blank if you don't want to change it</small></p>
+      </div>
+
+      <div class="form-group">
+        <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control', placeholder: 'Confirm Password'  %>
+      </div>
+
+      <div class="form-group">
+        <%= f.password_field :current_password, autocomplete: "off", class: 'form-control', placeholder: 'Current Password'  %>
+        <p class="form-text text-muted"><small>We need your current password to confirm your changes</small></p>
+      </div>
+
+      <div class="form-group">
+        <%= f.submit "Save Changes", class: 'btn btn-lg btn-block btn-primary' %>
+      </div>
+    <% end %>
+    <hr>
+
+    <p class="text-center"><%= link_to "Deactivate my account", registration_path(resource_name), data: { confirm: "Are you sure? You cannot undo this." }, method: :delete %></p>
+  </div>
+</div>

+ 37 - 0
app/views/devise/registrations/new.html.erb

@@ -0,0 +1,37 @@
+<div class="row">
+  <div class="col-lg-4 col-md-6 ml-auto mr-auto">
+    <h1 class="text-center">Sign Up</h1>
+
+    <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
+      <%= devise_error_messages! %>
+
+      <div class="form-group">
+        <%= f.text_field :first_name, autofocus: true, class: 'form-control', placeholder: "First Name" %>
+      </div>
+
+      <div class="form-group">
+        <%= f.text_field :last_name, autofocus: false, class: 'form-control', placeholder: "Last Name" %>
+      </div>
+
+      <div class="form-group">
+        <%= f.email_field :email, autofocus: false, class: 'form-control', placeholder: "Email Address" %>
+      </div>
+
+      <div class="form-group">
+        <%= f.password_field :password, autocomplete: "off", class: 'form-control', placeholder: 'Password' %>
+      </div>
+
+      <div class="form-group">
+        <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control', placeholder: 'Confirm Password' %>
+      </div>
+
+      <div class="form-group">
+        <%= f.submit "Sign up", class: "btn btn-primary btn-block btn-lg" %>
+      </div>
+    <% end %>
+
+    <div class="text-center">
+      <%= render "devise/shared/links" %>
+    </div>
+  </div>
+</div>