Browse Source
* Your account page / personal details brochureware * Edit password page working and added Co-authored-by: Dushan <dushan-madetech@users.noreply.github.com> * update password directing to the right place * update from put to patch As per the notice in this documenation: https://github.com/heartcombo/devise/wiki/How-To:-Allow-users-to-edit-their-password * update routes file * Account page: able to change name and email address * Check if logged in before accessing * Your account page - rubocop * Prettify * Fix spec for merge * Remove unused helper * Use permitted params Co-authored-by: Matthew Phelan <matthew.phelan@madetech.com> Co-authored-by: Dushan <dushan-madetech@users.noreply.github.com> Co-authored-by: baarkerlounger <db@slothlife.xyz>pull/112/head
Dushan
3 years ago
committed by
GitHub
11 changed files with 229 additions and 42 deletions
@ -0,0 +1,25 @@ |
|||||||
|
class Users::AccountController < ApplicationController |
||||||
|
def check_logged_in |
||||||
|
if current_user.nil? |
||||||
|
redirect_to(new_user_session_path) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def index |
||||||
|
check_logged_in |
||||||
|
end |
||||||
|
|
||||||
|
def personal_details |
||||||
|
check_logged_in |
||||||
|
end |
||||||
|
|
||||||
|
def update |
||||||
|
if current_user.update(user_params) |
||||||
|
redirect_to(users_account_path) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def user_params |
||||||
|
params.require(:user).permit(:email, :name, :password) |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,7 @@ |
|||||||
|
class Users::RegistrationsController < Devise::RegistrationsController |
||||||
|
protected |
||||||
|
|
||||||
|
def after_update_path_for(_resource) |
||||||
|
users_account_path |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,9 @@ |
|||||||
|
module AccountHelper |
||||||
|
def resource_name |
||||||
|
:user |
||||||
|
end |
||||||
|
|
||||||
|
def resource |
||||||
|
@resource = current_user |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,73 @@ |
|||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<h1 class="govuk-heading-l"> |
||||||
|
Your account |
||||||
|
</h1> |
||||||
|
<h2 class="govuk-heading-m"> |
||||||
|
Personal details |
||||||
|
</h2> |
||||||
|
<dl class="govuk-summary-list"> |
||||||
|
<div class="govuk-summary-list__row"> |
||||||
|
<dt class="govuk-summary-list__key"> |
||||||
|
Name |
||||||
|
</dt> |
||||||
|
<dd class="govuk-summary-list__value"> |
||||||
|
<%= current_user.name %> |
||||||
|
</dd> |
||||||
|
<dd class="govuk-summary-list__actions"> |
||||||
|
<a class="govuk-link" href="/users/account/personal_details" id="change-name"> |
||||||
|
Change<span class="govuk-visually-hidden"> |
||||||
|
name</span> |
||||||
|
</a> |
||||||
|
</dd> |
||||||
|
</div> |
||||||
|
<div class="govuk-summary-list__row"> |
||||||
|
<dt class="govuk-summary-list__key"> |
||||||
|
Email address |
||||||
|
</dt> |
||||||
|
<dd class="govuk-summary-list__value"> |
||||||
|
<%= current_user.email %> |
||||||
|
</dd> |
||||||
|
<dd class="govuk-summary-list__actions"> |
||||||
|
<a class="govuk-link" href="/users/account/personal_details" id="change-email"> |
||||||
|
Change<span class="govuk-visually-hidden"> |
||||||
|
email address</span> |
||||||
|
</a> |
||||||
|
</dd> |
||||||
|
</div> |
||||||
|
<div class="govuk-summary-list__row"> |
||||||
|
<dt class="govuk-summary-list__key"> |
||||||
|
Password |
||||||
|
</dt> |
||||||
|
<dd class="govuk-summary-list__value"> |
||||||
|
•••••••• |
||||||
|
</dd> |
||||||
|
<dd class="govuk-summary-list__actions"> |
||||||
|
<%= link_to "Change", edit_user_registration_path, id: "change-password" %> |
||||||
|
</dd> |
||||||
|
</div> |
||||||
|
<div class="govuk-summary-list__row"> |
||||||
|
<dt class="govuk-summary-list__key"> |
||||||
|
Organisation |
||||||
|
</dt> |
||||||
|
<dd class="govuk-summary-list__value"> |
||||||
|
<%= current_user.organisation %> |
||||||
|
</dd> |
||||||
|
<dd class="govuk-summary-list__actions"> |
||||||
|
<a class="govuk-link" href=""></a> |
||||||
|
</dd> |
||||||
|
</div> |
||||||
|
<div class="govuk-summary-list__row"> |
||||||
|
<dt class="govuk-summary-list__key"> |
||||||
|
Role |
||||||
|
</dt> |
||||||
|
<dd class="govuk-summary-list__value"> |
||||||
|
<%= current_user.role %> |
||||||
|
</dd> |
||||||
|
<dd class="govuk-summary-list__actions"> |
||||||
|
<a class="govuk-link" href=""></a> |
||||||
|
</dd> |
||||||
|
</div> |
||||||
|
</dl> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,23 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<%= link_to 'Back', :back, class: "govuk-back-link" %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= form_for(resource, as: resource_name, url: account_update_path(), html: { method: :patch }) do |f| %> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<h1 class="govuk-heading-l">Change your personal details</h1> |
||||||
|
|
||||||
|
<div class="govuk-form-group"> |
||||||
|
<%= f.label :name, class: "govuk-label" %> |
||||||
|
<%= f.text_field :name, autocomplete: "name", class: "govuk-input" %> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div class="govuk-form-group"> |
||||||
|
<%= f.label :email, class: "govuk-label" %> |
||||||
|
<%= f.email_field :email, autocomplete: "email", class: "govuk-input" %> |
||||||
|
</div> |
||||||
|
|
||||||
|
<%= f.submit "Save changes", class: "govuk-button" %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<% end %> |
@ -0,0 +1,7 @@ |
|||||||
|
class AddNameEmailRoleOrgToUsers < ActiveRecord::Migration[6.1] |
||||||
|
def change |
||||||
|
add_column :users, :name, :string |
||||||
|
add_column :users, :role, :string |
||||||
|
add_column :users, :organisation, :string |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue