fcid 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +22 -0
- data/app/controllers/fcid/feeds_controller.rb +22 -0
- data/app/controllers/fcid/friendships_controller.rb +74 -0
- data/app/controllers/fcid/messages_controller.rb +24 -0
- data/app/controllers/fcid/session_controller.rb +80 -0
- data/app/controllers/fcid/users_controller.rb +25 -0
- data/app/views/fcid/_ajax_new.html.erb +3 -0
- data/app/views/fcid/_announce.html.erb +5 -0
- data/app/views/fcid/_footer.html.erb +0 -0
- data/app/views/fcid/_navigation.html.erb +0 -0
- data/app/views/fcid/create.html.erb +6 -0
- data/app/views/fcid/feeds/_feed.html.erb +29 -0
- data/app/views/fcid/feeds/index.html.erb +4 -0
- data/app/views/fcid/feeds/show.html.erb +0 -0
- data/app/views/fcid/friendships/index.html.erb +5 -0
- data/app/views/fcid/friendships/new.html.erb +22 -0
- data/app/views/fcid/messages/_message.html.erb +0 -0
- data/app/views/fcid/messages/_message_tr.html.erb +8 -0
- data/app/views/fcid/messages/index.html.erb +20 -0
- data/app/views/fcid/new.html.erb +30 -0
- data/app/views/fcid/session/new.html.erb +40 -0
- data/app/views/fcid/users/_ajax_new.html.erb +3 -0
- data/app/views/fcid/users/create.html.erb +6 -0
- data/app/views/fcid/users/new.html.erb +33 -0
- data/app/views/friendships/new.html.erb +22 -0
- data/app/views/session/new.html.erb +20 -0
- data/config/routes.rb +29 -0
- data/lib/fcid/active_resource/exceptions.rb +7 -0
- data/lib/fcid/active_resource/extra_params.rb +66 -0
- data/lib/fcid/active_resource/session.rb +45 -0
- data/lib/fcid/base.rb +7 -0
- data/lib/fcid/config.rb +88 -0
- data/lib/fcid/consumer.rb +51 -0
- data/lib/fcid/controller.rb +46 -0
- data/lib/fcid/email.rb +9 -0
- data/lib/fcid/engine.rb +5 -0
- data/lib/fcid/feed.rb +17 -0
- data/lib/fcid/friendship.rb +5 -0
- data/lib/fcid/helpers.rb +49 -0
- data/lib/fcid/message.rb +5 -0
- data/lib/fcid/notification.rb +5 -0
- data/lib/fcid/publisher/base.rb +398 -0
- data/lib/fcid/session.rb +5 -0
- data/lib/fcid/user.rb +50 -0
- data/lib/fcid/user_methods.rb +39 -0
- data/lib/fcid/version.rb +3 -0
- data/lib/fcid.rb +12 -0
- data/lib/fcid_client.rb +14 -0
- data/lib/tasks/fcid_tasks.rake +4 -0
- data/lib/vendor/authenticated_system.rb +153 -0
- data/lib/vendor/authenticated_test_helper.rb +11 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/fcid_test.rb +9 -0
- data/test/test_helper.rb +15 -0
- metadata +169 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Fcid
|
3
|
+
module ActiveResource
|
4
|
+
|
5
|
+
module Base
|
6
|
+
module Session
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.send(:extend,ClassMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
# Fcid::Message.with_session current_user do
|
15
|
+
# message = Fcid::Message.new :message=>"x"
|
16
|
+
# message.save
|
17
|
+
# end
|
18
|
+
def with_session(user_id,&block)
|
19
|
+
user_id = user_id.to_param
|
20
|
+
# 计算一个 user_id 的hash加密传送给 fcid
|
21
|
+
|
22
|
+
timestamp = Time.now.to_i.to_s
|
23
|
+
key = user_id + Fcid.api_secret + timestamp
|
24
|
+
sig = Digest::MD5.hexdigest(key)
|
25
|
+
params = {:fcid_user_id=>user_id,:fcid_sig=>sig,:fcid_time=>timestamp}
|
26
|
+
params.each_pair do |key,value|
|
27
|
+
self.extra_params[key] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
Rails.logger.debug "extra params : #{self.extra_params.inspect}"
|
31
|
+
begin
|
32
|
+
yield
|
33
|
+
ensure
|
34
|
+
params.keys.each do |key|
|
35
|
+
self.extra_params.delete key
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/lib/fcid/base.rb
ADDED
data/lib/fcid/config.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Fcid
|
3
|
+
ROOT = File.join(Rails.root.to_s,"vendor","plugins","fcid")
|
4
|
+
def self.config
|
5
|
+
file = File.join(Rails.root.to_s,"config","fcid.yml")
|
6
|
+
@@config ||= YAML.load_file(file)[Rails.env]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.consumer
|
10
|
+
@consumer ||= OAuth::Consumer.new(api_key, api_secret, {
|
11
|
+
:site => url,
|
12
|
+
:scheme => :header,
|
13
|
+
:http_method => :post,
|
14
|
+
:request_token_path => "/oauth/request_token",
|
15
|
+
:access_token_path => "/oauth/access_token",
|
16
|
+
:authorize_path => "/oauth/authorize"
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.host
|
21
|
+
config["host"].to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.host_with_port
|
25
|
+
if port.blank? || port.to_s == "80"
|
26
|
+
host
|
27
|
+
else
|
28
|
+
"#{host}:#{port}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.url(*args)
|
33
|
+
args = args.collect &:to_s
|
34
|
+
File.join("http://#{host_with_port}",*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.port
|
38
|
+
config["port"].to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.api_key
|
42
|
+
config["api_key"].to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.api_secret
|
46
|
+
config["api_secret"].to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.email
|
50
|
+
columns["email"].to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.user
|
54
|
+
config["user"].to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def self.password
|
59
|
+
config["password"].to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def self.css
|
64
|
+
"http://#{host_with_port}/stylesheets/common.css"
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.javascripts
|
68
|
+
%w{dialog}.collect { |js|
|
69
|
+
"http://#{host_with_port}/javascripts/#{js}.js"
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
# 加密
|
74
|
+
def self.encrypt(user_id)
|
75
|
+
end
|
76
|
+
|
77
|
+
# 解密
|
78
|
+
def self.decrypt
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.columns
|
82
|
+
hash = {}
|
83
|
+
[config['columns']].flatten.compact.each do |o|
|
84
|
+
hash = (o.kind_of?(Hash) ? hash.merge(o) : {o=>o}).merge(hash)
|
85
|
+
end
|
86
|
+
hash
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Example usage:
|
2
|
+
#
|
3
|
+
# class Account < ActiveResource::Base
|
4
|
+
# self.site = "http://localhost:3000"
|
5
|
+
# end
|
6
|
+
#
|
7
|
+
# consumer = Consumer.new( user.access_token, Account )
|
8
|
+
# consumer.find(1) # => equivalent to Account.find(1), but with OAuth
|
9
|
+
|
10
|
+
module Fcid
|
11
|
+
|
12
|
+
class Consumer
|
13
|
+
attr_accessor :klass, :token
|
14
|
+
|
15
|
+
def initialize(token, resource_klass)
|
16
|
+
self.token = token
|
17
|
+
self.klass = Class.new(resource_klass) do
|
18
|
+
@token = token
|
19
|
+
|
20
|
+
|
21
|
+
@connection = Class.new(::ActiveResource::Connection) {
|
22
|
+
attr_accessor :token
|
23
|
+
|
24
|
+
|
25
|
+
%w( get delete head ).each do |verb|
|
26
|
+
define_method verb do |*args|
|
27
|
+
token.send(verb,*args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
%w( put post ).each do |verb|
|
32
|
+
define_method verb do |*args|
|
33
|
+
token.send(*args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
}.new(self.site, format)
|
37
|
+
|
38
|
+
@connection.token = token
|
39
|
+
end
|
40
|
+
|
41
|
+
%w( element_name collection_name ).each do |attribute|
|
42
|
+
self.klass.send "#{attribute}=", resource_klass.send(attribute)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def method_missing(method, *args)
|
47
|
+
klass.send method, *args if klass && klass.respond_to?(method)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Fcid
|
3
|
+
module Controller
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
|
9
|
+
def login_required
|
10
|
+
unless logged_in?
|
11
|
+
flash[:error] = "此操作需要登录."
|
12
|
+
redirect_to new_fcid_session_path(:redirect_to => url_for(params))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def logged_in?
|
17
|
+
!!current_user
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_user=(user)
|
21
|
+
session[:user_id] = user.try(:id)
|
22
|
+
@current_user = user
|
23
|
+
end
|
24
|
+
|
25
|
+
def current_user
|
26
|
+
@current_user ||= session[:user_id] && lambda{
|
27
|
+
begin
|
28
|
+
user = ::User.find(session[:user_id])
|
29
|
+
rescue Exception =>e
|
30
|
+
session.delete :user_id
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
}.bind(self).call
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
module ClassMethods
|
39
|
+
end
|
40
|
+
|
41
|
+
included do
|
42
|
+
helper_method :logged_in?,:current_user
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/fcid/email.rb
ADDED
data/lib/fcid/engine.rb
ADDED
data/lib/fcid/feed.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Fcid
|
3
|
+
class Feed < Base
|
4
|
+
|
5
|
+
def pictures
|
6
|
+
r = []
|
7
|
+
3.times do |index|
|
8
|
+
index = index + 1
|
9
|
+
url = send("picture#{index}_url")
|
10
|
+
link = send("picture#{index}_link")
|
11
|
+
r << {:url=>url,:link=>link} unless url.blank?
|
12
|
+
end
|
13
|
+
r
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/fcid/helpers.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Fcid
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def avatar(user,options={})
|
6
|
+
url = case user
|
7
|
+
when String
|
8
|
+
user
|
9
|
+
else
|
10
|
+
user.avatar
|
11
|
+
end
|
12
|
+
options = {:type=>:thumb,:link=>true}.merge(options)
|
13
|
+
url = "http://#{Fcid.host_with_port}/#{url}" unless url=~ /^http:\/\//
|
14
|
+
if options[:type]
|
15
|
+
# avatars_50_original_AVENIR003.jpg
|
16
|
+
url = url.gsub(/avatars_(\d+?)_original_(.+?)$/i,"avatars_\\1_#{options[:type]}_\\2")
|
17
|
+
end
|
18
|
+
img = image_tag(url,:alt=>user.uname,:class => "avatar avatar-#{options[:type]}")
|
19
|
+
img = link_to(img,user_path(user),:class => "uname",'data-user-id' => user.id) if options[:link]
|
20
|
+
img
|
21
|
+
end
|
22
|
+
|
23
|
+
def uname(user,options={})
|
24
|
+
options.reverse_merge! :link=>true
|
25
|
+
uname = user.name
|
26
|
+
if options[:link]
|
27
|
+
link_to uname,user_path(user),:class => "uname",'data-user-id' => user.id
|
28
|
+
else
|
29
|
+
uname
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def make_friend(user,options={})
|
35
|
+
options.reverse_merge! :ajax=>true
|
36
|
+
url = new_friendship_path(:friend_id=>user.id,:nolayout=>true)
|
37
|
+
link_to_function("加为好友","Boxy.load('#{url}',{title:'添加#{user.name}为好友'})")
|
38
|
+
end
|
39
|
+
|
40
|
+
def message_to(user,options={})
|
41
|
+
options.reverse_merge! :ajax=>true
|
42
|
+
url = new_message_path(:friend_id=>user.id,:nolayout=>true)
|
43
|
+
link_to_function("发送短信","Boxy.load('#{url}',{title:'发送短信息给#{user.name}'})")
|
44
|
+
end
|
45
|
+
|
46
|
+
alias profile_pic avatar
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/fcid/message.rb
ADDED