configurable field to unsubscribe from emails + link to do it yourself
This commit is contained in:
parent
79634f8faf
commit
4629ebf8f9
7 changed files with 66 additions and 20 deletions
|
@ -3095,3 +3095,7 @@ script.data-gratipay-username {
|
||||||
display: inline;
|
display: inline;
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.inline {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,28 @@ class NotificationsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unsubscribe
|
||||||
|
# TODO will a logged out user be unsubscribed after logging in?
|
||||||
|
# need to use devise stored_url or whatever
|
||||||
|
if current_user.nil?
|
||||||
|
return redirect_to sign_in_path, notice: 'Continue to unsubscribe from emails by logging in.'
|
||||||
|
end
|
||||||
|
|
||||||
|
if current_user.emails_allowed == false
|
||||||
|
return redirect_to edit_user_path(current_user), notice: 'You were already unsubscribed from emails.'
|
||||||
|
end
|
||||||
|
|
||||||
|
current_user.emails_allowed = false
|
||||||
|
success = current_user.save
|
||||||
|
|
||||||
|
if success
|
||||||
|
redirect_to edit_user_path(current_user), notice: 'You will no longer receive emails from Metamaps.'
|
||||||
|
else
|
||||||
|
flash[:alert] = 'Sorry, something went wrong. You have not been unsubscribed from emails.'
|
||||||
|
redirect_to edit_user_path(current_user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_receipts
|
def set_receipts
|
||||||
|
|
|
@ -13,13 +13,12 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
# GET /users/:id/edit
|
# GET /users/:id/edit
|
||||||
def edit
|
def edit
|
||||||
@user = current_user
|
@user = User.find(current_user.id)
|
||||||
respond_with(@user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT /users/:id
|
# PUT /users/:id
|
||||||
def update
|
def update
|
||||||
@user = current_user
|
@user = User.find(current_user.id)
|
||||||
|
|
||||||
if user_params[:password] == '' && user_params[:password_confirmation] == ''
|
if user_params[:password] == '' && user_params[:password_confirmation] == ''
|
||||||
# not trying to change the password
|
# not trying to change the password
|
||||||
|
@ -96,6 +95,6 @@ class UsersController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:name, :email, :image, :password, :password_confirmation)
|
params.require(:user).permit(:name, :email, :image, :password, :password_confirmation, :emails_allowed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,23 +33,35 @@
|
||||||
<div class="nameEdit"><%= @user.name %></div>
|
<div class="nameEdit"><%= @user.name %></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="changeName">
|
<div class="changeName">
|
||||||
<%= form.label :name, "Name:", :class => "firstFieldText" %>
|
<%= form.label :name, "Name:", class: 'firstFieldText' %>
|
||||||
<%= form.text_field :name %>
|
<%= form.text_field :name %>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= form.label :email, "Email:", class: 'firstFieldText' %>
|
||||||
|
<%= form.email_field :email %>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= form.label :emails_allowed, class: 'firstFieldText' do %>
|
||||||
|
<%= form.check_box :emails_allowed, class: 'inline' %>
|
||||||
|
Send Metamaps notifications to my email.
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div><%= form.label :email, "Email:", :class => "firstFieldText" %>
|
|
||||||
<%= form.email_field :email %></div>
|
|
||||||
<div class="changePass" onclick="Metamaps.Account.showPass()">Change Password</div>
|
<div class="changePass" onclick="Metamaps.Account.showPass()">Change Password</div>
|
||||||
<div class="toHide">
|
<div class="toHide">
|
||||||
<div>
|
<div>
|
||||||
<%= form.label :current_password, "Current Password:", :class => "firstFieldText" %>
|
<%= form.label :current_password, "Current Password:", :class => "firstFieldText" %>
|
||||||
<%= password_field_tag :current_password, params[:current_password] %>
|
<%= password_field_tag :current_password, params[:current_password] %>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= form.label :password, "New Password:", :class => "firstFieldText" %>
|
||||||
|
<%= form.password_field :password, :autocomplete => :off%>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= form.label :password_confirmation, "Confirm New Password:", :class => "firstFieldText" %>
|
||||||
|
<%= form.password_field :password_confirmation, :autocomplete => :off%>
|
||||||
|
</div>
|
||||||
|
<div class="noChangePass" onclick="Metamaps.Account.hidePass()">Oops, don't change password</div>
|
||||||
</div>
|
</div>
|
||||||
<div><%= form.label :password, "New Password:", :class => "firstFieldText" %>
|
|
||||||
<%= form.password_field :password, :autocomplete => :off%></div>
|
|
||||||
<div><%= form.label :password_confirmation, "Confirm New Password:", :class => "firstFieldText" %>
|
|
||||||
<%= form.password_field :password_confirmation, :autocomplete => :off%></div>
|
|
||||||
<div class="noChangePass" onclick="Metamaps.Account.hidePass()">Oops, don't change password</div>
|
|
||||||
</div>
|
|
||||||
<div id="accountPageLoading"></div>
|
<div id="accountPageLoading"></div>
|
||||||
<%= form.submit "Update", class: "update", onclick: "Metamaps.Account.showLoading()" %>
|
<%= form.submit "Update", class: "update", onclick: "Metamaps.Account.showLoading()" %>
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
|
|
|
@ -50,6 +50,9 @@ Metamaps::Application.routes.draw do
|
||||||
|
|
||||||
resources :messages, only: [:show, :create, :update, :destroy]
|
resources :messages, only: [:show, :create, :update, :destroy]
|
||||||
resources :notifications, only: [:index, :show] do
|
resources :notifications, only: [:index, :show] do
|
||||||
|
collection do
|
||||||
|
get :unsubscribe
|
||||||
|
end
|
||||||
member do
|
member do
|
||||||
put :mark_read
|
put :mark_read
|
||||||
put :mark_unread
|
put :mark_unread
|
||||||
|
|
5
db/migrate/20161125175229_add_emails_allowed_to_users.rb
Normal file
5
db/migrate/20161125175229_add_emails_allowed_to_users.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddEmailsAllowedToUsers < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
add_column :users, :emails_allowed, :boolean, default: true
|
||||||
|
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: 20161105160340) do
|
ActiveRecord::Schema.define(version: 20161125175229) 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"
|
||||||
|
@ -296,8 +296,8 @@ ActiveRecord::Schema.define(version: 20161105160340) do
|
||||||
t.string "password_salt", limit: 255
|
t.string "password_salt", limit: 255
|
||||||
t.string "persistence_token", limit: 255
|
t.string "persistence_token", limit: 255
|
||||||
t.string "perishable_token", limit: 255
|
t.string "perishable_token", limit: 255
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "code", limit: 8
|
t.string "code", limit: 8
|
||||||
t.string "joinedwithcode", limit: 8
|
t.string "joinedwithcode", limit: 8
|
||||||
t.text "settings"
|
t.text "settings"
|
||||||
|
@ -317,6 +317,7 @@ ActiveRecord::Schema.define(version: 20161105160340) do
|
||||||
t.integer "image_file_size"
|
t.integer "image_file_size"
|
||||||
t.datetime "image_updated_at"
|
t.datetime "image_updated_at"
|
||||||
t.integer "generation"
|
t.integer "generation"
|
||||||
|
t.boolean "emails_allowed", default: true
|
||||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
|
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue