Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ASCTech/mooculus
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Butsko committed Dec 27, 2012
2 parents 25adafb + 6b5b30f commit 3b00c03
Show file tree
Hide file tree
Showing 64 changed files with 6,340 additions and 336 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ gem 'less-rails'
# use Devise for login
gem 'devise'
gem 'omniauth'
gem 'oauth2'
gem 'omniauth-google-oauth2'
gem 'omniauth-oauth'

group :development do
gem 'capistrano'
Expand Down
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

body {
padding-top: 80px;
font-family: 'Open Sans', sans-serif;
}

#get-hint-button-container {
text-align: center;
}

38 changes: 19 additions & 19 deletions app/assets/stylesheets/khan-site.css

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,75 @@
class HomeController < ApplicationController
def index
end

def about
end

def people
@people = Array.new

@people << {
:name => 'Bart Snapp',
:photo => 'bart-snapp',
:description => 'Bart is at OSU.',
:link => 'http://www.math.osu.edu/~snapp/',
:email => '[email protected]'
}

@people << {
:name => 'Jim Fowler',
:photo => 'jim-fowler',
:description => 'Jim is at OSU.',
:link => 'http://www.math.osu.edu/~fowler/',
:email => '[email protected]'
}

@people << {
:name => 'Steven Gubkin',
:photo => 'steve-gubkin',
:description => 'Steve is at OSU.',
:email => '[email protected]',
:link => 'http://www.math.osu.edu/people/gubkin.1/view',
}

@people << {
:name => 'Ryan Kowalick',
:photo => 'ryan-kowalick',
:description => 'Ryan Kowalick',
:email => '[email protected]',
:link => 'http://www.math.osu.edu/people/kowalick.1'
}

@people << {
:name => 'Roman Holowinsky',
:photo => 'roman-holowinsky',
:description => 'Roman Holowinsky advises.',
:email => '[email protected]',
:link => 'http://www.math.osu.edu/~romanh/'
}

@people << {
:name => 'Sean Corey',
:photo => 'sean-corey',
:description => 'Sean Corey',
:email => '[email protected]',
}

@people << {
:name => 'Isaac Smith',
# :photo => 'isaac-smith',
:description => 'Isaac is an undergraduate at Ohio State; he is a teaching assistant in this course.',
:email => '[email protected]',
}

@people << {
:name => 'Sean Collins',
# :photo => 'sean-collins',
:description => 'Sean is an undergraduate at Ohio State; he is a teaching assistant in this course.',
:email => '[email protected]',
}

@people.shuffle!

end
end
30 changes: 19 additions & 11 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)

if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def coursera
@user = User.find_for_coursera(request.env["omniauth.auth"], current_user)

if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Coursera"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.coursera_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end

# This is necessary since Rails 3.0.4
# See https://github.com/intridea/omniauth/issues/185
# and http://www.arailsdemo.com/posts/44
protected
def handle_unverified_request
true
end
end
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
module ApplicationHelper
def html_logo
return '<span style="font-family: \'Open Sans\', sans-serif;"><span style="font-weight: 800;">mooc</span><span style="font-weight: 300;">ulus</span></span>'
end
end
1 change: 1 addition & 0 deletions app/models/exercise.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Exercise < ActiveRecord::Base
attr_accessible :title, :description, :page, :problem_number
has_many :scores, :dependent => :destroy
has_many :problems, :dependent => :destroy
end
4 changes: 4 additions & 0 deletions app/models/problem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Problem < ActiveRecord::Base
belongs_to :exercise
attr_accessible :name
end
2 changes: 1 addition & 1 deletion app/models/score.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Score < ActiveRecord::Base
attr_accessible :time_taken, :attempt_number, :complete, :count_hints, :seed,
:attempt_content
belongs_to :exercise
belongs_to :problem
belongs_to :user
end
27 changes: 15 additions & 12 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,36 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
devise :omniauthable

# Coursera doesn't provide us with an email address
def email_required?
false
end

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :email, :password, :coursera_id, :password_confirmation, :remember_me
attr_accessible :name

has_many :authentications, :dependent => :delete_all
has_many :scores, :dependent => :destroy

def apply_omniauth(auth)
puts auth
self.email = auth['info']['email']
self.name = auth['info']['name']
# should use this line probably in the future
#self.email = auth['extra']['raw_info']['email']
puts "Apply omniauth!"
self.email ||= auth['info']['email']
self.name ||= auth['info']['name']

# Again, saving token is optional. If you haven't created the column in authentications table, this will fail
authentications.build(:provider => auth['provider'], :uid => auth['uid'], :token => auth['credentials']['token'])
end

def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
def self.find_for_coursera(access_token, signed_in_resource=nil)
data = access_token.info
user = User.where(:email => data["email"]).first
user = User.where(:coursera_id => data["id"]).first

