Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
78 changed files
with
5,928 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.sqlite3 | ||
tmp | ||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
# Filters added to this controller apply to all controllers in the application. | ||
# Likewise, all the methods added will be available for all controllers. | ||
|
||
class ApplicationController < ActionController::Base | ||
helper :all # include all helpers, all the time | ||
helper :all | ||
protect_from_forgery # See ActionController::RequestForgeryProtection for details | ||
filter_parameter_logging :password | ||
|
||
protected | ||
|
||
def current_user | ||
@current_user ||= User.find_by_id(session[:user_id]) | ||
end | ||
helper_method :current_user | ||
|
||
def current_user=(user) | ||
session[:user_id] = user.try(:id) | ||
@current_user = user | ||
end | ||
|
||
# Scrub sensitive parameters from your log | ||
# filter_parameter_logging :password | ||
end | ||
def access_denied | ||
flash[:error] = "You do not have access!" | ||
redirect_to login_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class HomeController < ApplicationController | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class RestfulController < ApplicationController | ||
before_filter :can_create, :only=>%w[new create] | ||
before_filter :can_write, :only=>%w[edit update destroy] | ||
before_filter :can_read, :only=>%w[show] | ||
|
||
make_resourceful do | ||
actions :all | ||
end | ||
|
||
protected | ||
|
||
def can_create | ||
can_do(:create) | ||
end | ||
|
||
def can_write | ||
can_do(:write) | ||
end | ||
|
||
def can_read | ||
can_do(:read) | ||
end | ||
|
||
def can_do(action) | ||
return if (current_user||User.new).send("can_#{action}?", requested_object) | ||
access_denied | ||
end | ||
|
||
def requested_object | ||
case params[:action] | ||
when 'new','create' then build_object | ||
else current_object | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class UsersController < RestfulController | ||
skip_before_filter :verify_authenticity_token, :only => [:create] | ||
|
||
def new | ||
end | ||
|
||
def create | ||
if data = RPXNow.user_data(params[:token]) | ||
data = {:name=>data[:username],:email=>data[:email], :identifier=>data[:identifier]} | ||
self.current_user = User.find_by_identifier(data[:identifier]) || User.create!(data) | ||
redirect_to '/' | ||
else | ||
flash[:error] = :default | ||
redirect_to login_path | ||
end | ||
end | ||
|
||
def destroy | ||
self.current_user = nil | ||
redirect_to login_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module LinkHelper | ||
def link_to_s(object) | ||
link_to object.to_s, object | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
class User < ActiveRecord::Base | ||
NAME_FORMAT = /^[-_a-zA-Z\d]+$/ | ||
|
||
validates_uniqueness_of :name, :allow_nil=>false, :on=>:update | ||
validates_uniqueness_of :email, :allow_nil=>true, :on=>:update | ||
validates_format_of :name, :with=>NAME_FORMAT, :on=>:update | ||
validates_format_of :email, :with=>/.+@.+\..+/, :allow_nil=>true, :on=>:update | ||
|
||
before_create :clean_name, :uniquify_name, :remove_email_when_taken | ||
|
||
def to_s | ||
name | ||
end | ||
|
||
def can_create?(object) | ||
return true if admin? | ||
case object | ||
when User then anonymouse? | ||
else raise "NOT SUPPORTED" | ||
end | ||
end | ||
|
||
def can_write?(object) | ||
return true if admin? | ||
case object | ||
when User then object == self | ||
else raise "NOT SUPPORTED" | ||
end | ||
end | ||
|
||
def can_read?(object) | ||
return true if admin? | ||
case object | ||
when User then true | ||
else raise "NOT SUPPORTED" | ||
end | ||
end | ||
|
||
protected | ||
|
||
def anonymouse? | ||
new_record? | ||
end | ||
|
||
def clean_name | ||
self.name = name.split(//).select{|x| x =~ NAME_FORMAT}.to_s | ||
end | ||
|
||
def uniquify_name | ||
while User.find_by_name(name) | ||
self.name = "#{name}#{rand(100)}" | ||
end | ||
end | ||
|
||
def remove_email_when_taken | ||
self.email = nil if email and User.find_by_email(email) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% | ||
{ | ||
:error=>{:color=>'red', :default=>'FAIL!'}, | ||
:notice=>{:color=>'green', :default=>'SUCCESS!'} | ||
}.each do |k, v| | ||
%> | ||
<% if flash and flash[k] %> | ||
<div style="color:<%=v[:color]%>"> | ||
<% if flash[k] == :default %> | ||
<%= v[:default] %> | ||
<% else %> | ||
<%= flash[k] %> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% if current_user %> | ||
Hello <%= link_to_s current_user %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<html> | ||
<head> | ||
<title>CMDLiner</title> | ||
<link rel="shortcut icon" href="favicon.ico" > | ||
</head> | ||
<body> | ||
<div> | ||
<%= render 'layouts/user' %> | ||
<%= render 'layouts/flash' %> | ||
</div> | ||
|
||
<div> | ||
<%= yield %> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= RPXNow.embed_code('cmdliner', users_url) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello I am <%= @user %> and this is my page! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
ActionController::Routing::Routes.draw do |map| | ||
map.root :controller => 'home' | ||
map.login '/login', :controller => "users", :action => "new" | ||
|
||
map.resources :users | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class AddUsers < ActiveRecord::Migration | ||
def self.up | ||
create_table :users do |t| | ||
t.string :name, :null=>false | ||
t.string :identifier, :null=>false, :unique=>true | ||
t.string :email, :uniq=>true | ||
t.string :website | ||
t.boolean :admin, :default=>false, :null=>false | ||
t.timestamps | ||
end | ||
|
||
# enforce uniqueness | ||
add_index :users, :name, :unique => true | ||
add_index :users, :email, :unique => true | ||
end | ||
|
||
def self.down | ||
drop_table :users | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This file is auto-generated from the current state of the database. Instead of editing this file, | ||
# please use the migrations feature of Active Record to incrementally modify your database, and | ||
# then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your database schema. If you need | ||
# to create the application database on another system, you should be using db:schema:load, not running | ||
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended to check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(:version => 20090910191750) do | ||
|
||
create_table "users", :force => true do |t| | ||
t.string "name", :null => false | ||
t.string "identifier", :null => false | ||
t.string "email" | ||
t.string "website" | ||
t.boolean "admin", :default => false, :null => false | ||
t.datetime "created_at" | ||
t.datetime "updated_at" | ||
end | ||
|
||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true | ||
add_index "users", ["name"], :name => "index_users_on_name", :unique => true | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# http://github.com/grosser/clear_empty_attributes/blob/master/lib/clear_empty_attributes.rb | ||
class ActiveRecord::Base | ||
before_validation :clear_empty_attrs | ||
protected | ||
def clear_empty_attrs | ||
@attributes.each do |key,value| | ||
self[key] = nil if value.is_a?(String) && value.blank? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class String | ||
def split_after(max, options={}) | ||
zero_length_space = '' #aka ​ | ||
options[:with] ||= zero_length_space | ||
split(/ /).map do |part| | ||
part = part.mb_chars | ||
if part.length > max | ||
part[0...max] + options[:with] + part[max..-1].to_s.split_after(max) | ||
else | ||
part | ||
end | ||
end * ' ' | ||
end | ||
end | ||
|
||
|
||
#ActionView text helpers | ||
class String | ||
%w[auto_link excerpt highlight sanitize simple_format strip_tags word_wrap].each do |method| | ||
eval <<-EVAL | ||
def #{method}(*args) | ||
ActionController::Base.helpers.#{method}(self, *args) | ||
end | ||
EVAL | ||
|
||
def truncate(*args) | ||
#called with only a number | ||
if args.size == 1 and args[0].to_s =~ /^\d+$/ | ||
ActionController::Base.helpers.truncate(self, :length=>args[0]) | ||
else | ||
ActionController::Base.helpers.truncate(self, *args) | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
# user.name.blank_to_nil || 'default name' | ||
class String | ||
def blank_to_nil | ||
blank? ? nil : self | ||
end | ||
end | ||
|
||
class NilClass | ||
def blank_to_nil | ||
self | ||
end | ||
end |
Oops, something went wrong.