From 43bf87036f5ccb73898e8b8ce8e638722e4dceac Mon Sep 17 00:00:00 2001 From: Marten Veldthuis Date: Mon, 14 May 2018 16:52:26 +0100 Subject: [PATCH 1/8] Spice up edit page styling and add delete-account --- app/controllers/registrations_controller.rb | 13 +++ app/views/devise/registrations/edit.html.erb | 88 +++++++++++++++----- config/routes.rb | 2 + 3 files changed, 80 insertions(+), 23 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index fa62516e7..c0777d7eb 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -19,6 +19,19 @@ def update end end + def destroy + if current_user.valid_password?(params[:user][:current_password]) + UserInfoScrubber.scrub_personal_info!(current_user) + Activation.disable_instances!([current_user]) + Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) + set_flash_message! :notice, :destroyed + respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) } + else + flash[:delete_alert] = "Incorrect password" + render action: :edit + end + end + private def create_from_json diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 0a4cda975..7db42d1db 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,35 +1,77 @@ -

Edit <%= resource_name.to_s.humanize %>

+
+
+

Update your profile

-<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> - <%= devise_error_messages! %> + <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> -
<%= f.label :login %>
- <%= f.text_field :login, autofocus: true %>
+
+ <%= f.label :login %>
+ <%= f.text_field :login, autofocus: true, class: 'form-control' %> +
-
<%= f.label :display_name %>
- <%= f.text_field :display_name %>
+
+ <%= f.label :display_name %>
+ <%= f.text_field :display_name, class: 'form-control' %> +
-
<%= f.label :email %>
- <%= f.email_field :email %>
+
+ <%= f.label :email %>
+ <%= f.email_field :email, class: 'form-control' %> - <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> -
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
- <% end %> + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> +
-
<%= f.label :password %> (leave blank if you don't want to change it)
- <%= f.password_field :password, autocomplete: "off" %>
+
+
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "off", class: 'form-control' %> +
-
<%= f.label :password_confirmation %>
- <%= f.password_field :password_confirmation, autocomplete: "off" %>
+
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %> +
+
-
<%= f.label :current_password %> (we need your current password to confirm your changes)
- <%= f.password_field :current_password, autocomplete: "off" %>
+
+
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %> +
+
-
<%= f.submit "Update" %>
-<% end %> + <%= f.submit "Update", class: 'btn btn-primary' %> + <% end %> +
+
-

Cancel my account

+
-

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

+
+
Cancel my account
-<%= link_to "Back", :back %> +

+ If for whatever reason you no longer wish to maintain an account with us, + you can delete it here. Please note that any classifications you've made on + projects, and any comments you've posted on our Talk discussion fora will + remain. +

+ + <% if flash[:delete_alert] %> +

<%= flash[:delete_alert] %>

+ <% end %> + + <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :delete }) do |f| %> +
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %> +
+ + <%= f.submit "Cancel my account", class: 'btn btn-danger' %> + <% end %> + + <%= link_to "Back", :back %> +
diff --git a/config/routes.rb b/config/routes.rb index 8de1d10ce..fa1f50e17 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,9 +30,11 @@ post "/users/sign_in" => "sessions#create", as: :user_session delete "/users/sign_out" => "sessions#destroy", as: :destroy_user_session + get '/profile' => 'registrations#edit', as: :edit_user_registration get "/users/sign_up" => "registrations#new", as: :new_user_registration post "/users" => "registrations#create", as: :user_registration put "/users" => "registrations#update" + delete "/users" => "registrations#destroy", as: :destroy_user_registration end get "unsubscribe", to: "emails#unsubscribe_via_token" From 25fa0b679cc9a44ec77bf7b1523951ed4c807a30 Mon Sep 17 00:00:00 2001 From: Marten Veldthuis Date: Fri, 18 May 2018 11:22:27 +0100 Subject: [PATCH 2/8] Add specs --- .../registrations_controller_spec.rb | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 81971e363..cfd2cdcf1 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -256,7 +256,6 @@ end describe "#create" do - context "with valid user attributes" do let(:login) { "zoonser" } let(:extra_attributes) { { login: login } } @@ -339,5 +338,54 @@ end end end + + describe '#destroy' do + let(:password) { 'password' } + let(:user) { create :user, password: password } + let(:user_id) { user.id } + let(:access_token) { create(:access_token, resource_owner_id: user_id) } + + before(:each) do + sign_in user + request.env["HTTP_ACCEPT"] = "text/html" + end + + context 'with correct password' do + it 'redirects to root' do + delete :destroy, user: {current_password: password} + expect(response).to redirect_to('/') + expect(flash[:notice]).to be_present + end + + it 'deactivates the user' do + delete :destroy, user: {current_password: password} + expect(user.reload.active?).to be_falsey + end + + it 'scrubs the users information' do + expect(UserInfoScrubber).to receive(:scrub_personal_info!).with(user) + delete :destroy, user: {current_password: password} + end + end + + context 'with incorrect password' do + it 'renders error' do + delete :destroy, user: {current_password: 'wrong'} + expect(user.reload.active?).to be_truthy + expect(flash[:delete_alert]).to be_present + end + end + + let(:authorized_user) { user } + let(:resource) { user } + let(:instances_to_disable) do + [resource] | + resource.projects | + resource.memberships | + resource.collections + end + + # it_behaves_like "is deactivatable" + end end end From 457058dcea93378348e3a66b9493c1d05dfa2b95 Mon Sep 17 00:00:00 2001 From: Marten Veldthuis Date: Fri, 18 May 2018 11:29:02 +0100 Subject: [PATCH 3/8] Remove commented out shared examples for deactivate --- spec/controllers/registrations_controller_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index cfd2cdcf1..4cf4f3eba 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -384,8 +384,6 @@ resource.memberships | resource.collections end - - # it_behaves_like "is deactivatable" end end end From b6403b91c9f87d885405f499da93bf6dc426c5e4 Mon Sep 17 00:00:00 2001 From: Marten Veldthuis Date: Fri, 18 May 2018 12:16:44 +0100 Subject: [PATCH 4/8] Increase base font size --- app/assets/stylesheets/base.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/base.css b/app/assets/stylesheets/base.css index ce84acae4..e4ababadf 100644 --- a/app/assets/stylesheets/base.css +++ b/app/assets/stylesheets/base.css @@ -1,6 +1,6 @@ html, body { background: #fbfbfb; - font: 400 10px/20px Arial, sans-serif; + font: 400 12px/20px Arial, sans-serif; -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialiased; } @@ -66,19 +66,19 @@ h1 { } h2 { - font-size: 4.2em; + font-size: 3.2em; } h3 { - font-size: 3.6em; + font-size: 3em; } h4 { - font-size: 3em + font-size: 2.8em; } h5 { - font-size: 2.4em + font-size: 2.4em; } h6 { From 3a6322c432fe3592c54c48abbbd493b897dfe084 Mon Sep 17 00:00:00 2001 From: Marten Veldthuis Date: Fri, 18 May 2018 12:17:08 +0100 Subject: [PATCH 5/8] Convert password-forgot screens to Bootstrap --- app/views/devise/passwords/edit.html.erb | 40 +++++++++++++----------- app/views/devise/passwords/new.html.erb | 26 ++++++++------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index 85f77aff0..490aef690 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -1,22 +1,26 @@ -
-

Change your password

+
+
+

Change your password

- <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put, class: "form" }) do |f| %> - <%= devise_error_messages! %> - <%= f.hidden_field :reset_password_token %> + <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put}) do |f| %> + <%= devise_error_messages! %> + <%= f.hidden_field :reset_password_token %> -
- <%= f.label :password, "New password" %>
- <%= f.password_field :password, autofocus: true, autocomplete: "off" %> -
+
+ <%= f.label :password, "New password" %>
+ <%= f.password_field :password, autofocus: true, autocomplete: "off", class: 'form-control' %> +
-
- <%= f.label :password_confirmation, "Confirm new password" %>
- <%= f.password_field :password_confirmation, autocomplete: "off" %> -
+
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %> +
-
<%= f.submit "Change my password" %>
- <% end %> - - <%= render "devise/shared/links" %> -
\ No newline at end of file + <%= f.submit "Change my password", class: 'btn btn-primary' %> + <% end %> +
+ + +
diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index 8f9ab69f8..79118af99 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -1,16 +1,20 @@ -
-

Forgot your password?

+
+
+

Forgot your password?

- <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post, class: "form form--new-password" }) do |f| %> - <%= devise_error_messages! %> + <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> - +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, required: true, class: 'form-control' %> +
-
<%= f.submit "Send me reset email" %>
- <% end %> + <%= f.submit "Send me reset email", class: 'btn btn-primary' %> + <% end %> +
- <%= render "devise/shared/links" %> +
From 262e8d792bf2663e6ae0da70026cfa5896703d43 Mon Sep 17 00:00:00 2001 From: Marten Veldthuis Date: Fri, 18 May 2018 12:17:29 +0100 Subject: [PATCH 6/8] Fix indentation to 2 spaces --- .editorconfig | 6 + app/views/devise/registrations/edit.html.erb | 118 ++++++++++--------- 2 files changed, 68 insertions(+), 56 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..ce896ea99 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 7db42d1db..77cda2746 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,77 +1,83 @@
-
-

