gitlab-org--gitlab-foss/app/controllers/profiles/personal_access_tokens_controller.rb

43 lines
1.3 KiB
Ruby
Raw Normal View History

class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
def index
set_index_vars
end
def create
@personal_access_token = current_user.personal_access_tokens.generate(personal_access_token_params)
if @personal_access_token.save
flash[:personal_access_token] = @personal_access_token.token
redirect_to profile_personal_access_tokens_path, notice: "Your new personal access token has been created."
else
set_index_vars
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!
flash[:notice] = "Revoked personal access token #{@personal_access_token.name}!"
2016-04-15 11:24:20 -04:00
else
flash[:alert] = "Could not revoke personal access token #{@personal_access_token.name}."
2016-04-15 11:24:20 -04:00
end
redirect_to profile_personal_access_tokens_path
2016-04-15 11:24:20 -04:00
end
private
def personal_access_token_params
params.require(:personal_access_token).permit(:name, :expires_at, scopes: [])
end
def set_index_vars
@personal_access_token ||= current_user.personal_access_tokens.build
@scopes = Gitlab::Auth::SCOPES
@active_personal_access_tokens = current_user.personal_access_tokens.active.order(:expires_at)
@inactive_personal_access_tokens = current_user.personal_access_tokens.inactive
end
end