2016-04-19 04:31:21 -04:00
|
|
|
class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
|
2016-04-15 03:36:44 -04:00
|
|
|
def index
|
2016-11-22 03:57:31 -05:00
|
|
|
set_index_vars
|
2016-04-15 03:36:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@personal_access_token = current_user.personal_access_tokens.generate(personal_access_token_params)
|
|
|
|
|
|
|
|
if @personal_access_token.save
|
2016-06-01 22:57:47 -04:00
|
|
|
flash[:personal_access_token] = @personal_access_token.token
|
2016-06-09 04:38:49 -04:00
|
|
|
redirect_to profile_personal_access_tokens_path, notice: "Your new personal access token has been created."
|
2016-04-15 03:36:44 -04:00
|
|
|
else
|
2016-11-22 03:57:31 -05:00
|
|
|
set_index_vars
|
2016-04-15 03:36:44 -04:00
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-15 11:24:20 -04:00
|
|
|
def revoke
|
|
|
|
@personal_access_token = current_user.personal_access_tokens.find(params[:id])
|
|
|
|
|
|
|
|
if @personal_access_token.revoke!
|
2016-06-15 22:54:13 -04:00
|
|
|
flash[:notice] = "Revoked personal access token #{@personal_access_token.name}!"
|
2016-04-15 11:24:20 -04:00
|
|
|
else
|
2016-06-15 22:54:13 -04:00
|
|
|
flash[:alert] = "Could not revoke personal access token #{@personal_access_token.name}."
|
2016-04-15 11:24:20 -04:00
|
|
|
end
|
2016-06-15 22:54:13 -04:00
|
|
|
|
|
|
|
redirect_to profile_personal_access_tokens_path
|
2016-04-15 11:24:20 -04:00
|
|
|
end
|
|
|
|
|
2016-04-15 03:36:44 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def personal_access_token_params
|
2016-11-22 03:57:31 -05:00
|
|
|
params.require(:personal_access_token).permit(:name, :expires_at, scopes: [])
|
2016-04-15 03:36:44 -04:00
|
|
|
end
|
2016-06-02 23:53:16 -04:00
|
|
|
|
2016-11-22 03:57:31 -05:00
|
|
|
def set_index_vars
|
|
|
|
@personal_access_token ||= current_user.personal_access_tokens.build
|
|
|
|
@scopes = Gitlab::Auth::SCOPES
|
2016-06-02 23:53:16 -04:00
|
|
|
@active_personal_access_tokens = current_user.personal_access_tokens.active.order(:expires_at)
|
|
|
|
@inactive_personal_access_tokens = current_user.personal_access_tokens.inactive
|
|
|
|
end
|
2016-04-15 03:36:44 -04:00
|
|
|
end
|