unless user
user = User.create(:name => data["name"],
:email => data["email"],
:password => Devise.friendly_token[0,20]
)
user = User.create!(:coursera_id => data["id"],
:name => data["name"],
:password => Devise.friendly_token[0,20]
)
end
user
end
Expand Down
9 changes: 9 additions & 0 deletions app/views/home/_person.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<img style="float: left; margin-right: 16pt; margin-left: 16pt; margin-bottom: 16pt;" src="/photos/<%= @person[:photo] %>-150.jpg"/>
<h2><%= @person[:name] %></h2>
<% unless @person[:email].nil? %>
<span class="email"><a href="mailto:<%= @person[:email] %>"><%= @person[:email] %></a></span>
<% end %>
<% unless @person[:link].nil? %>
<span class="url"><a href="<%= @person[:link] %>" rel="external"><%= @person[:link] %></a></span>
<% end %>
<p><%= @person[:description] %></p>
6 changes: 6 additions & 0 deletions app/views/home/about.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="row-fluid">
<div class="span12"></div>
<h1>About <%=raw html_logo %></h1>
<p><%=raw html_logo %> is an experiment in mathematics.</p>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="hero-unit">
<h1>Help with math?</h1>
<p>Need help with a math course at Ohio State? Looking for lecture videos? Looking for practice exams? This is the place. <%= @course %></p>
<p><%= link_to 'Login', user_omniauth_authorize_path(:google_oauth2),
<p><%= link_to 'Login', user_omniauth_authorize_path(:coursera),
{ :class => "btn btn-primary btn-large" }%></p>
</div>
</div>
Expand Down
29 changes: 29 additions & 0 deletions app/views/home/people.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="row-fluid">
<div class="span12">
<h1>People</h1>
<p><%=raw html_logo %> was produced by a bunch of people. Here are some of them.</p>
</div>
</div>
<% people_per_row = 2 %>

<% for i in 0..(@people.length / people_per_row) do %>
<div class="row-fluid">
<% for j in 0...people_per_row do %>
<% @person = @people[people_per_row*i + j] %>
<div class="span<%= 12/people_per_row %>">
<% unless @person.nil? %>
<%= render :partial => "person" %>
<% end %>
</div>
<% end %>
</div>
<% end %>

<div class="row-fluid">
<div class="span12">
<h1>Acknowledgments</h1>
<p><%=raw html_logo %> could not have been produced without the generous support of the <a href="http://www.math.osu.edu/">mathematics department</a> at <a href="http://www.osu.edu/">The Ohio State University</a>.</p>

<p>Uses <a href="http://twitter.github.com/bootstrap/" rel="external">Twitter&rsquo;s bootstrap</a> and <a href="https://github.com/Khan/khan-exercises/" rel="external">Khan Academy&rsquo;s exercise framework</a>. Built on <a href="http://rubyonrails.org/">Rails</a>.</p>
</div>
</div>
15 changes: 7 additions & 8 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<%= javascript_include_tag "application" %>
<%= favicon_link_tag '/favicon.ico' %>
<%= csrf_meta_tags %>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,600,300,800,700' rel='stylesheet' type='text/css'>
</head>
<body>

<% if user_signed_in? %>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
Expand All @@ -18,31 +18,30 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#"><span style="font-weight: bold">MOOC</span>ulus</a>
<a class="brand" href="#"><%=raw html_logo %></a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="/">Lectures</a></li>
<li class="active"><%= link_to "Problems", :controller => "exercises", :action => "index" %></li>
<li class="active"><a href="/">lectures</a></li>
<li class="active"><%= link_to "problems", :controller => "exercises", :action => "index" %></li>
<% if user_signed_in? %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<%= current_user.name %>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Log out", destroy_user_session_path, :method => :delete %></li>
<li><%= link_to "log out", destroy_user_session_path, :method => :delete %></li>
</ul>
</li>
<% else %>
<li class=""><%= link_to "Login", user_omniauth_authorize_path(:google_oauth2) %></a>
<li class=""><%= link_to "login", user_omniauth_authorize_path(:coursera) %></a>

<% end %>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<% end %>

<div class="container-fluid">
<%= yield %>
Expand All @@ -51,7 +50,7 @@

<footer>
<div class="container">
<p>&copy; <%= Date.today.strftime( '%Y' ) %>, <a href="http://www.math.osu.edu/~fowler/" rel="external">Jim Fowler</a>, <a href="http://www.math.osu.edu/people/gubkin.1/view" rel="external">Steve Gubkin</a>, <a href="http://www.math.osu.edu/people/kowalick.1">Ryan Kowalick</a>, <a href="http://www.math.osu.edu/~snapp.14/">Bart Snapp</a>. Uses <a href="http://twitter.github.com/bootstrap/" rel="external">Twitter&rsquo;s bootstrap</a> and <a href="https://github.com/Khan/khan-exercises/" rel="external">Khan Academy&rsquo;s exercise framework</a>. Built on <a href="http://rubyonrails.org/">Rails</a>.</p>
<p>&copy; <%= Date.today.strftime( '%Y' ) %>, <a href="/people"><%=raw html_logo %> team</a>.
</div>
</footer>
</div> <!-- /container -->
Expand Down
5 changes: 3 additions & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@
# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
require "omniauth-google-oauth2"
config.omniauth :google_oauth2, '274300643461.apps.googleusercontent.com', 'qb9d9IhDExhM6Hu3eV7wZsUk', { :access_type => "offline", :approval_prompt => "" }

require "omniauth-coursera"
config.omniauth :coursera, 'db127b155312155233e6e5da331adfed38f96e4f', 'f4e61cf7794c5c703b8aa714d6cc4acca42c76ee'

# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
# provider :developer unless Rails.env.production?
end
14 changes: 8 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Assessor::Application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => 'home#index'

get "home/index"
get "people" => "home#people"
get "about" => "home#about"

get "score/index"

Expand Down Expand Up @@ -59,12 +63,10 @@
# resources :products
# end

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => 'home#index'

# After user authenticates with provider, user needs to go to omniauth call
match '/auth/:provider/callback' => 'authentications#create'
# match '/auth/:provider/callback' => 'authentications#create'

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

match '/api/v1/user/exercises/:exercise/problems/:problem/attempt' => 'score#attempt',
:constraints => { :problem => /\d+/ }, :via => :post
Expand Down
Loading

0 comments on commit 3b00c03

Please sign in to comment.