forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers_controller.rb
More file actions
51 lines (44 loc) · 1.51 KB
/
users_controller.rb
File metadata and controls
51 lines (44 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class UsersController < Devise::RegistrationsController
before_filter :authenticate_user!, :except => [:auth]
prepend_before_filter :check_captcha, only: [:create] # Change this to be any actions you want to protect.
respond_to :html, :json, :xml
# Overriding devise helpers
def resource_name
:user
end
# Auth endpoint
# validates a given access_token by responding with 200/401 status
def auth
# I like doing /auth?<token>
token = params[:access_token] ? params[:access_token] : params.keys.first
respond_with({status: 'unauthorized'}, :status => 401) and return if !token
@user = User.find_by_access_token(token)
respond_with({status: 'unauthorized'}, :status => 401) and return if !@user
respond_with @user
end
def dashboard
# Let the URL be ugly for now - preferable to users being confused on how
# to share their account page.
if current_user.present?
if current_user.primary_account
redirect_to :controller => 'players', :action => 'show', :id => current_user.primary_account.esdb_id, :name => current_user.primary_account.name
else
redirect_to settings_url
end
else
redirect_to :controller => :home, :action => :home
end
end
def update
current_user.update_attributes(params[:user])
render :text => "OK"
end
private
def check_captcha
unless verify_recaptcha
self.resource = resource_class.new sign_up_params
respond_with_navigational(resource) { render :new }
else
end
end
end