facebook integration work
This commit is contained in:
parent
c8f84918d4
commit
6b520b0a2b
|
|
@ -10,8 +10,7 @@ class SessionsController < ApplicationController
|
|||
def create
|
||||
user = User.find_by_email(params[:session][:email])
|
||||
if user && user.authenticate(params[:session][:password])
|
||||
sign_in user
|
||||
redirect_back_or music_sessions_url
|
||||
complete_sign_in user
|
||||
else
|
||||
flash.now[:error] = 'Invalid email/password combination'
|
||||
render 'new'
|
||||
|
|
@ -20,7 +19,28 @@ class SessionsController < ApplicationController
|
|||
|
||||
def create_oauth
|
||||
auth_hash = request.env['omniauth.auth']
|
||||
render :text => auth_hash.inspect
|
||||
authorization = UserAuthorization.find_by_provider_and_uid(auth_hash["provider"], auth_hash["uid"])
|
||||
if authorization
|
||||
# Sign in for a user who has already registered.
|
||||
complete_sign_in authorization.user
|
||||
else
|
||||
# Sign up for a completely new user.
|
||||
# First/last name: auth_hash["info"]["first_name"] and auth_hash["info"]["last_name"]
|
||||
# token: auth_hash["credentials"]["token"] -- "expires_at"
|
||||
#
|
||||
# For debugging - to see what all is there:
|
||||
# render :text => auth_hash.to_yaml
|
||||
user = User.new :name => auth_hash["info"]["name"], :email => auth_hash["info"]["email"]
|
||||
user.authorizations.build :provider => auth_hash["provider"], :uid => auth_hash["uid"],
|
||||
:token => auth_hash["credentials"]["token"], :token_expiration => auth_hash["credentials"]["expires_at"]
|
||||
user.save
|
||||
complete_sign_in user
|
||||
end
|
||||
end
|
||||
|
||||
def complete_sign_in(user)
|
||||
sign_in user
|
||||
redirect_back_or music_sessions_url
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ class UsersController < ApplicationController
|
|||
def create
|
||||
@user = User.new(params[:jam_ruby_user])
|
||||
if @user.save
|
||||
sign_in @user
|
||||
flash[:success] = "Welcome to Jamkazam!"
|
||||
redirect_to @user
|
||||
sign_in @user, :new => true
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
module SessionsHelper
|
||||
|
||||
def sign_in(user)
|
||||
if (:new was set to true)
|
||||
flash[:success] = "Welcome to Jamkazam!"
|
||||
redirect_to user
|
||||
end
|
||||
cookies.permanent[:remember_token] = user.remember_token
|
||||
self.current_user = user
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
<% provide(:title, 'Sign up') %>
|
||||
<h1>Sign up</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<a href="/auth/facebook"><img src="http://ventnation.com/images/fb-signup-button.png?1343414918"></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<%= form_for(@user) do |f| %>
|
||||
|
|
@ -20,4 +26,4 @@
|
|||
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue