summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNihad Abbasov <narkoz.2008@gmail.com>2011-11-15 11:08:05 +0400
committerNihad Abbasov <narkoz.2008@gmail.com>2011-11-15 11:08:05 +0400
commit003bf61258ea20128315076936f09ea198e56bcb (patch)
tree85345a86c9c72080b4319fffdb11010a9b2b4aac
parent8d74123d61e83c29b5449773e1c471d2e2aa126f (diff)
downloadgitlab-ce-003bf61258ea20128315076936f09ea198e56bcb.tar.gz
add auth token for users
-rw-r--r--app/models/user.rb3
-rw-r--r--config/initializers/devise.rb4
-rw-r--r--db/migrate/20111115063954_add_authentication_token_to_users.rb5
-rw-r--r--db/schema.rb3
-rw-r--r--spec/models/user_spec.rb11
5 files changed, 19 insertions, 7 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 1d41028d59a..0320a6208eb 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,7 +1,7 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
- devise :database_authenticatable,
+ devise :database_authenticatable, :token_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
@@ -25,6 +25,7 @@ class User < ActiveRecord::Base
:foreign_key => :assignee_id,
:dependent => :destroy
+ before_create :ensure_authentication_token
scope :not_in_project, lambda { |project| where("id not in (:ids)", :ids => project.users.map(&:id) ) }
def identifier
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index e62db747a64..68bf5a0ea39 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -158,11 +158,11 @@ Devise.setup do |config|
# ==> Configuration for :token_authenticatable
# Defines name of the authentication token params key
- # config.token_authentication_key = :auth_token
+ config.token_authentication_key = :private_token
# If true, authentication through token does not store user in session and needs
# to be supplied on each request. Useful if you are using the token as API token.
- # config.stateless_token = false
+ config.stateless_token = true
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
diff --git a/db/migrate/20111115063954_add_authentication_token_to_users.rb b/db/migrate/20111115063954_add_authentication_token_to_users.rb
new file mode 100644
index 00000000000..84433656d6c
--- /dev/null
+++ b/db/migrate/20111115063954_add_authentication_token_to_users.rb
@@ -0,0 +1,5 @@
+class AddAuthenticationTokenToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :authentication_token, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c9abdef4f7a..83f916d4acf 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111111093150) do
+ActiveRecord::Schema.define(:version => 20111115063954) do
create_table "issues", :force => true do |t|
t.string "title"
@@ -103,6 +103,7 @@ ActiveRecord::Schema.define(:version => 20111111093150) do
t.string "skype", :default => "", :null => false
t.string "linkedin", :default => "", :null => false
t.string "twitter", :default => "", :null => false
+ t.string "authentication_token"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 14d48114c30..a22aee75b0d 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -19,15 +19,20 @@ describe User do
user.identifier.should == "test_mail.com"
end
+ it "should have authentication token" do
+ user = Factory(:user)
+ user.authentication_token.should_not == ""
+ end
+
describe "dependent" do
- before do
+ before do
@user = Factory :user
- @note = Factory :note,
+ @note = Factory :note,
:author => @user,
:project => Factory(:project)
end
- it "should destroy all notes with user" do
+ it "should destroy all notes with user" do
Note.find_by_id(@note.id).should_not be_nil
@user.destroy
Note.find_by_id(@note.id).should be_nil