Skip to content
Extraits de code Groupes Projets
Valider 24e17322 rédigé par Lukas Matt's avatar Lukas Matt
Parcourir les fichiers

Implement token authentication

* create a new token on a new session
* delete the current token on session exit
parent ae582e45
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class Api::V1::TokensController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :authenticate_user!
respond_to :json
def create
current_user.ensure_authentication_token!
render :status => 200, :json => { :token => current_user.authentication_token }
end
def destroy
current_user.reset_authentication_token!
render :json => true, :status => 200
end
end
......@@ -7,4 +7,10 @@ class SessionsController < Devise::SessionsController
layout ->(c) { request.format == :mobile ? "application" : "with_header_with_footer" }, :only => [:new]
use_bootstrap_for :new
after_filter :reset_authentication_token, :only => [:create]
before_filter :reset_authentication_token, :only => [:destroy]
def reset_authentication_token
current_user.reset_authentication_token!
end
end
......@@ -16,7 +16,7 @@ class User < ActiveRecord::Base
scope :yearly_actives, ->(time = Time.now) { logged_in_since(time - 1.year) }
scope :halfyear_actives, ->(time = Time.now) { logged_in_since(time - 6.month) }
devise :database_authenticatable, :registerable,
devise :token_authenticatable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:lockable, :lastseenable, :lock_strategy => :none, :unlock_strategy => :none
......
......@@ -6,6 +6,7 @@ require 'sidekiq/web'
require 'sidetiq/web'
Diaspora::Application.routes.draw do
resources :report, :except => [:edit, :new]
if Rails.env.production?
......@@ -209,6 +210,9 @@ Diaspora::Application.routes.draw do
get "/users/:username" => 'users#show', :as => 'user'
get "/tags/:name" => 'tags#show', :as => 'tag'
end
namespace :v1 do
resources :tokens, :only => [:create, :destroy]
end
end
get 'community_spotlight' => "contacts#spotlight", :as => 'community_spotlight'
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter