Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed May 23, 2008
0 parents commit a0081bd
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2008 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 16 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
h1. simple_restful_openid plugin

I couldn't make sense of some of the others, so I wrote my own.

h2. Usage

script/plugin install git://github.com/seven1m/simple_restful_openid.git
script/generate simple_restful_openid

To sign in, browse to /session/new

h2. Requirements

Edge Rails or Rails 2.1+

Copyright (c) 2008 Tim Morgan, released under the MIT license
22 changes: 22 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the simple_restful_openid plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the simple_restful_openid plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'SimpleRestfulOpenid'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
8 changes: 8 additions & 0 deletions generators/simple_restful_openid/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Description:
Generates a Sessions controller and adds a resource route for it.

Example:
./script/generate simple_restful_openid

This will create:
app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require File.dirname(__FILE__) + '/../../lib/route_resource_command.rb'
require File.dirname(__FILE__) + '/../../lib/config_gem_command.rb'

class SimpleRestfulOpenidGenerator < Rails::Generator::Base
def manifest
record do |m|
m.class_collisions 'Session'
m.file 'sessions_controller.rb', 'app/controllers/sessions_controller.rb'
m.directory 'app/views/sessions'
m.file 'new.html.erb', 'app/views/sessions/new.html.erb'
m.route_resource :session
m.config_gem 'ruby-openid', :version => '>= 2.0', :lib => 'openid/consumer'
end
end
end

7 changes: 7 additions & 0 deletions generators/simple_restful_openid/templates/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% form_tag session_url, :method => :post do %>
<p>
<label for="url">OpenID URL:</label>
<%= text_field_tag :url %>
<%= submit_tag 'Sign In' %>
</p>
<% end %>
48 changes: 48 additions & 0 deletions generators/simple_restful_openid/templates/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'openid/store/filesystem'

class SessionsController < ApplicationController
# login page
def new
end

# login form submission
def create
store = OpenID::Store::Filesystem.new(RAILS_ROOT + '/tmp')
consumer = OpenID::Consumer.new(session, store)
oid_req = consumer.begin params[:url]
realm = request.protocol + request.host_with_port
return_to = session_url
redirect_to oid_req.redirect_url(realm, return_to)
end

def show
if params['openid.mode']
# the openid provider sends the browser back here
# we'd rather use the update method because it's more RESTful
update
else
redirect_to new_session_path
end
end

# back from openid provider
def update
store = OpenID::Store::Filesystem.new(RAILS_ROOT + '/tmp')
consumer = OpenID::Consumer.new(session, store)
url = request.protocol + request.host_with_port + request.relative_url_root + request.path
response = consumer.complete(params.reject { |k, v| k !~ /^openid\./ }, url)
if response.status == :success
session[:url] = response.identity_url
redirect_to snippets_path
else
flash[:notice] = 'Failure signing in with OpenID.'
redirect_to new_session_path
end
end

# sign out
def destroy
session[:url] = nil
redirect_to new_session_path
end
end
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# no hook code here
1 change: 1 addition & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# no install hook code here
19 changes: 19 additions & 0 deletions lib/config_gem_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Rails
module Generator
module Commands
class Create < Base
def config_gem(name, options={})
sentinel = 'Rails::Initializer.run do |config|'
name_and_options = name.inspect
name_and_options << ", #{options.inspect}" if options.any?
logger.route "config.gem #{name_and_options}"
unless options[:pretend]
gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
"#{match}\n config.gem #{name_and_options}\n"
end
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/route_resource_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Rails
module Generator
module Commands
class Create < Base
def route_resource(*resources)
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
sentinel = 'ActionController::Routing::Routes.draw do |map|'

logger.route "map.resource #{resource_list}"
unless options[:pretend]
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
"#{match}\n map.resource #{resource_list}\n"
end
end
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/simple_restful_openid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SimpleRestfulOpenid
4 changes: 4 additions & 0 deletions tasks/simple_restful_openid_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :simple_restful_openid do
# # Task goes here
# end
8 changes: 8 additions & 0 deletions test/simple_restful_openid_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test/unit'

class SimpleRestfulOpenidTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_this_plugin
flunk
end
end
1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit a0081bd

Please sign in to comment.