[refs #374] Add custom http basic auth for api
This commit is contained in:
parent
5bcebcf384
commit
7812adfdbc
|
@ -396,11 +396,11 @@ module GitHub
|
|||
}
|
||||
|
||||
ERROR_AUTH = {
|
||||
"error" => "You need to sign in or sign up before continuing."
|
||||
"message" => "You need to sign in or sign up before continuing."
|
||||
}
|
||||
|
||||
ERROR_WRONG_PASS = {
|
||||
"error" => "Invalid email or password."
|
||||
"message" => "Invalid email or password."
|
||||
}
|
||||
|
||||
ERROR_RATE_LIMIT = {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Api::V1::BaseController < ApplicationController
|
||||
before_filter :http_auth
|
||||
before_filter :restrict_paginate, :only => :index
|
||||
|
||||
protected
|
||||
|
@ -8,4 +9,12 @@ class Api::V1::BaseController < ApplicationController
|
|||
params[:per_page] = 30 if params[:per_page].blank? or params[:per_page].to_i < 1
|
||||
params[:per_page] = 100 if params[:per_page].to_i >100
|
||||
end
|
||||
|
||||
def http_auth
|
||||
authenticate_or_request_with_http_basic do |email, password|
|
||||
raise HttpBasicAuthError if email.blank? && password.blank?
|
||||
@current_user = User.find_by_email(email)
|
||||
@current_user && @current_user.valid_password?(password) ? true : raise(HttpBasicWrongPassError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Api::V1::BuildListsController < Api::V1::BaseController
|
||||
before_filter :authenticate_user!
|
||||
skip_before_filter :authenticate_user!, :only => [:show, :index] if APP_CONFIG['anonymous_access']
|
||||
#before_filter :authenticate_user!
|
||||
#skip_before_filter :authenticate_user!, :only => [:show, :index] if APP_CONFIG['anonymous_access']
|
||||
|
||||
load_and_authorize_resource :project, :only => :index
|
||||
load_and_authorize_resource :build_list, :only => [:show, :create, :cancel, :publish, :reject_publish]#, :shallow => true
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Api::V1::PlatformsController < Platforms::BaseController
|
||||
|
||||
before_filter :authenticate_user!
|
||||
skip_before_filter :authenticate_user!, :only => [:advisories] if APP_CONFIG['anonymous_access']
|
||||
#before_filter :authenticate_user!
|
||||
#skip_before_filter :authenticate_user!, :only => [:advisories] if APP_CONFIG['anonymous_access']
|
||||
load_and_authorize_resource
|
||||
|
||||
autocomplete :user, :uname
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Api::V1::ProjectsController < Api::V1::BaseController
|
||||
before_filter :authenticate_user!
|
||||
#before_filter :authenticate_user!
|
||||
load_and_authorize_resource
|
||||
|
||||
def get_id
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Api::V1::RepositoriesController < Api::V1::BaseController
|
||||
before_filter :authenticate_user!
|
||||
#before_filter :authenticate_user!
|
||||
|
||||
load_and_authorize_resource :repository, :through => :platform, :shallow => true
|
||||
end
|
||||
|
|
|
@ -40,6 +40,13 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
rescue_from HttpBasicAuthError do |exception|
|
||||
render :json => {:message => t("flash.http_basic_error_msg")}.to_json, :status => 401
|
||||
end
|
||||
rescue_from HttpBasicWrongPassError do |exception|
|
||||
render :json => {:message => t("flash.http_basic_wrong_pass_error_message")}.to_json, :status => 401
|
||||
end
|
||||
|
||||
rescue_from Grit::NoSuchPathError, :with => :not_found
|
||||
|
||||
protected
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
class HttpBasicWrongPassError < StandardError
|
||||
end
|
||||
class HttpBasicAuthError < StandardError
|
||||
end
|
|
@ -138,6 +138,8 @@ en:
|
|||
|
||||
500_message: Error 500. Something went wrong. We've been notified about this issue and we'll take a look at it shortly.
|
||||
404_message: Error 404. Resource not found!
|
||||
http_basic_auth_error_message: You need to sign in or sign up before continuing
|
||||
http_basic_wrong_pass_error_message: Invalid email or password
|
||||
|
||||
collaborators:
|
||||
successfully_changed: Collaborators list successfully changed
|
||||
|
|
|
@ -138,6 +138,8 @@ ru:
|
|||
|
||||
500_message: Ошибка 500. Что-то пошло не так. Мы уже в курсе данной проблемы и постараемся поскорее ее решить.
|
||||
404_message: Ошибка 404. Страница не найдена!
|
||||
http_basic_auth_error_message: Вы должны авторизоваться или зарегестрироваться
|
||||
http_basic_wrong_pass_error_message: Неверный имейл или пароль
|
||||
|
||||
collaborators:
|
||||
successfully_changed: Список коллабораторов успешно изменен
|
||||
|
|
Loading…
Reference in New Issue