Skip to content

Commit

Permalink
Regenerate API Token on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanPorta committed Jan 13, 2015
1 parent 76d00ec commit 02c1a71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/sessions_controller.rb
Expand Up @@ -18,6 +18,8 @@ def login

# GET /logout
def destroy
# TODO: Probably not how we want to handle this, but it will work for now.
current_user.regenerate_api_token
current_session nil
redirect_to root_url
end
Expand Down
7 changes: 6 additions & 1 deletion app/models/user.rb
Expand Up @@ -86,10 +86,15 @@ def friendship_requests_received
inverse_friendships.where approved: nil
end

def regenerate_api_token
generate_api_token
save
end

private

def generate_api_token
self.api_token ||= loop do
self.api_token = loop do
random_token = SecureRandom.urlsafe_base64(64).tr('lIO0', 'sxyz')
break random_token unless self.class.exists?(api_token: random_token)
end
Expand Down

0 comments on commit 02c1a71

Please sign in to comment.