aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorrhenium <re4k@re4k.info>2013-05-28 16:06:55 +0900
committerrhenium <re4k@re4k.info>2013-05-28 16:06:55 +0900
commit55f7cae17ec78afadb27fd31c62a55c3bc6b47cf (patch)
tree6d02d963e14861fe3d71c18ace0a8c4587b2f344 /app
parent76f2450412b974ede2a904504cf5bffd28a01776 (diff)
downloadaclog-55f7cae17ec78afadb27fd31c62a55c3bc6b47cf.tar.gz
add account settings
Diffstat (limited to 'app')
-rw-r--r--app/controllers/settings_controller.rb27
-rw-r--r--app/models/account.rb22
-rw-r--r--app/models/notification.rb4
-rw-r--r--app/views/layouts/_base.html.haml1
-rw-r--r--app/views/settings/confirm_deactivation.html.haml5
-rw-r--r--app/views/settings/deactivate.html.haml3
-rw-r--r--app/views/settings/index.html.haml10
7 files changed, 71 insertions, 1 deletions
diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
new file mode 100644
index 0000000..0b86888
--- /dev/null
+++ b/app/controllers/settings_controller.rb
@@ -0,0 +1,27 @@
+class SettingsController < ApplicationController
+ before_filter :authenticate!
+ layout "index"
+
+ def index
+ end
+
+ def update
+ @account.update_settings!(notification: params[:notification] == "true",
+ private: params[:private] == "true")
+ redirect_to action: "index"
+ end
+
+ def confirm_deactivation
+ end
+
+ def deactivate
+ @account.deactivate!
+ reset_session
+ end
+
+ private
+ def authenticate!
+ raise Aclog::Exceptions::LoginRequired unless session[:user_id]
+ @account = session[:account]
+ end
+end
diff --git a/app/models/account.rb b/app/models/account.rb
index de4be88..80c2f80 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -1,17 +1,39 @@
require "msgpack/rpc/transport/unix"
class Account < ActiveRecord::Base
+ ACTIVE = 0; DEACTIVATED = 1
+
belongs_to :user
+ scope :active, -> { where(status: Account::ACTIVE) }
+
def self.create_or_update(hash)
account = where(user_id: hash[:user_id]).first_or_initialize
account.oauth_token = hash[:oauth_token]
account.oauth_token_secret = hash[:oauth_token_secret]
account.consumer_version = hash[:consumer_version]
+ account.status = Account::ACTIVE
account.save if account.changed?
account
end
+ def notification?; self.notification end
+ def private?; self.private end
+ def active?; self.status == Account::ACTIVE end
+
+ def update_settings!(params)
+ self.notification = params[:notification]
+ self.private = params[:private]
+ self.save! if self.changed?
+ end
+
+ def deactivate!
+ self.status = Account::DEACTIVATED
+ self.save!
+
+ update_connection
+ end
+
def update_connection
transport = MessagePack::RPC::UNIXTransport.new
client = MessagePack::RPC::Client.new(transport, File.join(Rails.root, "tmp", "sockets", "receiver.sock"))
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 4f5a68e..f01393f 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -1,7 +1,9 @@
class Notification
def self.notify_favorite(tweet)
if Settings.notification.favorites.include?(tweet.favorites.count)
- reply_favs(tweet, tweet.favorites.count) if tweet.user.registered?
+ if tweet.user.registered? && tweet.user.account.notification?
+ reply_favs(tweet, tweet.favorites.count)
+ end
end
end
diff --git a/app/views/layouts/_base.html.haml b/app/views/layouts/_base.html.haml
index 868c269..907bd45 100644
--- a/app/views/layouts/_base.html.haml
+++ b/app/views/layouts/_base.html.haml
@@ -16,6 +16,7 @@
= link_to "about", about_path
- if logged_in?
%li= link_to "logout", logout_path
+ %li= link_to "settings", settings_path
%li= link_to session[:account].user.screen_name, user_best_path(session[:account].user.screen_name)
- else
%li= link_to "login", "/i/login"
diff --git a/app/views/settings/confirm_deactivation.html.haml b/app/views/settings/confirm_deactivation.html.haml
new file mode 100644
index 0000000..bc58b74
--- /dev/null
+++ b/app/views/settings/confirm_deactivation.html.haml
@@ -0,0 +1,5 @@
+%h1 deactivate
+= form_tag "/i/settings/deactivate", method: :post do
+ = link_to "Cancel", action: "index"
+ = submit_tag
+
diff --git a/app/views/settings/deactivate.html.haml b/app/views/settings/deactivate.html.haml
new file mode 100644
index 0000000..94d3203
--- /dev/null
+++ b/app/views/settings/deactivate.html.haml
@@ -0,0 +1,3 @@
+%h1 deactivated
+ご利用ありがとうございました。記録を停止されますが、データは削除されません。もう一度ログインをすると記録が再開されます。
+
diff --git a/app/views/settings/index.html.haml b/app/views/settings/index.html.haml
new file mode 100644
index 0000000..375bba9
--- /dev/null
+++ b/app/views/settings/index.html.haml
@@ -0,0 +1,10 @@
+%h1 settings
+= form_tag "/i/settings/update", method: :post do
+ = check_box_tag :notification, true, @account.notification
+ = label_tag :notification, "通知を有効にする"
+ = check_box_tag :private, true, @account.private
+ = label_tag :private, "best を非公開にする"
+ = submit_tag
+
+= link_to "Deactivate my account", controller: "settings", action: "confirm_deactivation"
+