I have two user models one is
1. User.rb (this is my own authentication system which handles users that just sign up within my site.
- Authenticate.rb (this is the OmniAuth authentication for users that want to signup through facebook.
Im having a hard time handling both models…..for example here is the code for my navigation
- if fb_signed_in?
.nav.pull-right.padding-top
%li
- if fb_signed_in?
%li#fat-menu.dropdown
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#"}
%span
Signed in as
= fb_current_user.email
%ul.dropdown-menu
%li= link_to "Profile", "#"
%li.divider
%li= link_to "Sign out", leave_path, method: "get"
- else
.nav.pull-right
%span.light_color Already a Member?
= link_to "Sign in", signin_path, class: 'light_color'
%span.light_color or
= link_to "Sign up", signup_path, class: 'light_color'
- else
.nav.pull-right.padding-top
%li
- if signed_in?
%li#fat-menu.dropdown
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#"}
%span
Signed in as
= current_user.email
%ul.dropdown-menu
%li= link_to "Profile", "#"
%li.divider
%li= link_to "Sign out", signout_path, method: "get"
- else
.nav.pull-right
%span.light_color Already a Member?
= link_to "Sign in", signin_path, class: 'light_color'
%span.light_color or
= link_to "Sign up", signup_path, class: 'light_color'
So i have defined a fb_signed_in? adn a signed_in? which basically does the same thing though..also with current_user and fb_current_user but heres the code for both
current_user
def current_user
@current_user = @current_user ||
User.find_by_remember_token(cookies[:remember_token])
end
and this is for fb_current_user
def fb_current_user
@fb_current_user ||= Authenticate.find(session[:user_id]) if session[:user_id]
end
so they do do different things….but is there a way to make those two one…since it will be a lot cleaner and im trying to create a comment system that will print users name and gravatar image and im getting confused on how to write the code for that since it uses gravatar_for @user and i would also have to do gravatar_for @authenticate for fb users.
Im basically using Hartl’s authentication and trying to integrate Omniauth with it
Please let me know if the question is confusing or unclear and i will try to explain better
Thank You
How about:
Although this may cause problems in other places since you don’t know what a
current_useris without testing its type.In my projects I have just one
Usermodel which has manyAuthorizations, where I put the omniauth-related stuff (socurrent_useris always aUser).