parser

Написать ответ на текущее сообщение

 

 
   команды управления поиском

Ответ

Sanja v.2 24.05.2009 16:21

выкачайте и положите в ./lib новый модуль (не от JainRain), а consumer.cgi замените на
#! /usr/bin/perl -I ./lib

use strict;
use warnings;
use CGI;
use LWP::UserAgent;
use Net::OpenID::Consumer;

use Digest::MD5 qw(md5_hex);
use URI::Escape;

my $SECRET = 'вставьте сюда что-нть своё.';
# Также замените http://lj.bougakov.com/table/login/
# /return.html в тексте ниже на свой URI

my $cgi = new CGI;

if ($cgi->param("user")) {
	 my $csr = init_consumer($cgi);
	 my $url;
	 if ($cgi->param('site')) {
	 	$url = sprintf($cgi->param('site'),$cgi->param('user'));
	 } else {
	 	$url = $cgi->param('user');
	 }
	 print STDERR "URL entered: $url\n";
	 my $claimed_identity = $csr->claimed_identity($url);
		if (! defined $claimed_identity) {
			foreach my $par ($cgi->param) {
				print STDERR "$par = ".$cgi->param($par)."\n";
			}
			print "No identity on given URL";
		}
		my $check_url = $claimed_identity->check_url(
			return_to =>
			$cgi->url(-full=>1,-query=>0)."?openidvfy=1",
			trust_root=>$cgi->url(-base=>1));
		print $cgi->redirect(-location=> $check_url);
} elsif ($cgi->param("openidvfy")) {
	my $csr = init_consumer($cgi);
	if (my $setup_url = $csr->user_setup_url) {
		print $cgi->redirect(-location=>$setup_url);
		exit(0);
	} elsif	($csr->user_cancel) {
		print $cgi->header('text/html');
		print $cgi->start_html("Login cancelled"),
			$cgi->h1("Login cancelled"),
			$cgi->p("You've cancelled login on other site"),
			$cgi->end_html;
	} elsif (my $vident = $csr->verified_identity) {

	my $timestamp = time();
	my $hash = md5_hex($SECRET . "|" . $vident->url . "|".$ENV{HTTP_USER_AGENT}."|".$ENV{REMOTE_ADDR}."|".$ENV{HTTP_VIA}."|".$timestamp);
	print $cgi->redirect('http://lj.bougakov.com/table/login/return.html?timestamp=' . $timestamp . '&identity_url=' . uri_escape($vident->url) . '&token=' . uri_escape($hash) . '&dummy=1');

	#	print $cgi->header('text/html');
	#	print $cgi->start_html("Authentication successful"),
	#		$cgi->h1("Authentication successfull"),
	#		$cgi->p("You've successfully logged into our site as",
	#			$cgi->a({-href=>$vident->url},$vident->display),". Congratulations!"),
	#		$cgi->end_html;
	} else {
		print $cgi->header('text/html');
		print $cgi->start_html("Authentication failed"),
			$cgi->h1("Authentication failed"),
			$cgi->p("Error validating identity:",
			$cgi->escapeHTML($csr->err));
			$cgi->end_html;
	}

} else {
	# Print out form to enter OpenID URL
	my %site_list=(
		'http://users.livejournal.com/%s'=>'LiveJournal');
#		'http://lj.rossia.org/users/%s'=>'LJ.Rossia.org',
#		'http://www.greatestjournal.com/users/%s'=>'GreatestJournal',
#		'%s','Other (enter full URL into Login field');
	print $cgi->header("text/html"),
	$cgi->start_html("My test open_id page"),
	$cgi->h1("My test open_id page"),
	$cgi->start_form(-method=>'POST'),
	"Login:",$cgi->textfield(-name=>"user",-size=>40),"<br>",
	"Site:",
	$cgi->popup_menu(-name=>"site",-Values=>[sort keys(%site_list)],
		-labels=>\%site_list),
	"<br>",$cgi->submit(-name=>'login',-value=>'Log in'),
	$cgi->end_form,
	$cgi->end_html;
	exit(0);
}

sub init_consumer {
	my $cgi=shift;
	 return Net::OpenID::Consumer->new(
	   ua	 => LWP::UserAgent->new(),
	   args  => $cgi,
	   consumer_secret => $SECRET ,
	   required_root => $cgi->url(-base=>1),
	 );
}