diff options
| author | mo k <mo@mokhan.ca> | 2012-08-26 09:51:11 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-08-26 09:51:11 -0600 |
| commit | b3640bddef1f6cc73aaf12c67e3525dbb6f17d98 (patch) | |
| tree | fae5d56de769b063b1a8a677dbd4200789f7b1bb | |
| parent | b49633af3d9454f7afd351a65820bbbd3be0ab5d (diff) | |
create home controller and user.
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | app/assets/stylesheets/application.css | 13 | ||||
| -rw-r--r-- | app/assets/stylesheets/custom.css.scss (renamed from app/assets/stylesheets/application.css.scss) | 0 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 14 | ||||
| -rw-r--r-- | app/controllers/home_controller.rb | 6 | ||||
| -rw-r--r-- | app/controllers/sessions_controller.rb | 3 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 3 | ||||
| -rw-r--r-- | app/models/user.rb | 3 | ||||
| -rw-r--r-- | app/views/home/index.html.erb | 2 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20120826005440_create_users.rb | 11 | ||||
| -rw-r--r-- | public/index.html | 241 |
13 files changed, 55 insertions, 246 deletions
@@ -20,6 +20,7 @@ group :assets do end gem 'jquery-rails' +gem 'bootstrap-sass' gem 'bootswatch-rails' gem 'omniauth-github' diff --git a/Gemfile.lock b/Gemfile.lock index 0053919..093f065 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,7 @@ GEM i18n (~> 0.6) multi_json (~> 1.0) arel (3.0.2) + bootstrap-sass (2.0.4.0) bootswatch-rails (0.0.12) railties (>= 3.1) builder (3.0.0) @@ -127,6 +128,7 @@ PLATFORMS ruby DEPENDENCIES + bootstrap-sass bootswatch-rails coffee-rails (~> 3.2.1) jquery-rails diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..3192ec8 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,13 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_tree . + */ diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/custom.css.scss index 081c605..081c605 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/custom.css.scss diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e8065d9..c58eda4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,17 @@ class ApplicationController < ActionController::Base protect_from_forgery + helper_method :current_user + + private + + def current_user + @current_user ||= User.find(session[:user_id]) if session[:user_id] + end + + def authenticate! + unless current_user + flash[:notice] = "please sign in" + redirect_to('/auth/github') + end + end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..9d5086c --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,6 @@ +class HomeController < ApplicationController + def index + @key = ENV['GITHUB_KEY'] + @secret = ENV['GITHUB_SECRET'] + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 8d64438..900f76f 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,7 +1,8 @@ class SessionsController < ApplicationController def create - auth = request.env["omniauth.auth"] Rails.logger.info auth + + auth = request.env["omniauth.auth"] user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth) session[:user_id] = user.id redirect_to root_url, :notice => "Signed in!" diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ac9d11f..de6be79 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,2 @@ module ApplicationHelper - def current_user - - end end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..5b54886 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,3 @@ +class User < ActiveRecord::Base + attr_accessible :name, :provider, :uid +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..64e60ba --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,2 @@ +<p><%= @key %></p> +<p><%= @secret %></p> diff --git a/config/routes.rb b/config/routes.rb index bdc5ca9..410ef9d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,7 +51,7 @@ Techtalk::Application.routes.draw do # You can have the root of your site routed with "root" # just remember to delete public/index.html. - # root :to => 'welcome#index' + root :to => 'home#index' # See how all your routes lay out with "rake routes" diff --git a/db/migrate/20120826005440_create_users.rb b/db/migrate/20120826005440_create_users.rb new file mode 100644 index 0000000..e1ec007 --- /dev/null +++ b/db/migrate/20120826005440_create_users.rb @@ -0,0 +1,11 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :provider + t.string :uid + + t.timestamps + end + end +end diff --git a/public/index.html b/public/index.html deleted file mode 100644 index a1d5099..0000000 --- a/public/index.html +++ /dev/null @@ -1,241 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>Ruby on Rails: Welcome aboard</title> - <style type="text/css" media="screen"> - body { - margin: 0; - margin-bottom: 25px; - padding: 0; - background-color: #f0f0f0; - font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana"; - font-size: 13px; - color: #333; - } - - h1 { - font-size: 28px; - color: #000; - } - - a {color: #03c} - a:hover { - background-color: #03c; - color: white; - text-decoration: none; - } - - - #page { - background-color: #f0f0f0; - width: 750px; - margin: 0; - margin-left: auto; - margin-right: auto; - } - - #content { - float: left; - background-color: white; - border: 3px solid #aaa; - border-top: none; - padding: 25px; - width: 500px; - } - - #sidebar { - float: right; - width: 175px; - } - - #footer { - clear: both; - } - - #header, #about, #getting-started { - padding-left: 75px; - padding-right: 30px; - } - - - #header { - background-image: url("assets/rails.png"); - background-repeat: no-repeat; - background-position: top left; - height: 64px; - } - #header h1, #header h2 {margin: 0} - #header h2 { - color: #888; - font-weight: normal; - font-size: 16px; - } - - - #about h3 { - margin: 0; - margin-bottom: 10px; - font-size: 14px; - } - - #about-content { - background-color: #ffd; - border: 1px solid #fc0; - margin-left: -55px; - margin-right: -10px; - } - #about-content table { - margin-top: 10px; - margin-bottom: 10px; - font-size: 11px; - border-collapse: collapse; - } - #about-content td { - padding: 10px; - padding-top: 3px; - padding-bottom: 3px; - } - #about-content td.name {color: #555} - #about-content td.value {color: #000} - - #about-content ul { - padding: 0; - list-style-type: none; - } - - #about-content.failure { - background-color: #fcc; - border: 1px solid #f00; - } - #about-content.failure p { - margin: 0; - padding: 10px; - } - - - #getting-started { - border-top: 1px solid #ccc; - margin-top: 25px; - padding-top: 15px; - } - #getting-started h1 { - margin: 0; - font-size: 20px; - } - #getting-started h2 { - margin: 0; - font-size: 14px; - font-weight: normal; - color: #333; - margin-bottom: 25px; - } - #getting-started ol { - margin-left: 0; - padding-left: 0; - } - #getting-started li { - font-size: 18px; - color: #888; - margin-bottom: 25px; - } - #getting-started li h2 { - margin: 0; - font-weight: normal; - font-size: 18px; - color: #333; - } - #getting-started li p { - color: #555; - font-size: 13px; - } - - - #sidebar ul { - margin-left: 0; - padding-left: 0; - } - #sidebar ul h3 { - margin-top: 25px; - font-size: 16px; - padding-bottom: 10px; - border-bottom: 1px solid #ccc; - } - #sidebar li { - list-style-type: none; - } - #sidebar ul.links li { - margin-bottom: 5px; - } - - .filename { - font-style: italic; - } - </style> - <script type="text/javascript"> - function about() { - info = document.getElementById('about-content'); - if (window.XMLHttpRequest) - { xhr = new XMLHttpRequest(); } - else - { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } - xhr.open("GET","rails/info/properties",false); - xhr.send(""); - info.innerHTML = xhr.responseText; - info.style.display = 'block' - } - </script> - </head> - <body> - <div id="page"> - <div id="sidebar"> - <ul id="sidebar-items"> - <li> - <h3>Browse the documentation</h3> - <ul class="links"> - <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li> - <li><a href="http://api.rubyonrails.org/">Rails API</a></li> - <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li> - <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li> - </ul> - </li> - </ul> - </div> - - <div id="content"> - <div id="header"> - <h1>Welcome aboard</h1> - <h2>You’re riding Ruby on Rails!</h2> - </div> - - <div id="about"> - <h3><a href="rails/info/properties" onclick="about(); return false">About your application’s environment</a></h3> - <div id="about-content" style="display: none"></div> - </div> - - <div id="getting-started"> - <h1>Getting started</h1> - <h2>Here’s how to get rolling:</h2> - - <ol> - <li> - <h2>Use <code>rails generate</code> to create your models and controllers</h2> - <p>To see all available options, run it without parameters.</p> - </li> - - <li> - <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2> - <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p> - </li> - - <li> - <h2>Create your database</h2> - <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p> - </li> - </ol> - </div> - </div> - - <div id="footer"> </div> - </div> - </body> -</html> |
