2012-03-04 19:30:26 +00:00
|
|
|
class UserTokensController < ApplicationController
|
2012-03-06 18:51:21 +00:00
|
|
|
before_filter :ensure_authenticated!
|
2012-03-04 19:30:26 +00:00
|
|
|
|
|
|
|
def create
|
2013-09-25 16:01:54 +00:00
|
|
|
claimed_num = user_token_creator.create(current_user, params[:user_token])
|
2012-03-04 19:30:26 +00:00
|
|
|
|
2013-09-25 16:01:54 +00:00
|
|
|
if claimed_num
|
|
|
|
redirect_to_profile(claimed_num)
|
|
|
|
else
|
|
|
|
render :error
|
|
|
|
end
|
|
|
|
end
|
2012-03-04 19:30:26 +00:00
|
|
|
|
2013-09-25 16:01:54 +00:00
|
|
|
private
|
2012-03-04 19:30:26 +00:00
|
|
|
|
2013-09-25 16:01:54 +00:00
|
|
|
def redirect_to_profile(claimed_num)
|
|
|
|
if claimed_num > 0
|
|
|
|
notice = "Claimed #{claimed_num} asciicasts, yay!"
|
2012-03-04 19:30:26 +00:00
|
|
|
else
|
2013-09-25 16:01:54 +00:00
|
|
|
notice = "Authenticated successfully, yippie!"
|
2012-03-04 19:30:26 +00:00
|
|
|
end
|
2013-09-25 16:01:54 +00:00
|
|
|
|
|
|
|
redirect_to profile_path(current_user), :notice => notice
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_token_creator
|
|
|
|
@user_token_creator ||= UserTokenCreator.new
|
2012-03-04 19:30:26 +00:00
|
|
|
end
|
2013-09-25 16:01:54 +00:00
|
|
|
|
2012-03-04 19:30:26 +00:00
|
|
|
end
|