Update your profile

+
+

Update your profile

- <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> - <%= devise_error_messages! %> + <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> -
- <%= f.label :login %>
- <%= f.text_field :login, autofocus: true, class: 'form-control' %> -
+
+ <%= f.label :login %>
+ <%= f.text_field :login, autofocus: true, class: 'form-control' %> +
-
- <%= f.label :display_name %>
- <%= f.text_field :display_name, class: 'form-control' %> -
+
+ <%= f.label :display_name %>
+ <%= f.text_field :display_name, class: 'form-control' %> +
-
- <%= f.label :email %>
- <%= f.email_field :email, class: 'form-control' %> +
+ <%= f.label :email %>
+ <%= f.email_field :email, class: 'form-control' %> - <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> -
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
- <% end %> -
+ <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> +
-
-
- <%= f.label :password %> (leave blank if you don't want to change it)
- <%= f.password_field :password, autocomplete: "off", class: 'form-control' %> -
+
+
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "off", class: 'form-control' %> +
-
- <%= f.label :password_confirmation %>
- <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %> -
-
+
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %> +
+
-
-
- <%= f.label :current_password %> (we need your current password to confirm your changes)
- <%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %> -
-
+
+
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %> +
+
- <%= f.submit "Update", class: 'btn btn-primary' %> - <% end %> -
+ <%= f.submit "Update", class: 'btn btn-primary' %> + <% end %> +

-
-
Cancel my account
+
+
+
+
+
Cancel my account
-

- If for whatever reason you no longer wish to maintain an account with us, - you can delete it here. Please note that any classifications you've made on - projects, and any comments you've posted on our Talk discussion fora will - remain. -

+

+ If for whatever reason you no longer wish to maintain an account with us, + you can delete it here. Please note that any classifications you've made on + projects, and any comments you've posted on our Talk discussion fora will + remain. +

- <% if flash[:delete_alert] %> -

<%= flash[:delete_alert] %>

- <% end %> - - <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :delete }) do |f| %> -
+ <% if flash[:delete_alert] %> +

<%= flash[:delete_alert] %>

+ <% end %> + + <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :delete }) do |f| %> +
<%= f.label :current_password %> (we need your current password to confirm your changes)
<%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %> -
+
- <%= f.submit "Cancel my account", class: 'btn btn-danger' %> - <% end %> + <%= f.submit "Cancel my account", class: 'btn btn-danger' %> + <% end %> - <%= link_to "Back", :back %> + <%= link_to "Back", :back %> +
+
+
From 759fd91f210e9b6f7a5fee20f03017db28da8af5 Mon Sep 17 00:00:00 2001 From: Marten Veldthuis Date: Fri, 18 May 2018 12:18:08 +0100 Subject: [PATCH 7/8] Convert other forms to Bootstrap --- app/views/devise/registrations/new.html.erb | 100 ++++++++++---------- app/views/devise/sessions/new.html.erb | 36 +++---- app/views/devise/shared/_links.erb | 4 +- 3 files changed, 72 insertions(+), 68 deletions(-) diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index cee82ca5c..71e3eccc3 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,57 +1,59 @@ -
-

Sign up

- - <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {class: "form form--new-user"}) do |f| %> - -
-
- <%= f.label :login, "Username (required)" %><%= resource.errors[:login].join(', ')%>
- <%= f.text_field :login, autofocus: true, required: true %> -
-
- -
-
- <%= f.label :credited_name, "Real Name (optional)" %><%= resource.errors[:display_name].join(', ')%>
- <%= f.text_field :display_name %> - We’ll use this to give you credit in scientific papers, posters, etc -
-
- -
- +
+
+

Create account

+ + <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + +
"> + <%= f.label :login, "Username (required)" %><%= resource.errors[:login].join(', ')%>
+ <%= f.text_field :login, autofocus: true, required: true, class: 'form-control' %> +
+ +
"> + <%= f.label :credited_name, "Real Name (optional)" %><%= resource.errors[:display_name].join(', ')%>
+ <%= f.text_field :display_name, class: 'form-control' %> + We’ll use this to give you credit in scientific papers, posters, etc +
+ +
"> + <%= f.label :email, "Email (required)"%><%= resource.errors[:email].join(', ')%>
+ <%= f.email_field :email, required: true, class: 'form-control' %> +
+ +
+ <%= f.label :password, "Password (required)"%><%= resource.errors[:password].join(', ')%>
+ <%= f.password_field :password, autocomplete: "off", required: true, class: 'form-control' %> + + <%= f.label :password_confirmation, "Password confirmation (required)" %><%= resource.errors[:password_confirmation].join(', ')%>
+ <%= f.password_field :password_confirmation, autocomplete: "off", required: true, class: 'form-control' %> +
+ +
+ +
+ +
+ <%= f.label :global_email_communication do %> + <%= f.check_box :global_email_communication, checked: true %> + It’s okay to send me email every once in a while. + <% end %>
-
-
- <%= f.label :password, "Password (required)"%><%= resource.errors[:password].join(', ')%>
- <%= f.password_field :password, autocomplete: "off", required: true %> -
- -
- <%= f.label :password_confirmation, "Password confirmation (required)" %><%= resource.errors[:password_confirmation].join(', ')%>
- <%= f.password_field :password_confirmation, autocomplete: "off", required: true %> -
-
- -
- +
+ <%= f.label :beta_email_communication do %> + <%= f.check_box :beta_email_communication, checked: false %> + I’d like to help test new projects, and be emailed when they’re available. + <% end %>
-
<%= f.submit "Sign up" %>
+ <%= f.submit "Create account", class: 'btn btn-primary' %> <% end %> +
+
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index d6d57a0cc..fbda518fa 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,23 +1,25 @@ -
-

Sign in

+
+
+

Sign in

- <%= form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: "form form--new-session"}) do |f| %> -
- <%= f.label :login, "Username or Email Address" %>
- <%= f.text_field :login, autofocus: true, required: true %> -
+ <%= form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: "form form--new-session"}) do |f| %> +
+ <%= f.label :login, "Username or Email Address" %>
+ <%= f.text_field :login, autofocus: true, required: true %> +
-
- <%= f.label :password %>
- <%= f.password_field :password, autocomplete: "off" %> -
+
+ <%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "off" %> +
- <% if devise_mapping.rememberable? -%> -
<%= f.check_box :remember_me %> <%= f.label :remember_me %>
- <% end -%> + <% if devise_mapping.rememberable? -%> +
<%= f.check_box :remember_me %> <%= f.label :remember_me %>
+ <% end -%> -
<%= f.submit "Sign in" %>
- <% end %> +
<%= f.submit "Sign in" %>
+ <% end %> - <%= render "devise/shared/links" %> + <%= render "devise/shared/links" %> +
diff --git a/app/views/devise/shared/_links.erb b/app/views/devise/shared/_links.erb index e4d894af5..5cdba81b9 100644 --- a/app/views/devise/shared/_links.erb +++ b/app/views/devise/shared/_links.erb @@ -1,4 +1,4 @@ -