Merge branch 'master' of bitbucket.org:jamkazam/jam-web
This commit is contained in:
commit
8b65f6063f
4
Gemfile
4
Gemfile
|
|
@ -25,6 +25,10 @@ gem 'eventmachine'
|
|||
gem 'amqp'
|
||||
gem 'logging-rails', :require => 'logging/rails'
|
||||
gem 'tire'
|
||||
gem 'rb-readline'
|
||||
gem 'omniauth'
|
||||
gem 'omniauth-facebook'
|
||||
gem 'fb_graph'
|
||||
gem 'sendgrid'
|
||||
gem 'recaptcha'
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ class ApiUsersController < ApiController
|
|||
# if someone wants to use it, please add in captcha or some other bot-protector
|
||||
def create
|
||||
# sends email to email account for confirmation
|
||||
@user = UserManager.new.signup(params[:name],
|
||||
@user = UserManager.new.signup(params[:first_name],
|
||||
params[:last_name],
|
||||
params[:email],
|
||||
params[:password],
|
||||
params[:password_confirmation],
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ class SessionsController < ApplicationController
|
|||
def new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
user = User.authenticate(params[:session][:email], params[:session][:password])
|
||||
|
||||
|
|
@ -11,13 +12,62 @@ class SessionsController < ApplicationController
|
|||
flash.now[:error] = 'Invalid email/password combination'
|
||||
render 'new'
|
||||
else
|
||||
sign_in user
|
||||
redirect_back_or music_sessions_url
|
||||
complete_sign_in user
|
||||
end
|
||||
end
|
||||
|
||||
# OAuth docs
|
||||
# http://net.tutsplus.com/tutorials/ruby/how-to-use-omniauth-to-authenticate-your-users/
|
||||
def create_oauth
|
||||
auth_hash = request.env['omniauth.auth']
|
||||
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
|
||||
#FbGraph.debug!
|
||||
#app = FbGraph::Application.new '468555793186398', :secret => '546a5b253972f3e2e8b36d9a3dd5a06e'
|
||||
token = auth_hash[:credentials][:token]
|
||||
|
||||
# FIXME:
|
||||
# This should probably be in a transaction somehow, meaning the user
|
||||
# create and the authorization create. Concern is UserManager.new.signup sends
|
||||
# an email and whatnot.
|
||||
user = UserManager.new.signup(auth_hash[:info][:first_name],
|
||||
auth_hash[:info][:last_name],
|
||||
auth_hash[:info][:email],
|
||||
nil,
|
||||
nil,
|
||||
auth_hash[:info][:location],
|
||||
nil, # state
|
||||
nil, # @country
|
||||
nil,
|
||||
nil)
|
||||
auth = user.user_authorizations.build :provider => auth_hash[:provider], :uid => auth_hash[:uid],
|
||||
:token => auth_hash[:credentials][:token], :token_expiration => Time.at(auth_hash[:credentials][:expires_at])
|
||||
user.save
|
||||
auth.save
|
||||
complete_sign_in user
|
||||
end
|
||||
end
|
||||
|
||||
def complete_sign_in(user)
|
||||
sign_in user
|
||||
redirect_back_or music_sessions_url
|
||||
end
|
||||
|
||||
def destroy
|
||||
sign_out
|
||||
redirect_to root_url
|
||||
end
|
||||
end
|
||||
|
||||
def failure
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
|
||||
|
||||
@user = User.new
|
||||
|
||||
# check recaptcha; if any errors seen, contribute it to the model
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ module UsersHelper
|
|||
hclass = options[:hclass]
|
||||
gravatar =
|
||||
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
|
||||
image_tag(gravatar_url, alt: user.name, class: "#{hclass}")
|
||||
image_tag(gravatar_url, alt: "#{user.first_name} #{user.last_name}", class: "#{hclass}")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ node :last_name do |follower|
|
|||
follower.user.last_name
|
||||
end
|
||||
|
||||
node :name do |follower|
|
||||
follower.user.name
|
||||
end
|
||||
|
||||
node :city do |follower|
|
||||
follower.user.city
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ attributes :id, :name, :city, :state, :country, :website, :biography, :photo_url
|
|||
|
||||
unless @band.users.nil? || @band.users.size == 0
|
||||
child :users => :musicians do
|
||||
attributes :id, :first_name, :last_name, :name, :photo_url
|
||||
attributes :id, :first_name, :last_name, :photo_url
|
||||
|
||||
# TODO: figure out how to omit empty arrays
|
||||
node :instruments do |user|
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ node :last_name do |follower|
|
|||
follower.user.last_name
|
||||
end
|
||||
|
||||
node :name do |follower|
|
||||
follower.user.name
|
||||
end
|
||||
|
||||
node :city do |follower|
|
||||
follower.user.city
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ node :last_name do |following|
|
|||
following.user.last_name
|
||||
end
|
||||
|
||||
node :name do |follower|
|
||||
follower.user.name
|
||||
end
|
||||
|
||||
node :city do |following|
|
||||
following.user.city
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
object @user.friends
|
||||
|
||||
attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online
|
||||
attributes :id, :first_name, :last_name, :city, :state, :country, :email, :online
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
collection @users
|
||||
|
||||
# do not retrieve all child collections when showing a list of users
|
||||
attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online, :musician, :photo_url
|
||||
attributes :id, :first_name, :last_name, :city, :state, :country, :email, :online, :musician, :photo_url
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
object @user
|
||||
|
||||
attributes :id, :first_name, :last_name, :name, :city, :state, :country, :online, :photo_url, :gender, :birth_date, :internet_service_provider, :friend_count, :follower_count, :following_count
|
||||
attributes :id, :first_name, :last_name, :city, :state, :country, :online, :photo_url, :gender, :birth_date, :internet_service_provider, :friend_count, :follower_count, :following_count
|
||||
|
||||
unless @user.friends.nil? || @user.friends.size == 0
|
||||
child :friends => :friends do
|
||||
attributes :id, :first_name, :last_name, :name, :online
|
||||
attributes :id, :first_name, :last_name, :online
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<li>
|
||||
<a>
|
||||
<img src="{image}"/>
|
||||
<span class="text">{name}</span>
|
||||
<span class="text">{first_name} {last_name}</span>
|
||||
<span class="subtext">{subtext}</span>
|
||||
</a>
|
||||
</li>
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
<div class="userinfo">
|
||||
<%= gravatar_for current_user, size: 52, hclass: "avatar medium" %>
|
||||
<div class="username">
|
||||
<h2><%= current_user.name %></h2>
|
||||
<h2><%= "#{current_user.first_name} #{current_user.last_name}" %></h2>
|
||||
<%= image_tag "down_arrow.png", :class=> "profile-toggle" %>
|
||||
<ul>
|
||||
<li><a layout-link="account">Profile</a></li>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
<% provide(:title, "Sign in") %>
|
||||
<h1>Sign in</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<a href="/auth/facebook"><img src="/fb-signup-button.png"></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<%= form_for(:session, url: sessions_path) do |f| %>
|
||||
|
|
@ -16,4 +22,4 @@
|
|||
|
||||
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,21 @@
|
|||
<% provide(:title, 'Sign up') %>
|
||||
<h1>Sign up</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<a href="/auth/facebook"><img src="/fb-signup-button.png"></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<%= form_for(@user) do |f| %>
|
||||
<%= render 'shared/error_messages', object: f.object %>
|
||||
<%= f.label :name %>
|
||||
<%= f.text_field :name %>
|
||||
<%= f.label :first_name %>
|
||||
<%= f.text_field :first_name %>
|
||||
|
||||
<%= f.label :last_name %>
|
||||
<%= f.text_field :last_name %>
|
||||
|
||||
<%= f.label :email %>
|
||||
<%= f.text_field :email %>
|
||||
|
|
@ -31,4 +40,4 @@
|
|||
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
Rails.application.config.middleware.use OmniAuth::Builder do
|
||||
provider :facebook, '468555793186398', '546a5b253972f3e2e8b36d9a3dd5a06e', {:scope => 'email,user_location'}
|
||||
end
|
||||
|
|
@ -17,6 +17,9 @@ SampleApp::Application.routes.draw do
|
|||
match '/email_sent', to: 'users#email_sent'
|
||||
match '/signin', to: 'sessions#new'
|
||||
match '/signout', to: 'sessions#destroy', via: :delete
|
||||
# oauth
|
||||
match '/auth/:provider/callback', :to => 'sessions#create_oauth'
|
||||
match '/auth/failure', :to => 'sessions#failure'
|
||||
|
||||
match '/help', to: 'static_pages#help'
|
||||
match '/about', to: 'static_pages#about'
|
||||
|
|
|
|||
|
|
@ -8,19 +8,20 @@ class UserManager < BaseManager
|
|||
@log = Logging.logger[self]
|
||||
end
|
||||
|
||||
def signup(name, email, password, password_confirmation,
|
||||
def signup(first_name, last_name, email, password, password_confirmation,
|
||||
city, state, country, instruments, signup_confirm_url)
|
||||
|
||||
@user = User.new
|
||||
|
||||
# TODO: figure out why can't user verify_recaptcha here
|
||||
# ALSO: make sure we dont do the recaptcha stuff if used facebook.
|
||||
|
||||
# check recaptcha; if any errors seen, contribute it to the model
|
||||
#unless verify_recaptcha(:model => @user, :message => "recaptcha")
|
||||
# return @user # @user.errors.any? is true now
|
||||
#else
|
||||
# sends email to email account for confirmation
|
||||
@user = User.signup(name, email, password, password_confirmation,
|
||||
@user = User.signup(first_name, last_name, email, password, password_confirmation,
|
||||
city, state, country, instruments, signup_confirm_url)
|
||||
|
||||
return @user
|
||||
|
|
@ -37,4 +38,4 @@ class UserManager < BaseManager
|
|||
return @user
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ describe UserManager do
|
|||
|
||||
describe "signup" do
|
||||
it "signup successfully" do
|
||||
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
@user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
|
||||
@user.errors.any?.should be_false
|
||||
@user.name.should == "bob"
|
||||
@user.first_name.should == "bob"
|
||||
@user.last_name.should == "smith"
|
||||
@user.email.should == "bob@jamkazam.com"
|
||||
@user.email_confirmed.should be_false
|
||||
@user.city.should == "Austin"
|
||||
|
|
@ -27,7 +28,7 @@ describe UserManager do
|
|||
end
|
||||
|
||||
it "signup successfully with instruments" do
|
||||
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA",
|
||||
@user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA",
|
||||
[{ :instrument_id => "electric guitar", :proficiency_level => 3, :priority => 0}], "http://localhost:3000/confirm" )
|
||||
|
||||
@user.errors.any?.should be_false
|
||||
|
|
@ -38,28 +39,28 @@ describe UserManager do
|
|||
end
|
||||
|
||||
it "duplicate signup failure" do
|
||||
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
@user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
UserMailer.deliveries.length.should == 1
|
||||
@user.errors.any?.should be_false
|
||||
|
||||
# exactly the same parameters; should dup on email, and send no email
|
||||
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
@user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
UserMailer.deliveries.length.should == 1
|
||||
@user.errors.any?.should be_true
|
||||
@user.errors[:email][0].should == "has already been taken"
|
||||
|
||||
# change email so that name appears dupped
|
||||
@user = @user_manager.signup("bob", "bobbie@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
@user = @user_manager.signup("bob", "smith", "bobbie@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
UserMailer.deliveries.length.should == 1
|
||||
@user.errors.any?.should be_true
|
||||
@user.errors[:name][0].should == "has already been taken"
|
||||
end
|
||||
|
||||
it "fail on no username" do
|
||||
@user = @user_manager.signup("", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
@user = @user_manager.signup("", "", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
UserMailer.deliveries.length.should == 0
|
||||
@user.errors.any?.should be_true
|
||||
@user.errors[:name][0].should == "can't be blank"
|
||||
@user.errors[:first_name][0].should == "can't be blank"
|
||||
end
|
||||
|
||||
it "fail on no username" do
|
||||
|
|
@ -72,7 +73,7 @@ describe UserManager do
|
|||
|
||||
describe "signup_confirm" do
|
||||
it "fail on no username" do
|
||||
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
@user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
||||
@user = @user_manager.signup_confirm(@user.signup_token)
|
||||
@user.email_confirmed.should be_true
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue