-
-
Save ciaranlee/40157 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# SUPER DARING APP TEMPLATE 1.0 | |
# By Peter Cooper | |
# modified to use authlogic, as per the tutorial here: http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup | |
# Link to local copy of edge rails | |
inside('vendor') { run 'ln -s ~/src/ext/git/rails rails' } | |
# Delete unnecessary files | |
run "rm README" | |
run "rm public/index.html" | |
run "rm public/favicon.ico" | |
run "rm public/robots.txt" | |
run "rm -f public/javascripts/*" | |
# Download JQuery | |
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js > public/javascripts/jquery.js" | |
run "curl -L http://jqueryjs.googlecode.com/svn/trunk/plugins/form/jquery.form.js > public/javascripts/jquery.form.js" | |
# Set up git repository | |
git :init | |
git :add => '.' | |
# Copy database.yml for distribution use | |
run "cp config/database.yml config/database.yml.example" | |
# Set up .gitignore files | |
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore" | |
run %{find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore} | |
file '.gitignore', <<-END | |
.DS_Store | |
log/*.log | |
tmp/**/* | |
config/database.yml | |
db/*.sqlite3 | |
END | |
# Set up sessions, RSpec, user model, OpenID, etc | |
generate("rspec") | |
generate("session", "user_session") | |
generate("controller", "user_sessions") | |
generate("rspec_scaffold", "user", "login:string", "crypted_password:string", "password_salt:string", "persistence_token:string", "login_count:integer", "last_request_at:datetime", "last_login_at:datetime", "current_login_at:datetime", "last_login_ip:string", "current_login_ip:string") | |
# set the default controller | |
route "map.resource :user_session" | |
route "map.root :controller => 'user_sessions', :action => 'new'" | |
route "map.resource :account, :controller => 'users'" | |
route "map.resources :users" | |
# set up user_sessions_controller | |
file 'app/controllers/user_sessions_controller.rb', | |
%q{class UserSessionsController < ApplicationController | |
before_filter :require_no_user, :only => [:new, :create] | |
before_filter :require_user, :only => :destroy | |
def new | |
@user_session = UserSession.new | |
end | |
def create | |
@user_session = UserSession.new(params[:user_session]) | |
if @user_session.save | |
flash[:notice] = "Login successful!" | |
redirect_back_or_default account_url | |
else | |
render :action => :new | |
end | |
end | |
def destroy | |
current_user_session.destroy | |
flash[:notice] = "Logout successful!" | |
redirect_back_or_default new_user_session_url | |
end | |
end | |
} | |
# set up user model | |
file 'app/models/user.rb', | |
%q{class User < ActiveRecord::Base | |
acts_as_authentic | |
end | |
} | |
# set up the users_controller | |
file 'app/controllers/users_controller.rb', | |
%q{class UsersController < ApplicationController | |
before_filter :require_no_user, :only => [:new, :create] | |
before_filter :require_user, :only => [:show, :edit, :update] | |
def new | |
@user = User.new | |
end | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
flash[:notice] = "Account registered!" | |
redirect_back_or_default account_url | |
else | |
render :action => :new | |
end | |
end | |
def show | |
@user = @current_user | |
end | |
def edit | |
@user = @current_user | |
end | |
def update | |
@user = @current_user # makes our views "cleaner" and more consistent | |
if @user.update_attributes(params[:user]) | |
flash[:notice] = "Account updated!" | |
redirect_to account_url | |
else | |
render :action => :edit | |
end | |
end | |
end | |
} | |
# set up the application controller | |
file 'app/controllers/application_controller.rb', | |
%q{# 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 | |
protect_from_forgery # See ActionController::RequestForgeryProtection for details | |
# Scrub sensitive parameters from your log | |
# filter_parameter_logging :password | |
filter_parameter_logging :password, :password_confirmation | |
helper_method :current_user_session, :current_user | |
private | |
def current_user_session | |
return @current_user_session if defined?(@current_user_session) | |
@current_user_session = UserSession.find | |
end | |
def current_user | |
return @current_user if defined?(@current_user) | |
@current_user = current_user_session && current_user_session.user | |
end | |
def require_user | |
unless current_user | |
store_location | |
flash[:notice] = "You must be logged in to access this page" | |
redirect_to new_user_session_url | |
return false | |
end | |
end | |
def require_no_user | |
if current_user | |
store_location | |
flash[:notice] = "You must be logged out to access this page" | |
redirect_to account_url | |
return false | |
end | |
end | |
def store_location | |
session[:return_to] = request.request_uri | |
end | |
def redirect_back_or_default(default) | |
redirect_to(session[:return_to] || default) | |
session[:return_to] = nil | |
end | |
end | |
} | |
# set up some views | |
file 'app/views/password_resets/edit.html.erb', | |
%q{<h1>Change My Password</h1> | |
<% form_for @user, :url => password_reset_path, :method => :put do |f| %> | |
<%= f.error_messages %> | |
<%= f.label :password %><br /> | |
<%= f.password_field :password %><br /> | |
<br /> | |
<%= f.label :password_confirmation %><br /> | |
<%= f.password_field :password_confirmation %><br /> | |
<br /> | |
<%= f.submit "Update my password and log me in" %> | |
<% end %> | |
} | |
file 'app/views/password_resets/new.html.erb', | |
%q{<h1>Forgot Password</h1> | |
Fill out the form below and instructions to reset your password will be emailed to you:<br /> | |
<br /> | |
<% form_tag password_resets_path do %> | |
<label>Email:</label><br /> | |
<%= text_field_tag "email" %><br /> | |
<br /> | |
<%= submit_tag "Reset my password" %> | |
<% end %> | |
} | |
file 'app/views/user_sessions/new.html.erb', | |
%q{<h1>Login</h1> | |
<% form_for @user_session, :url => user_session_path do |f| %> | |
<%= f.error_messages %> | |
<%= f.label :login %><br /> | |
<%= f.text_field :login %><br /> | |
<br /> | |
<%= f.label :password %><br /> | |
<%= f.password_field :password %><br /> | |
<br /> | |
<%= f.check_box :remember_me %><%= f.label :remember_me %><br /> | |
<br /> | |
<%= f.submit "Login" %> | |
<% end %> | |
} | |
file 'app/views/user_sessions/new.html.erb', | |
%q{<h1>Login</h1> | |
<% form_for @user_session, :url => user_session_path do |f| %> | |
<%= f.error_messages %> | |
<%= f.label :login %><br /> | |
<%= f.text_field :login %><br /> | |
<br /> | |
<%= f.label :password %><br /> | |
<%= f.password_field :password %><br /> | |
<br /> | |
<%= f.check_box :remember_me %><%= f.label :remember_me %><br /> | |
<br /> | |
<%= f.submit "Login" %> | |
<% end %> | |
} | |
file 'app/views/users/_form.html.erb', | |
%q{<%= form.label :login %><br /> | |
<%= form.text_field :login %><br /> | |
<br /> | |
<%= form.label :password, form.object.new_record? ? nil : "Change password" %><br /> | |
<%= form.password_field :password %><br /> | |
<br /> | |
<%= form.label :password_confirmation %><br /> | |
<%= form.password_field :password_confirmation %><br /> | |
<br /> | |
} | |
file 'app/views/users/edit.html.erb', | |
%q{<h1>Edit My Account</h1> | |
<% form_for @user, :url => account_path do |f| %> | |
<%= f.error_messages %> | |
<%= render :partial => "form", :object => f %> | |
<%= f.submit "Update" %> | |
<% end %> | |
<br /><%= link_to "My Profile", account_path %> | |
} | |
file 'app/views/users/new.html.erb', | |
%q{<h1>Register</h1> | |
<% form_for @user, :url => account_path do |f| %> | |
<%= f.error_messages %> | |
<%= render :partial => "form", :object => f %> | |
<%= f.submit "Register" %> | |
<% end %> | |
} | |
file 'app/views/users/show.html.erb', | |
%q{<p> | |
<b>Login:</b> | |
<%=h @user.login %> | |
</p> | |
<p> | |
<b>Login count:</b> | |
<%=h @user.login_count %> | |
</p> | |
<p> | |
<b>Last request at:</b> | |
<%=h @user.last_request_at %> | |
</p> | |
<p> | |
<b>Last login at:</b> | |
<%=h @user.last_login_at %> | |
</p> | |
<p> | |
<b>Current login at:</b> | |
<%=h @user.current_login_at %> | |
</p> | |
<p> | |
<b>Last login ip:</b> | |
<%=h @user.last_login_ip %> | |
</p> | |
<p> | |
<b>Current login ip:</b> | |
<%=h @user.current_login_ip %> | |
</p> | |
<%= link_to 'Edit', edit_account_path %> | |
} | |
# run migrations | |
rake('db:migrate') | |
# Install all gems | |
gem 'authlogic' | |
# gem 'rspec' | |
# gem 'rspec-rails' | |
# rake('gems:install', :sudo => true) | |
# Initialize submodules | |
# git :submodule => "init" | |
# Commit all work so far to the repository | |
git :add => '.' | |
git :commit => "-a -m 'Initial commit'" | |
# Success! | |
puts "SUCCESS!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment