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
class SessionsController < ApplicationController | |
def create | |
@user = User.find_or_create_from_auth_hash(auth_hash) | |
self.current_user = @user | |
redirect_to '/' | |
end | |
protected | |
def auth_hash |
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
def create | |
omniauth = request.env["omniauth.auth"] | |
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid']) | |
if authentication | |
flash[:notice] = "Signed in successfully." | |
sign_in_and_redirect(:user, authentication.user) | |
elsif current_user | |
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid']) | |
flash[:notice] = "Authentication successful." | |
redirect_to authentications_url |
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
def create | |
if signing_in | |
if service_1 | |
elsif service_2 | |
elsif .. | |
end | |
elsif associating_an_account | |
if service_1 | |
elsif service_2 | |
elsif .. |
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
def create | |
user = find_user || create_user | |
associate_account_if_necessary | |
login(user) | |
redirect_to_appropriate_location | |
end |
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
def create | |
runner = StrategyRunner.new | |
begin | |
user = runner.run(:Authentication, request) || runner.run(:UserCreation, request) | |
auto_login(user) | |
runner.run(:ExternalServiceAssociation, request, user) if user | |
rescue ExternalServiceAssociationStrategyFinderError => e | |
#Swallow this. Sometimes there is no external service to associate with | |
rescue PasswordAuthenticationError => e | |
flash[:login_alert] = 'bad_username' |
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
class StrategyRunner | |
def run(strategy_name, *params) | |
finder_klass = Kernel.const_get(strategy_name.to_s + "StrategyFinder") | |
finder = finder_klass.new(*params) | |
strategy_klass = finder.strategy | |
result = if strategy_klass.nil? | |
nil | |
else | |
strategy = strategy_klass.new() | |
strategy.run(*finder.params) |
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
class AuthenticationStrategyFinder | |
def initialize(request) | |
@request = request | |
end | |
def strategy | |
@authentication_class ||= | |
if @request.session[:user_id].present? | |
SessionAuthenticationStrategy | |
elsif @request.params[:user_session].present? |
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
class PasswordAuthenticationStrategy < AuthenticationStrategy | |
def run(username, password) | |
user = DbUser.find_by_username(username) | |
return user if user.present? && password.xfire_bcrypt == user.password | |
#If the user tried to auth via password and failed raise an exception | |
raise PasswordAuthenticationError.new("Incorrect Username or Password") | |
end | |
end |
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
<div class="media"> | |
<div id="mediaspace_wrapper" style="position: relative; width: 500px; height: 298px;"><object type="application/x-shockwave-flash" data="/jwplayer/jwplayer.flash.swf" width="100%" height="100%" bgcolor="#000000" id="mediaspace" name="mediaspace" tabindex="0"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="seamlesstabbing" value="true"><param name="wmode" value="opaque"></object><div id="mediaspace_jwpsrv" style="position: absolute; top: 0px; z-index: 10;"></div></div> | |
<script type="text/javascript"> | |
jwplayer.key="L9eJslnS4SIMCy1u1VeSZLNSyUJNi3shW1f35A==" | |
jwplayer('mediaspace').setup({ | |
autostart: true, | |
file: 'http://video.xfire.com/5ede1f.mp4', |
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
<div id='mediaspace'></div> | |
<script type='text/javascript'> | |
jwplayer.key="L9eJslnS4SIMCy1u1VeSZLNSyUJNi3shW1f35A==" | |
jwplayer('mediaspace').setup({ | |
autostart: true, | |
file: '<%= url %>', | |
width: 500, | |
height: 298, | |
primary: 'flash', |