Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
3a609038
Commit
3a609038
authored
Apr 15, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow creating Personal Access Tokens through the website.
parent
973b948b
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
104 additions
and
0 deletions
+104
-0
app/controllers/profiles/personal_access_tokens_controller.rb
...controllers/profiles/personal_access_tokens_controller.rb
+22
-0
app/models/personal_access_token.rb
app/models/personal_access_token.rb
+9
-0
app/models/user.rb
app/models/user.rb
+1
-0
app/views/profiles/personal_access_tokens/create.html.haml
app/views/profiles/personal_access_tokens/create.html.haml
+2
-0
app/views/profiles/personal_access_tokens/index.html.haml
app/views/profiles/personal_access_tokens/index.html.haml
+44
-0
config/routes.rb
config/routes.rb
+1
-0
db/migrate/20160415062917_create_personal_access_tokens.rb
db/migrate/20160415062917_create_personal_access_tokens.rb
+11
-0
db/schema.rb
db/schema.rb
+14
-0
No files found.
app/controllers/profiles/personal_access_tokens_controller.rb
0 → 100644
View file @
3a609038
class
Profiles::PersonalAccessTokensController
<
ApplicationController
def
index
@user
=
current_user
@personal_access_token
=
current_user
.
personal_access_tokens
.
new
end
def
create
@personal_access_token
=
current_user
.
personal_access_tokens
.
generate
(
personal_access_token_params
)
if
@personal_access_token
.
save
redirect_to
profile_personal_access_tokens_path
,
notice:
"Created personal access token!"
else
render
:index
end
end
private
def
personal_access_token_params
params
.
require
(
:personal_access_token
).
permit
(
:name
)
end
end
app/models/personal_access_token.rb
0 → 100644
View file @
3a609038
class
PersonalAccessToken
<
ActiveRecord
::
Base
belongs_to
:user
def
self
.
generate
(
params
)
personal_access_token
=
self
.
new
(
params
)
personal_access_token
.
token
=
Devise
.
friendly_token
(
50
)
personal_access_token
end
end
app/models/user.rb
View file @
3a609038
...
...
@@ -109,6 +109,7 @@ class User < ActiveRecord::Base
# Profile
has_many
:keys
,
dependent: :destroy
has_many
:emails
,
dependent: :destroy
has_many
:personal_access_tokens
,
dependent: :destroy
has_many
:identities
,
dependent: :destroy
,
autosave:
true
# Groups
...
...
app/views/profiles/personal_access_tokens/create.html.haml
0 → 100644
View file @
3a609038
%h1
Profiles::PersonalAccessTokens#create
%p
Find me in app/views/profiles/personal_access_tokens/create.html.haml
app/views/profiles/personal_access_tokens/index.html.haml
0 → 100644
View file @
3a609038
-
page_title
"Personal Access Tokens"
-
header_title
page_title
,
profile_personal_access_tokens_path
.row.prepend-top-default
.col-lg-3.profile-settings-sidebar
%h4
.prepend-top-0
=
page_title
%p
You can generate a personal access token for each application you use that needs access to GitLab.
.col-lg-9
%h5
.prepend-top-0
Add a Personal Access Token
%p
.profile-settings-content
Pick a name for the application, and we'll give you a unique token.
=
form_for
[
:profile
,
@personal_access_token
],
method: :post
,
html:
{
class:
'js-requires-input'
}
do
|
f
|
.form-group
=
f
.
label
:name
,
class:
'label-light'
=
f
.
text_field
:name
,
class:
"form-control"
,
required:
true
.prepend-top-default
=
f
.
submit
'Add Personal Access Token'
,
class:
"btn btn-create"
%hr
%h5
Active Personal Access Tokens
-
if
@user
.
personal_access_tokens
.
exists?
.table-responsive
%table
.table.table-striped
%thead
%tr
%th
Name
%th
Token
%th
Created At
%tbody
-
@user
.
personal_access_tokens
.
each
do
|
token
|
%tr
%td
=
token
.
name
%td
=
token
.
token
%td
=
token
.
created_at
-
else
%span
You don't have any tokens yet.
\ No newline at end of file
config/routes.rb
View file @
3a609038
...
...
@@ -333,6 +333,7 @@ Rails.application.routes.draw do
resources
:keys
resources
:emails
,
only:
[
:index
,
:create
,
:destroy
]
resource
:avatar
,
only:
[
:destroy
]
resources
:personal_access_tokens
,
only:
[
:index
,
:create
]
resource
:two_factor_auth
,
only:
[
:new
,
:create
,
:destroy
]
do
member
do
post
:codes
...
...
db/migrate/20160415062917_create_personal_access_tokens.rb
0 → 100644
View file @
3a609038
class
CreatePersonalAccessTokens
<
ActiveRecord
::
Migration
def
change
create_table
:personal_access_tokens
do
|
t
|
t
.
references
:user
,
index:
true
,
foreign_key:
true
,
null:
false
t
.
string
:token
,
index:
{
unique:
true
},
null:
false
t
.
string
:name
,
null:
false
t
.
timestamps
null:
false
end
end
end
db/schema.rb
View file @
3a609038
...
...
@@ -704,6 +704,19 @@ ActiveRecord::Schema.define(version: 20160421130527) do
add_index
"oauth_applications"
,
[
"owner_id"
,
"owner_type"
],
name:
"index_oauth_applications_on_owner_id_and_owner_type"
,
using: :btree
add_index
"oauth_applications"
,
[
"uid"
],
name:
"index_oauth_applications_on_uid"
,
unique:
true
,
using: :btree
create_table
"personal_access_tokens"
,
force: :cascade
do
|
t
|
t
.
integer
"user_id"
,
null:
false
t
.
string
"token"
,
null:
false
t
.
string
"name"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
boolean
"revoked"
,
default:
false
t
.
datetime
"expires_at"
end
add_index
"personal_access_tokens"
,
[
"token"
],
name:
"index_personal_access_tokens_on_token"
,
unique:
true
,
using: :btree
add_index
"personal_access_tokens"
,
[
"user_id"
],
name:
"index_personal_access_tokens_on_user_id"
,
using: :btree
create_table
"project_group_links"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
integer
"group_id"
,
null:
false
...
...
@@ -1030,4 +1043,5 @@ ActiveRecord::Schema.define(version: 20160421130527) do
add_index
"web_hooks"
,
[
"created_at"
,
"id"
],
name:
"index_web_hooks_on_created_at_and_id"
,
using: :btree
add_index
"web_hooks"
,
[
"project_id"
],
name:
"index_web_hooks_on_project_id"
,
using: :btree
add_foreign_key
"personal_access_tokens"
,
"users"
end
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