Skip to content

Commit

Permalink
Add user show and edit pages (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
canan8 authored May 27, 2020
1 parent 8e4e861 commit 5107b44
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 47 deletions.
8 changes: 4 additions & 4 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Users::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
before_action :configure_account_update_params, only: [:update]

# GET /resource/sign_up
# def new
Expand Down Expand Up @@ -46,9 +46,9 @@ class Users::RegistrationsController < Devise::RegistrationsController
# end

# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end
def configure_account_update_params
devise_parameter_sanitizer.permit(:account_update, keys: [:name, :title])
end

# The path used after sign up.
# def after_sign_up_path_for(resource)
Expand Down
94 changes: 57 additions & 37 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,43 +1,63 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<div class="ui container">
<%= render "devise/shared/error_messages", resource: resource %>

<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</div>

<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>

<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "new-password" %>
<% if @minimum_password_length %>
<br />
<em><%= @minimum_password_length %> characters minimum</em>
<h3 class="ui top attached header">
<i class="settings icon"></i>
<div class="content">
Account Settings
<div class="sub header">Manage your preferences</div>
</div>
</h3>
<div class="ui attached segment">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class: 'ui form'}) do |f| %>

<div class="field">
<%= f.label :full_name %>
<%= f.text_field :name, autocomplete: "name" %>
</div>

<div class="field">
<%= f.label :email %>
<%= f.email_field :email, autocomplete: "email" %>
</div>

<div class="field">
<%= f.label :title %>
<%= f.text_field :title, autocomplete: "name" %>
</div>

<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>

<div class="field">
<%= f.label :password %>
<%= f.password_field :password, autocomplete: "new-password" %>
</div>

<div class="field">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>

<div class="field">
<%= f.label :current_password %>
<%= f.password_field :current_password, autocomplete: "current-password" %>
</div>

<div class="actions">
<%= f.button "Save", class: 'blue ui button' %>
<%= link_to "Cancel", current_user, class: 'ui button'%>
</div>
<% end %>

<h3>Delete my account</h3>

<p>Unhappy? </p> <br />
<%= link_to "Delete my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete, class: 'negative ui button' %>
<br />
</div>
</div>

<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>

<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "current-password" %>
</div>

<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>

<h3>Cancel my account</h3>
<!-- <%= link_to "Back", :back %> -->

<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>

<%= link_to "Back", :back %>
4 changes: 2 additions & 2 deletions app/views/layouts/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<div class="ui simple dropdown item" id="dropdown">
Account <i class="dropdown icon"></i>
<div class="menu">
<%= link_to 'Profile', root_path, class: 'item' %>
<%= link_to 'Settings', root_path, class: 'item' %>
<%= link_to 'Profile', current_user, class: 'item' %>
<%= link_to 'Settings', edit_user_registration_path, class: 'item' %>
<div class="divider"></div>
<%= link_to 'Log out', destroy_user_session_path, class: 'item', method: :delete %>
</div>
Expand Down
29 changes: 26 additions & 3 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
<h1 align="center"><%= @user.name %></h1>
<h4 align="center"><%= @user.title %></h4>
<h4 align="center"><%= @user.email %></h4>
<div class="ui container">
<div class="ui card">
<div class="content">
<div class="header">
<%= @user.name %>
</div>
</div>
<div class="content">
<h4 class="ui sub header">
<%= @user.title %>
</h4>
<div class="ui small feed">
<div class="event">
<div class="content">
<div class="summary">
<%= @user.email %>
</div>
</div>
</div>
</div>
</div>
<div class="extra content">
<%= link_to 'Edit', edit_user_registration_path, class: 'ui button' %>
</div>
</div>
</div>
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
}

resources :users, only: [:show, :index]

as :user do
get 'users/edit', :to => 'devise/registrations#edit', :as => :user_root
end

root 'welcome#index'
get 'teams', to: 'teams#index'
# post 'login', to: 'sessions#create'

end

0 comments on commit 5107b44

Please sign in to comment.