diff options
author | Saito <saitowu@gmail.com> | 2012-06-29 11:43:15 +0400 |
---|---|---|
committer | Saito <saitowu@gmail.com> | 2012-06-29 11:43:15 +0400 |
commit | 7f44599ed0ddb1e01395f41e5f4bec869c2238e6 (patch) | |
tree | d182a22deaed0d61f67834abdf55c8d04bacffe8 /config/initializers/grack_auth.rb | |
parent | 86807b8ecc1b6e6e55e297d52bd2c04375d1e3f1 (diff) |
integrate with gitlabhq authority
Diffstat (limited to 'config/initializers/grack_auth.rb')
-rw-r--r-- | config/initializers/grack_auth.rb | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/config/initializers/grack_auth.rb b/config/initializers/grack_auth.rb index 17d3641a366..27a0a1db903 100644 --- a/config/initializers/grack_auth.rb +++ b/config/initializers/grack_auth.rb @@ -2,7 +2,30 @@ module Grack class Auth < Rack::Auth::Basic def valid? - true - end - end -end + # Authentication with username and password + email, password = @auth.credentials + user = User.find_by_email(email) + return false unless user.valid_password?(password) + + # Find project by PATH_INFO from env + if m = /^\/([\w-]+).git/.match(@env['PATH_INFO']).to_a + return false unless project = Project.find_by_path(m.last) + end + + # Git upload and receive + if @env['REQUEST_METHOD'] == 'GET' + true + elsif @env['REQUEST_METHOD'] == 'POST' + if @env['REQUEST_URI'].end_with?('git-upload-pack') + return project.dev_access_for?(user) + elsif @env['REQUEST_URI'].end_with?('git-upload-pack') + #TODO master branch protection + return project.dev_access_for?(user) + else + false + end + end + + end# valid? + end# Auth +end# Grack |