Skip to content

Commit

Permalink
added controllers
Browse files Browse the repository at this point in the history
added models
added haml plugins
  • Loading branch information
olivM committed Apr 6, 2009
1 parent 37dc128 commit b405c22
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/controllers/account_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class AccountController < ApplicationController
before_filter :login_required

def index

end

def notebooks
@notebooks = User.find(session[:user_id]).notebooks
end

end
23 changes: 23 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,27 @@ class ApplicationController < ActionController::Base

# Scrub sensitive parameters from your log
# filter_parameter_logging :password

def login_required
if session[:user_id]
@user ||= User.find(session[:user_id])
@access_token ||= OAuth::AccessToken.new(get_consumer, @user.oauth_token, @user.oauth_secret)
else
redirect_to :controller => 'session', :action => 'new'
end
end

def get_consumer
require 'oauth/consumer'
require 'oauth/signature/rsa/sha1'
consumer = OAuth::Consumer.new(CONSUMER_KEY,CONSUMER_SECRET,
{
:site => "https://www.google.com",
:request_token_path => "/accounts/OAuthGetRequestToken",
:access_token_path => "/accounts/OAuthGetAccessToken",
:authorize_path=> "/accounts/OAuthAuthorizeToken",
:signature_method => "RSA-SHA1",
:private_key_file => PATH_TO_PRIVATE_KEY})
end

end
31 changes: 31 additions & 0 deletions app/controllers/session_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class SessionController < ApplicationController
skip_before_filter :login_required, :only => [:new, :create]

def new
consumer = get_consumer
request_token = consumer.get_request_token( {}, {:scope => "https://www.google.com/base/feeds/ https://www.google.com/m8/feeds/"})
session[:oauth_secret] = request_token.secret
next_url = "http://localhost:3000/session/create"
redirect_to request_token.authorize_url + "&oauth_callback=#{next_url}"
end

def create
request_token = OAuth::RequestToken.new(get_consumer, params[:oauth_token], session[:oauth_secret])
access_token = request_token.get_access_token
xml = XmlSimple.xml_in(access_token.get("https://www.google.com/m8/feeds/contacts/default/full/").body)
email = xml["author"].first["email"].first
user = User.find_or_create_by_email(email)
user.name = xml["author"].first["name"].first
user.oauth_token = access_token.token
user.oauth_secret = access_token.secret
user.save
session[:user_id] = user.id
redirect_to :controller => 'account'
end

def delete
reset_session
flash[:notice] = "You have been logged out"
redirect_to :action => 'new'
end
end
2 changes: 2 additions & 0 deletions app/helpers/account_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AccountHelper
end
2 changes: 2 additions & 0 deletions app/helpers/session_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SessionHelper
end
6 changes: 6 additions & 0 deletions app/models/annoter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Annoter < ActiveRecord::Base

belongs_to :notebook
belongs_to :user

end
19 changes: 19 additions & 0 deletions app/models/notebook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Notebook < ActiveRecord::Base

belongs_to :creator, :class_name => "User"

has_many :annoters

has_many :users, :through => :annoters

has_many :readers, :through => :annoters, :source => :user, :conditions => "status = 'READER' "
has_many :writers, :through => :annoters, :source => :user, :conditions => "status = 'WRITER' "

validates_presence_of :name, :creator_id

def after_create
# create the notebook_user entry
self.writers << self.creator
end

end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class User < ActiveRecord::Base
validates_presence_of :email, :oauth_token, :oauth_secret
validates_uniqueness_of :email

has_many :annoters
has_many :notebooks, :through => :annoters

end
3 changes: 3 additions & 0 deletions app/views/account/index.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- for notebook in @notebooks
%li
%a{:href=> "/notebook/notebook.name"}=notebook.name
2 changes: 2 additions & 0 deletions app/views/layouts/main.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#sidebar
= render_component :controller => 'account', :action => 'notebooks'
17 changes: 17 additions & 0 deletions config/rsacert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICpDCCAg2gAwIBAgIJAKZCTXXCnDupMA0GCSqGSIb3DQEBBQUAMEExCzAJBgNV
BAYTAkZSMQ4wDAYDVQQIEwVQYXJpczEOMAwGA1UEBxMFUGFyaXMxEjAQBgNVBAoT
CU1haGktTWFoaTAeFw0wOTA0MDYwNjU5NDJaFw0xMDA0MDYwNjU5NDJaMEExCzAJ
BgNVBAYTAkZSMQ4wDAYDVQQIEwVQYXJpczEOMAwGA1UEBxMFUGFyaXMxEjAQBgNV
BAoTCU1haGktTWFoaTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyTHvRk96
YeaupMCahVsG+oqzqunkbtpIqnT77JfWfhI67BbY2aBl6f6ZwSMIW2cyT6ti57bV
jqqAZLC9O9dIXIXuay7PoFVdlJoVRknkYjJrYZVRNqJCAg/hdxzzBIzBdIE6V7Dh
96nbKzjZUaFKxIzA9swQlNqPYtKbeYzSbJ8CAwEAAaOBozCBoDAdBgNVHQ4EFgQU
rJ6kcXLDIQOIXDNuDDEl3Jq/MCowcQYDVR0jBGowaIAUrJ6kcXLDIQOIXDNuDDEl
3Jq/MCqhRaRDMEExCzAJBgNVBAYTAkZSMQ4wDAYDVQQIEwVQYXJpczEOMAwGA1UE
BxMFUGFyaXMxEjAQBgNVBAoTCU1haGktTWFoaYIJAKZCTXXCnDupMAwGA1UdEwQF
MAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAuRyBerksnVISvryfPzspMr5kD+cDsrs3
yqjHe2uCT8+zBx+BJx9RUOaTWwa8x9WHkZh2Qvl2dwJs5arcvY85M4Af4TCuYEKH
XbxhNnmy9++FcB+28oymYo/8nc2ofcHTssVCgUz0YX6GqG/9+kER3NfT4gY1xImw
0in/Lnp5m5U=
-----END CERTIFICATE-----
15 changes: 15 additions & 0 deletions config/rsakey.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDJMe9GT3ph5q6kwJqFWwb6irOq6eRu2kiqdPvsl9Z+EjrsFtjZ
oGXp/pnBIwhbZzJPq2LnttWOqoBksL0710hche5rLs+gVV2UmhVGSeRiMmthlVE2
okICD+F3HPMEjMF0gTpXsOH3qdsrONlRoUrEjMD2zBCU2o9i0pt5jNJsnwIDAQAB
AoGAXrkixQCQRt17pdeEKHrVy0lYE4Sw5rvgcFhJb3eBJbPhh9ut1rAcq1ESBItA
2P+6ASZYl21OGDAP6NgJD85oo0khuDwt7yWOUy8hFT51QPFx3lVhQFLnloriKbSa
9bYSw9ZoloFscwj+jLS04Bq9etBllqik9cgaaj0+rktGl/kCQQDqFap7wEI+2G54
1BgMvLm9CjDgZ/t+c1Vn4GiyfeqUQBhDvBeXLRZM+ei2/ZyxRJihwN/2ogFE4liM
aZU6dRTTAkEA3AgAGMDePMXofzkHrcfkZ+pW4wdNJI4FgOllpI4OSdgJ2c+eWDDQ
sNKkqDn4GH3Mr/95iihXBnhkxWDZA3IZhQJBAKTkUCxOGRwV73Ozy6ElTB1K0XUy
Kik/6xh6LqYVJqn5oF4OX/vA6eWdYP2OFtOUQ4Qlzl34brZsTv3R3inIkbsCQGEP
rms8+Uw5yXwFvltsqFcmyrlPiTos5ESfsNTMTYVJpd7NdX5V2lmGMlh7afPz2o1w
1z6Y2PrjtSBUvqaEeLkCQQCAJ7TsqeQ02gY6qz/LFP1QRJTxG3jdUigQRKPyl9Tr
typsKkQFW0xBp5TXCcAY2yyeUg7UiOkB0G3Y/4SoEu8M
-----END RSA PRIVATE KEY-----
7 changes: 7 additions & 0 deletions test/fixtures/annoters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

# one:
# column: value
#
# two:
# column: value
7 changes: 7 additions & 0 deletions test/fixtures/notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

# one:
# column: value
#
# two:
# column: value
13 changes: 13 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
name: MyString
oauth_token: MyString
oauth_secret: MyString
email: MyString

two:
name: MyString
oauth_token: MyString
oauth_secret: MyString
email: MyString
8 changes: 8 additions & 0 deletions test/functional/account_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class AccountControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
8 changes: 8 additions & 0 deletions test/functional/session_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class SessionControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
8 changes: 8 additions & 0 deletions test/unit/annoters_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class AnnotersTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/account_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class AccountHelperTest < ActionView::TestCase
end
4 changes: 4 additions & 0 deletions test/unit/helpers/session_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class SessionHelperTest < ActionView::TestCase
end
8 changes: 8 additions & 0 deletions test/unit/notebook_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class NotebookTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
8 changes: 8 additions & 0 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
8 changes: 8 additions & 0 deletions vendor/plugins/haml/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
begin
require File.join(File.dirname(__FILE__), 'lib', 'haml') # From here
rescue LoadError
require 'haml' # From gem
end

# Load Haml and Sass
Haml.init_rails(binding)

0 comments on commit b405c22

Please sign in to comment.