Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sample code for WCR2012 lightning talk
class ApplicationController < ActionController::Base
def current_user
User.find_by_id(session[:user_id])
end
def current_user=(user)
session[:user_id] = user.id
end
def logged_in?
!!self.current_user
end
def require_login
unless logged_in?
redirect_to login_url and return false
end
end
end
# app/controllers/concerns/authentication.rb
module Authentication
def current_user
User.find_by_id(session[:user_id])
end
def current_user=(user)
session[:user_id] = user.id
end
def logged_in?
!!self.current_user
end
# Any other methods you want, so long as they
# pertain to authentication
end
class ApplicationController < ActionController::Base
include Authentication
# Where do I look for the authentication stuff?
# In Authentication, of course!
end
def foo
# Does some stuff ...
if @user.status == :active
@user.status = :inactive
@user.save!
end
end
def bar
# Does some other stuff ...
if @user.status == :active
@user.status = :inactive
@user.save!
end
end
def baz
# Does yet other stuff ...
if @user.status == :active
@user.status = :inactive
@user.save!
end
end
def deactivate_user(user)
if user.status == :active
user.status = :inactive
user.save!
end
end
def foo
# Does some stuff ...
deactivate_user(@user)
end
def bar
# Does some other stuff ...
deactivate_user(@user)
end
def baz
# Does yet other stuff ...
deactivate_user(@user)
end
class User < ActiveRecord::Base
def adobe_profile
AdobeId::Profile.new(self.adobe_profile_id)
end
def connected_to_adobe_profile?
!self.adobe_profile_id.nil?
end
def connect_to_adobe_profile(profile_obj)
self.adobe_profile_id = profile_obj.id
self.email_unique = false
save
end
def disconnect_adobe_profile
self.adobe_profile_id = nil
self.email_unique = true
save
end
end
module UserAdobeProfile
def adobe_profile
AdobeId::Profile.new(self.adobe_profile_id)
end
def connected_to_adobe_profile?
!self.adobe_profile_id.nil?
end
# Anything else pertaining to users' Adobe profiles
end
class User < ActiveRecord::Base
include UserAdobeProfile
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.