本项目的成员可以使用自己的用户名和密码克隆
This commit is contained in:
parent
38b97aa558
commit
6fa67051e1
1
Gemfile
1
Gemfile
|
@ -6,6 +6,7 @@ unless RUBY_PLATFORM =~ /w32/
|
|||
gem 'iconv'
|
||||
end
|
||||
|
||||
gem 'grack', path:'./lib/grack'
|
||||
gem 'rest-client'
|
||||
gem "mysql2", "= 0.3.18"
|
||||
gem 'redis-rails'
|
||||
|
|
|
@ -197,9 +197,12 @@ default:
|
|||
#max_concurrent_ajax_uploads: 2
|
||||
#pic_types: "bmp,jpeg,jpg,png,gif"
|
||||
|
||||
repository_root_path: '/Users/guange/repository'
|
||||
|
||||
# specific configuration options for production environment
|
||||
# that overrides the default ones
|
||||
production:
|
||||
repository_root_path: '/home/pdl/redmine-2.3.2-0/apache2/htdocs'
|
||||
cookie_domain: ".trustie.net"
|
||||
rmagick_font_path: /usr/share/fonts/ipa-mincho/ipam.ttf
|
||||
email_delivery:
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
RedmineApp::Application.routes.draw do
|
||||
mount Mobile::API => '/api'
|
||||
|
||||
# Enable Grack support
|
||||
mount Trustie::Grack.new, at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) }, via: [:get, :post]
|
||||
|
||||
resources :homework_users
|
||||
resources :no_uses
|
||||
delete 'no_uses', :to => 'no_uses#delete'
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 949be9116a76b50a6f86baf507dec4c4d7fb34c6
|
|
@ -1,2 +1,3 @@
|
|||
require 'trustie/utils'
|
||||
require 'trustie/utils/image'
|
||||
require 'trustie/grack/grack'
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
require 'rack/auth/basic'
|
||||
require 'rack/auth/abstract/handler'
|
||||
require 'rack/auth/abstract/request'
|
||||
|
||||
module Grack
|
||||
class Auth < Rack::Auth::Basic
|
||||
def call(env)
|
||||
@env = env
|
||||
@request = Rack::Request.new(env)
|
||||
@auth = Request.new(env)
|
||||
|
||||
if not @auth.provided?
|
||||
unauthorized
|
||||
elsif not @auth.basic?
|
||||
bad_request
|
||||
else
|
||||
result = if (access = valid?(@auth) and access == true)
|
||||
@env['REMOTE_USER'] = @auth.username
|
||||
@app.call(env)
|
||||
else
|
||||
if access == '404'
|
||||
render_not_found
|
||||
elsif access == '403'
|
||||
#render_no_access
|
||||
unauthorized
|
||||
else
|
||||
unauthorized
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
end# method call
|
||||
|
||||
|
||||
def render_not_found
|
||||
[404, {"Content-Type" => "text/plain"}, ["Not Found"]]
|
||||
end
|
||||
|
||||
def valid?(auth)
|
||||
match = @request.path_info.match(/(\/.+\.git)\//)
|
||||
if match
|
||||
rep = Repository.where("root_url like ?", "%#{match[1]}")
|
||||
return "404" if rep.empty?
|
||||
username, password = auth.credentials
|
||||
user, last_login_on = User.try_to_login(username, password)
|
||||
return '403' unless user
|
||||
if user.member_of?(rep.first.project) || user.admin?
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
end# class Auth
|
||||
end# module Grack
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
require_relative 'auth'
|
||||
|
||||
module Trustie
|
||||
module Grack
|
||||
|
||||
def self.new
|
||||
Rack::Builder.new do
|
||||
use ::Grack::Auth
|
||||
run ::Grack::Server.new(
|
||||
project_root: Redmine::Configuration['repository_root_path'] || "/home/pdl/redmine-2.3.2-0/apache2/htdocs",
|
||||
upload_pack: true,
|
||||
receive_pack:true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue