Skip to content

Commit

Permalink
References #28 - Login and logout now works, with login buttons from h…
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflunt committed Jun 23, 2012
1 parent 51a21a4 commit 1d51a67
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 27 deletions.
Binary file added app/assets/images/login_buttons/facebook_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/login_buttons/github_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/login_buttons/twitter_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion app/assets/javascripts/cortex_core.js.coffee.erb
Expand Up @@ -17,6 +17,9 @@ $ ->
window.shareLinkControl = $('#share-link-control')
window.shareLinkDiv = $('#share-link')

window.starControl = $('#star-control')
window.starDiv = $('#star-options')

window.thoughtHistoriesLinks = $(".thought-history-link")
window.thoughtHistoryBoxes = $(".thought-histories-box")

Expand Down Expand Up @@ -58,7 +61,15 @@ $ ->
$.get(document.URL+".js?since="+getRenderTimestamp()+"&next_refresh="+getCurrThoughtWallRefreshDelay()).error( ->
delayAction(ajaxRefreshPage, requestFailRetryDelay)
)

window.makeSureLocalStorageHasAtLeastDefaultValues = () ->
if !localStorage["recentThoughtWallCodes"]
localStorage["recentThoughtWallCodes"] = ""
if !localStorage["preferredTheme"]
localStorage["preferredTheme"] = "theme-canvas"

$(document).ready ->
addThoughtWallCodeToRecentList($('#thought-wall-code').html(), $('title').html())
if (supportsHtml5Storage())
makeSureLocalStorageHasAtLeastDefaultValues()
addThoughtWallCodeToRecentList($('#thought-wall-code').html(), $('title').html())
delayAction(ajaxRefreshPage, minThoughtWallRefreshDelay)
8 changes: 8 additions & 0 deletions app/assets/javascripts/login_options.js.coffee.erb
@@ -0,0 +1,8 @@
$ ->
window.toggleVisibilityOfLoginOptionsDiv = ->
if (starOptionsDiv.css('opacity') is "1")
starOptionsDiv.animate({opacity: 0.0}, 100, ->
starOptionsDiv.hide())
else
starOptionsDiv.show()
starOptionsDiv.animate({opacity: 1.0}, 100)
6 changes: 0 additions & 6 deletions app/assets/javascripts/thoughts.js.coffee.erb
Expand Up @@ -62,12 +62,6 @@ $ ->
return -1
else
return Math.abs(clientIndex - index)

makeSureLocalStorageHasAtLeastDefaultValues = () ->
if !localStorage["recentThoughtWallCodes"]
localStorage["recentThoughtWallCodes"] = ""
if !localStorage["preferredTheme"]
localStorage["preferredTheme"] = "theme-canvas"

$(document).ready ->
if (supportsHtml5Storage())
Expand Down
10 changes: 9 additions & 1 deletion app/assets/stylesheets/controls.sass
Expand Up @@ -55,6 +55,14 @@
margin-right: 5px
margin-left: 5px

#star-options
@extend .control-middle
@extend .control-menu
opacity: 1.0
color: white
border-radius: 0px 0px 7px 7px
border-width: 0px 1px 1px 1px
background-color: $dark-theme-medium-grey
#recent-thought-walls
@extend .control-middle
@extend .control-menu
Expand Down Expand Up @@ -87,7 +95,7 @@
@extend .theme-preview
width: 15px
height: 15px
float: left
float: left
#share-link
@extend .control-middle
@extend .control-menu
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -8,4 +8,13 @@ class ApplicationController < ActionController::Base
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end

def redirect_to_page_i_was_on_or_root
if cookies[:page_i_was_on]
redirect_to "/#{cookies[:page_i_was_on]}"
cookies.delete :page_i_was_on
else
redirect_to root_url
end
end
end
14 changes: 4 additions & 10 deletions app/controllers/sessions_controller.rb
Expand Up @@ -7,22 +7,16 @@ def create
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id


if cookies[:page_i_was_on].nil?
redirect_to root_url
else
redirect_to cookies[:page_i_was_on]
cookies.delete :page_i_was_on
end
redirect_to_page_i_was_on_or_root
end

def destroy
session[:user_id] = nil
flash[:notice] = "Signed out."
redirect_to root_url, :notice => "Signed out."
Rails.logger.info "Redirecting..."
redirect_to_page_i_was_on_or_root
end

def failure
redirect_to root_url
redirect_to_page_i_was_on_or_root
end
end
3 changes: 2 additions & 1 deletion app/controllers/thought_walls_controller.rb
Expand Up @@ -13,7 +13,6 @@ def export

def show
@render_timestamp = Time.now.utc.to_i
session[:page_i_was_on] = request.fullpath

if params[:since]
@last_render_at = Time.at(params[:since].to_i).utc
Expand All @@ -31,6 +30,8 @@ def show
@next_refresh = get_next_refresh(0, true)
end

cookies[:page_i_was_on] = @thought_wall.code

respond_to do |format|
format.html
format.js {render layout: false}
Expand Down
17 changes: 11 additions & 6 deletions app/views/controls/_control_bar.haml
@@ -1,19 +1,24 @@
#control-bar
#controls-left
-if current_user
=link_to "\u2605", "javascript:;", class: "control-left"
-else
=link_to 'login', '/auth/google_oauth2', class: "control-left"
=link_to "\u2605", "javascript:;", id: 'star-control', class: "control-left"
=link_to "recent", "javascript:;", id: "recent-thought-walls-link", class: "control-middle"
=link_to "new", "/", class: "control-right"


#controls-right
%img#theme-current-preview{src: ''}
=link_to "\u25be", "javascript:;", class: "control-right", id: "theme-selector-control"
=link_to ".csv", export_thought_wall_path(@thought_wall.code, format: "csv"), class: "control-left"
=link_to "share", "javascript:;", id: "share-link-control", class: "control-right"

#star-options
-if current_user
=link_to "logout", '/signout'
-else
login with
%table
%tr
%td
=link_to image_tag("login_buttons/google_oauth2_32.png", title: 'Google', alt: 'Google'), '/auth/google_oauth2'

#recent-thought-walls
#theme-selector
=render partial: "controls/theme_selector"
Expand Down
6 changes: 4 additions & 2 deletions config/routes.rb
@@ -1,13 +1,15 @@
Cortex::Application.routes.draw do
root :to => 'thought_walls#create'

match '/auth/:provider/callback', to: 'sessions#create'
match "/auth/failure" => "sessions#failure"
match "/signout" => "sessions#destroy", :as => :signout

resources :thought_walls, :only => [:export, :create, :update, :show] do
get 'export', :on => :member
end

resources :thoughts, :only => [:show, :create, :edit, :update]

match "/about" => "thought_walls#index"
match "/:id" => "thought_walls#show"
match '/auth/:provider/callback', to: 'sessions#create'
end

0 comments on commit 1d51a67

Please sign in to comment.