added token authenticatable to user model
This commit is contained in:
parent
01796fb7be
commit
be662a65c6
7 changed files with 46 additions and 4 deletions
|
|
@ -141,4 +141,13 @@ class UsersController < ApplicationController
|
||||||
tar_path = PhotoMover::move_photos(current_user)
|
tar_path = PhotoMover::move_photos(current_user)
|
||||||
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
|
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_new_token
|
||||||
|
if current_user.reset_authentication_token!
|
||||||
|
@token = current_user.authentication_token
|
||||||
|
else
|
||||||
|
@token = "No token created"
|
||||||
|
end
|
||||||
|
render :text => @token
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
devise :invitable, :database_authenticatable, :registerable,
|
devise :invitable, :database_authenticatable, :registerable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable,
|
:recoverable, :rememberable, :trackable, :validatable,
|
||||||
:timeoutable
|
:timeoutable, :token_authenticatable
|
||||||
|
|
||||||
before_validation :strip_and_downcase_username
|
before_validation :strip_and_downcase_username
|
||||||
before_validation :set_current_language, :on => :create
|
before_validation :set_current_language, :on => :create
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ Devise.setup do |config|
|
||||||
|
|
||||||
# ==> Configuration for :token_authenticatable
|
# ==> Configuration for :token_authenticatable
|
||||||
# Defines name of the authentication token params key
|
# Defines name of the authentication token params key
|
||||||
# config.token_authentication_key = :auth_token
|
config.token_authentication_key = :auth_token
|
||||||
|
|
||||||
# ==> Scopes configuration
|
# ==> Scopes configuration
|
||||||
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,12 @@ Diaspora::Application.routes.draw do
|
||||||
:invitations => "invitations"} do
|
:invitations => "invitations"} do
|
||||||
get 'invitations/resend/:id' => 'invitations#resend', :as => 'invitation_resend'
|
get 'invitations/resend/:id' => 'invitations#resend', :as => 'invitation_resend'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# generating a new user token (for devise)
|
||||||
|
match 'users/generate_new_token' => 'users#generate_new_token'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get 'login' => redirect('/users/sign_in')
|
get 'login' => redirect('/users/sign_in')
|
||||||
|
|
||||||
scope 'admins', :controller => :admins do
|
scope 'admins', :controller => :admins do
|
||||||
|
|
|
||||||
11
db/migrate/20110518184453_add_token_auth_to_user.rb
Normal file
11
db/migrate/20110518184453_add_token_auth_to_user.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
class AddTokenAuthToUser < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column(:users, :authentication_token, :string, :limit => 30)
|
||||||
|
add_index(:users, :authentication_token, :unique => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_index(:users, :column => :authentication_token)
|
||||||
|
remove_column(:users, :authentication_token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20110518010050) do
|
ActiveRecord::Schema.define(:version => 20110518184453) do
|
||||||
|
|
||||||
create_table "aspect_memberships", :force => true do |t|
|
create_table "aspect_memberships", :force => true do |t|
|
||||||
t.integer "aspect_id", :null => false
|
t.integer "aspect_id", :null => false
|
||||||
|
|
@ -361,8 +361,10 @@ ActiveRecord::Schema.define(:version => 20110518010050) do
|
||||||
t.integer "invitation_limit"
|
t.integer "invitation_limit"
|
||||||
t.integer "invited_by_id"
|
t.integer "invited_by_id"
|
||||||
t.string "invited_by_type"
|
t.string "invited_by_type"
|
||||||
|
t.string "authentication_token", :limit => 30
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true
|
||||||
add_index "users", ["email"], :name => "index_users_on_email"
|
add_index "users", ["email"], :name => "index_users_on_email"
|
||||||
add_index "users", ["invitation_service", "invitation_identifier"], :name => "index_users_on_invitation_service_and_invitation_identifier", :unique => true
|
add_index "users", ["invitation_service", "invitation_identifier"], :name => "index_users_on_invitation_service_and_invitation_identifier", :unique => true
|
||||||
add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token"
|
add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token"
|
||||||
|
|
|
||||||
|
|
@ -138,4 +138,18 @@ describe UsersController do
|
||||||
assigns[:email_prefs]['mentioned'].should be_false
|
assigns[:email_prefs]['mentioned'].should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#generate_new_token' do
|
||||||
|
it 'generates a new token for the current user' do
|
||||||
|
lambda {
|
||||||
|
get 'generate_new_token'
|
||||||
|
}.should change{ @user.reload.authentication_token }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'displays a token' do
|
||||||
|
get 'generate_new_token'
|
||||||
|
response.body.should include(@user.reload.authentication_token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Loading…
Reference in a new issue