Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
finishing apis for signing-up
  • Loading branch information
Eladio Ruiz committed Dec 22, 2010
1 parent 5edf8ed commit 5ce6142
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
15 changes: 12 additions & 3 deletions app/controllers/api_controller.rb
Expand Up @@ -162,15 +162,24 @@ def uploadmatch
end

def newuser
@token = params[:token]
@user_name = params[:user_name]
@user_email = params[:user_email]
@user_login = params[:user_login]
@user_password = params[:user_name]
@user_password = params[:user_password]
@user_handicap = params[:user_handicap]

@user = User.new({:name => @user_name, :email => @user_email, :login => @user_email, :password => @user_password, :handicap => @user_handicap});
@auth_token = User.generatetoken(@user_login, @user_password)

@user = User.new({:name => @user_name, :email => @user_email, :login => @user_email, :password => @user_password, :password_confirmation => @user_password, :handicap => @user_handicap, :auth_token => @auth_token});
@user.save

if @user.errors.empty?
@res = {:auth_token => @auth_token, :user_id => @user.id, :name => @user_name, :email => @user_email, :login => @user_email, :password => @user_password, :handicap => @user_handicap}
else
@res= nil
end

render :json => @res.to_json()
end

private
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Expand Up @@ -35,7 +35,9 @@ def create
# reset_session
@user = User.new(params[:user])
@user.save

if @user.errors.empty?
auth_token = User.generatetoken(@user.login, @user.password)
self.current_user = @user

flash[:notice] = "Gracias por registrarse en My Golf Card!"
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -9,7 +9,7 @@ class User < ActiveRecord::Base
#named_scope :allowed,

# Virtual attribute for the unencrypted password
attr_accessor :password
attr_accessor :password, :auth_token

validates_presence_of :login, :email, :name
validates_presence_of :password, :if => :password_required?
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -56,7 +56,7 @@
map.connect '/api/getstrokes', :controller => 'api', :action => 'getstrokes', :conditions => {:method => :post}
map.connect '/api/uploadmatch', :controller => 'api', :action => 'uploadmatch', :conditions => {:method => :post}
map.connect '/api/uploadmatchform', :controller => 'api', :action => 'uploadmatchform', :conditions => {:method => :post}
map.connect '/api/newuser', :controller => 'api', :action => 'newuser', :conditions => {:method => :post}
map.connect '/api/newuser', :controller => 'api', :action => 'newuser'#, :conditions => {:method => :post}

map.resources :users

Expand Down

0 comments on commit 5ce6142

Please sign in to comment.