Ruby On Rails in UA Icon_home Главная Add to bookmarks Translate translate Profile Войти
Регистрация Форум Блоги Пользователи Ресурсы Список джемов      Поиск   

Ruby On Rails in UA/Вопросы по программированию на ROR/Ruby CGI - Basic Authorization/RE: Ruby CGI - Basic Authorization

Назадназад Новыйновый Ответитьответить
2008-06-16 14:34:28 Ответить  
Dracula
Dracula
Адрес:
Сообщений: 23
Регистр: 2008-05-31
его блог 0 сообщ.
RE: Ruby CGI - Basic Authorization
Большое спасибо Равилю за оказанную помощь в реализации этого примера:
Пример Ruby CGI Basic Authorization
логин и пароль - 'test'

---------------------------------------
Добавьте это в свой .htaccess
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_CGI_AUTHORIZATION:%1]
---------------------------------------
index.rb
---------------------------------------
#!c:/ruby/bin/ruby.exe

$kcode = "windows-1251"

require 'cgi'

cgi = CGI.new 'html4'
auth_type, credentials = ENV['HTTP_CGI_AUTHORIZATION'].split(' ')

if auth_type == 'Basic' && (user, pass = credentials.unpack('m*').first.split(':', 2)) && user == 'test' && pass = 'test'
cgi.out {
cgi.html {
cgi.body {
cgi.h2 { "Логин: #{user}" } +
cgi.h2 { "Пароль: #{pass}" }
}
}
}
else
cgi.out("Status" => "401 Authorization Required", "Type" => "text/html", "WWW-Authenticate" => 'Basic realm="Web Password"') do
"401 Authorization Required"
end
end

, , ,
Назадназад Новыйновый Ответитьответить
Ключевые слова:
Гости: 81 Онлайн: 0
Rambler's Top100
О проекте по всем вопросам обращайтесь на support
Rubyclub.com.ua Copyright © 2007 - 2008