BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
003bf612
Commit
003bf612
authored
Nov 15, 2011
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add auth token for users
parent
8d74123d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
7 deletions
+19
-7
user.rb
app/models/user.rb
+2
-1
devise.rb
config/initializers/devise.rb
+2
-2
20111115063954_add_authentication_token_to_users.rb
...grate/20111115063954_add_authentication_token_to_users.rb
+5
-0
schema.rb
db/schema.rb
+2
-1
user_spec.rb
spec/models/user_spec.rb
+8
-3
No files found.
app/models/user.rb
View file @
003bf612
class
User
<
ActiveRecord
::
Base
class
User
<
ActiveRecord
::
Base
# Include default devise modules. Others available are:
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise
:database_authenticatable
,
devise
:database_authenticatable
,
:token_authenticatable
,
:recoverable
,
:rememberable
,
:trackable
,
:validatable
:recoverable
,
:rememberable
,
:trackable
,
:validatable
# Setup accessible (or protected) attributes for your model
# Setup accessible (or protected) attributes for your model
...
@@ -25,6 +25,7 @@ class User < ActiveRecord::Base
...
@@ -25,6 +25,7 @@ class User < ActiveRecord::Base
:foreign_key
=>
:assignee_id
,
:foreign_key
=>
:assignee_id
,
:dependent
=>
:destroy
:dependent
=>
:destroy
before_create
:ensure_authentication_token
scope
:not_in_project
,
lambda
{
|
project
|
where
(
"id not in (:ids)"
,
:ids
=>
project
.
users
.
map
(
&
:id
)
)
}
scope
:not_in_project
,
lambda
{
|
project
|
where
(
"id not in (:ids)"
,
:ids
=>
project
.
users
.
map
(
&
:id
)
)
}
def
identifier
def
identifier
...
...
config/initializers/devise.rb
View file @
003bf612
...
@@ -158,11 +158,11 @@ Devise.setup do |config|
...
@@ -158,11 +158,11 @@ 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
=
:private
_token
# If true, authentication through token does not store user in session and needs
# 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.
# to be supplied on each request. Useful if you are using the token as API token.
# config.stateless_token = fals
e
config
.
stateless_token
=
tru
e
# ==> 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
...
...
db/migrate/20111115063954_add_authentication_token_to_users.rb
0 → 100644
View file @
003bf612
class
AddAuthenticationTokenToUsers
<
ActiveRecord
::
Migration
def
change
add_column
:users
,
:authentication_token
,
:string
end
end
db/schema.rb
View file @
003bf612
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,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
=>
2011111
1093150
)
do
ActiveRecord
::
Schema
.
define
(
:version
=>
2011111
5063954
)
do
create_table
"issues"
,
:force
=>
true
do
|
t
|
create_table
"issues"
,
:force
=>
true
do
|
t
|
t
.
string
"title"
t
.
string
"title"
...
@@ -103,6 +103,7 @@ ActiveRecord::Schema.define(:version => 20111111093150) do
...
@@ -103,6 +103,7 @@ ActiveRecord::Schema.define(:version => 20111111093150) do
t
.
string
"skype"
,
:default
=>
""
,
:null
=>
false
t
.
string
"skype"
,
:default
=>
""
,
:null
=>
false
t
.
string
"linkedin"
,
:default
=>
""
,
:null
=>
false
t
.
string
"linkedin"
,
:default
=>
""
,
:null
=>
false
t
.
string
"twitter"
,
:default
=>
""
,
:null
=>
false
t
.
string
"twitter"
,
:default
=>
""
,
:null
=>
false
t
.
string
"authentication_token"
end
end
add_index
"users"
,
[
"email"
],
:name
=>
"index_users_on_email"
,
:unique
=>
true
add_index
"users"
,
[
"email"
],
:name
=>
"index_users_on_email"
,
:unique
=>
true
...
...
spec/models/user_spec.rb
View file @
003bf612
...
@@ -19,15 +19,20 @@ describe User do
...
@@ -19,15 +19,20 @@ describe User do
user
.
identifier
.
should
==
"test_mail.com"
user
.
identifier
.
should
==
"test_mail.com"
end
end
it
"should have authentication token"
do
user
=
Factory
(
:user
)
user
.
authentication_token
.
should_not
==
""
end
describe
"dependent"
do
describe
"dependent"
do
before
do
before
do
@user
=
Factory
:user
@user
=
Factory
:user
@note
=
Factory
:note
,
@note
=
Factory
:note
,
:author
=>
@user
,
:author
=>
@user
,
:project
=>
Factory
(
:project
)
:project
=>
Factory
(
:project
)
end
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
Note
.
find_by_id
(
@note
.
id
).
should_not
be_nil
@user
.
destroy
@user
.
destroy
Note
.
find_by_id
(
@note
.
id
).
should
be_nil
Note
.
find_by_id
(
@note
.
id
).
should
be_nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment