2012-07-31 08:35:27 +01:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
class Api::V1::BaseController < ApplicationController
|
2012-09-21 20:15:48 +01:00
|
|
|
before_filter :http_auth
|
2012-08-31 13:23:44 +01:00
|
|
|
before_filter :restrict_paginate, :only => :index
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def restrict_paginate
|
|
|
|
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
|
2012-09-21 20:15:48 +01:00
|
|
|
|
|
|
|
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
|
2012-07-31 08:35:27 +01:00
|
|
|
end
|