]> wagner.pp.ru Git - oss/stilllife.git/commitdiff
Debugged posting with
authorVictor Wagner <vitus@wagner.pp.ru>
Wed, 26 Mar 2008 22:46:41 +0000 (22:46 +0000)
committerVictor Wagner <vitus@wagner.pp.ru>
Wed, 26 Mar 2008 22:46:41 +0000 (22:46 +0000)
simultaneuos openid login

forum/forum

index 5d56642520e6ab0a7edccee849b7225d981c5bf7..9f12ad841445c91abe6aa7519661e8fef9b86df5 100755 (executable)
@@ -98,6 +98,9 @@ if ($cgi->request_method ne "POST") {
                                }       
                        }
                }
+               if (index($path_translated,$forum->{userdir})==0) {
+                       show_user_page($cgi,$forum);
+               }       
                show_error($forum,"Некорректный вызов скрипта. Отсутствует параметр
                                действия");
        }       
@@ -119,6 +122,13 @@ if ($cgi->request_method ne "POST") {
        show_error($forum,"Некорректный вызов скрипта. Отсутствует параметр действия");
 }      
 
+#-------------------------------------------------------------- 
+#-------- Чтение конфигурационного файла и связанные с этим действия
+#------------------------------------------------------------------ 
+
+#
+# Преобразование пути в файловой системе сервера в путь в URL
+# 
 sub dir2url {
        my ($cgi,$dir) = @_;
        my $prefix="";
@@ -149,12 +159,13 @@ sub dir2url {
 # враг.
 # Возвращает список имя,значение, имя, значение который прививается в
 # хэш
-
+#
 sub get_forum_config {
-       $path_translated = $1 if $ENV{PATH_TRANSLATED}=~/^(\S+)$/;
+       $path_translated = $1 if $ENV{PATH_TRANSLATED}=~/^(.+)$/;
        $path_translated=~s/\/+$//;
        my @path=split("/",$path_translated);
        while (@path>1) {
+               print STDERR "Searching for config in ",join("/",@path),"\n";
                if (-r (my $config=join("/",@path,".forum")) ) {
                        open F,"<",$config;
                        my %config;
@@ -168,6 +179,7 @@ sub get_forum_config {
                        # файл .forum
                         
                        $config{"forumtop"} = dir2url($cgi,join("/",@path));
+                       $config{"forumroot"} = join("/",@path);
                        # Если в конфиге отсутствует переменная templates, но
                        # рядом с конфигом присутствует директория templates,
                        # то шаблоны там.
@@ -201,6 +213,9 @@ sub get_forum_config {
                                show_error(\%config,"В конфигурации форума указана несуществующая директория данных "); 
                                exit;
                        }
+                       #
+                       # Некоторые умолчания
+                       #
                        $config{"authperiod"}="+1M" if (! exists $config{"authperiod"}); 
                        $config{"renewtime"} = "86000" if (!exists $config{"renewtime"});
                        $config{"replies_per_page"} = 50 if (!exists $config{"replies_per_page"});
@@ -353,6 +368,7 @@ sub show_template {
        print
        $cgi->header(-type=>"text/html",-charset=>"utf-8",($forum->{cookies}?(-cookie=>$forum->{cookies}):())),
        $tree->as_HTML("<>&");
+       exit;
 }
 #
 # Поправляет ссылки на служебные файлы и скрипты форума
@@ -416,14 +432,7 @@ sub substitute_user_info {
 my ($tree,$forum,$user) = @_;
 my %userinfo;
 if (defined $user) {
-       my %users;
-       dbmopen %users,datafile($forum,"passwd"),0644;
-       if (!$users{$user}) {
-               show_error($forum,"Неизвестный пользователь $user");
-       }
-       my $record = thaw($users{$user});
-       %userinfo = %$record;
-       $userinfo{"user"} = $user;
+       %userinfo=%$user;
 } else {
        # Если не сказано, какой юзер, то текущий.
        %userinfo = %{$forum->{"authenticated"}}  
@@ -458,11 +467,27 @@ if (defined $user) {
        for my $element ( $tree->look_down("class",qr/^ap-/)) {
                my $field=$1 if $element->attr("class")=~/^ap-(.*)$/;   
                $element->delete_content();
-               $element->push_content(str2tree($userinfo{$field})) 
-                               if $userinfo{$field};
-               $element->attr(href=>"mailto:$userinfo{$field}") 
-                       if ($element->tag eq "a" && $field eq "email");
-       }
+               $field =~ tr/-/_/;
+               $userinfo{$field} = 0 if (!exists $userinfo{$field} && grep ($field eq
+                       $_,"forums","messages","topics"));
+               if (exists $userinfo{$field}) {
+                        
+                       my $data;
+                       if ($field eq "registered" || substr($field,0,5) eq "last_") {
+                       $data = strftime("%d.%m.%Y %H:%M",localtime($userinfo{$field}))
+                       } elsif ($field=~/^<\w+/) {
+                               $data = str2tree($userinfo{$field});
+                       } else {
+                               $data = $userinfo{$field}
+                       }
+                       $element->push_content($data);
+                       if (ref($data)) {
+                               $data->delete;
+                       }       
+                       $element->attr(href=>"mailto:$userinfo{$field}") 
+                               if ($element->tag eq "a" && $field eq "email");
+               }       
+       } 
 
 
 }
@@ -574,6 +599,11 @@ sub authenticate {
        my $userinfo = thaw($userbase{$user}) ;
        dbmclose %userbase;
        #while (my ($key,$val)=each %$userinfo) { print STDERR "$key => '$val'\n";}
+       if (defined $forum->{denied_status} && $userinfo->{status} eq 
+               $forum->{denied_status}) {
+               set_error($forum,"Вход пользователя $user в систему заблокирован");
+               return undef;
+       }       
        if (crypt($password,$userinfo->{passwd}) eq $userinfo->{passwd}) {
                delete $userinfo->{"passwd"};
                $cgi->delete("password");
@@ -697,13 +727,24 @@ sub register {
                }       
                close $f;
                close $out;
-               $userinfo->{'avatar'}= $forum->{"userurl"}."/".$filename;
+               my ($w,$h) = imgsize($forum->{"userdir"}."/".$filename);
+               $userinfo->{'avatar'}= {src=>$forum->{"userurl"}."/".$filename,
+                       width=>$w,height=>$h};
                $cgi->delete("avatar");
                $cgi->delete("avatarfile");
        }
-       
+       my @restrict = split /\s*,\s*/, $forum->{restricted_user_info};
+       set_default_user_attrs($forum,$userinfo);
        foreach my $param       ($cgi->param) {
-               $userinfo->{$param} = $cgi->param($param);
+               next if  (grep $_ eq $param,@restrict);
+               next if $param =~ /_format$/;
+               if (defined $cgi->param("${param}_format")) {
+                       my $tree = input2tree($cgi,$forum,$param);
+                       $userinfo->{$param} = tree2str($tree);
+                       $tree->delete();
+               } else {
+                       $userinfo->{$param} = $cgi->param($param);
+               }
        }
        $userinfo->{registered} = time;
        if (exists $forum->{default_status}) {
@@ -712,9 +753,89 @@ sub register {
        print STDERR "stilllife forum: registering user $user\n";
        $userbase{$user} = freeze($userinfo);
        dbmclose %userbase;
-       newsession(undef,$forum,$user);
-       forum_redirect($cgi,$forum,$returnto) 
+       if (!defined $forum->{denied_status} || $userinfo->{status} ne
+               $forum->{denied_status}) { 
+               newsession(undef,$forum,$user);
+               forum_redirect($cgi,$forum,$returnto); 
+       } else {
+               # FIXME Email validation
+               # Email to admin
+               show_template("newuser",$cgi,$forum);
+       }
 }      
+
+sub set_default_user_attrs {
+       my ($forum,$userinfo) = @_;
+       while (my($key,$val) = each %$forum) {
+               next unless $key =~ /^default_(.*)$/;
+               $userinfo->{$1} = $val;
+       }       
+}
+
+sub show_user_page {
+       my ($cgi,$forum) = @_;
+       my $rights;
+       $rights=getrights($cgi,$forum) if ($forum->{authenticated}); 
+       my %base;
+       my $tree;
+       dbmopen %base,datafile($forum,"passwd"),0664;
+       if ($path_translated eq $forum->{userdir}) {
+         # показать список пользователей
+         $tree = gettemplate($forum,"userlist");
+         my $usertpl = $tree->look_down(class=>"userinfo");
+         my $userlist = $usertpl->parent;
+         $usertpl->detach;
+         for my $user (sort keys %base) {
+                       my $block = $usertpl->clone;
+                       $userlist->push_content($block);
+                       my $userinfo =thaw($base{$user});
+                       $userinfo->{"user"} = $user;
+                       substitute_user_info($block,$forum,$userinfo);
+                       profile_links($block,$user,$rights,$forum);
+         }             
+         $usertpl->delete;     
+       } else {
+               my $user = substr($path_translated,length($forum->{userdir})+1);
+               if (!$base{$user}) {
+                       print $cgi->header(-status=>"404 NOT FOUND");
+                       exit;
+               }
+               my $userinfo = thaw($base{$user});
+               $userinfo->{"user"} = $user;
+               $tree = gettemplate($forum,"user");
+               substinfo($tree,[_tag=>"title"],_content=>"Stilllife user: $user");
+               substitute_user_info($tree,$forum,$userinfo);
+               profile_links($tree,$user,$rights,$forum);
+               unless ($userinfo->{openiduser}) {
+                       for my $userlink ($tree->look_down(_tag => "a",class=>"author")) {
+                               $userlink->attr("href",undef);
+                               $userlink->tag("span");
+                       }       
+               }
+       }       
+       my $page = 
+       $tree->as_HTML("<>&");
+       my $length = do {use bytes; length($page);};
+       print $cgi->header(-type=>"text/html",-content_length=>$length,
+       -charset=>"utf-8",($forum->{cookies}?(-cookie=>$forum->{cookies}):())),
+       $page;
+}
+sub profile_links {
+       my ($tree,$user,$rights,$forum)=@_;
+       foreach my $profile_link ($tree->look_down(_tag=>"a",
+                       href=>qr/profile=/)) {
+               if ((defined $rights && $rights eq "admin")|| 
+                       (defined $forum->{autheticated}{user} &&
+                        $forum->{authenticated}{user} eq $user)) {
+
+                               $profile_link->attr("href",
+                                       $cgi->url(-absolute=>1,-path_info=>0).$forum->{userurl}.
+                                       "/".$user."?profile=1");
+               } else {        
+                       $profile_link->delete();
+               }       
+       }       
+}
 sub clear_user_cookies {
        my ($cgi,$forum) = @_;
        $forum->{cookies}=[ $cgi->cookie(-name=>"sluser", -value=>"0",
@@ -919,7 +1040,7 @@ sub new_topic {
                form_error($form,$cgi,$forum,"Тема с urlname $urlname уже
                существует");
        }       
-       my $url = $cgi->url(-absolute=>1,-path_info=>1)."/$urlname.html";
+       my $url = $cgi->path_info."/$urlname.html";
                $url =~ s/\/+/\//g;
        if (!$cgi->param("title")) {
                form_error($form,$cgi,$forum,"Тема должна иметь непустое название");
@@ -1202,7 +1323,7 @@ sub savetree {
 
 sub gettemplate {
        my ($forum, $template,$url) = @_;
-       $url =~ s/\/+/\//g;
+       $url =~ s/\/+/\//g if defined $url;
        my $filename=$forum->{"templates"}."/$template.html";
        if (! -r $filename) {
                show_error($forum,"Нет шаблона $template");
@@ -1303,12 +1424,20 @@ sub openid_verify {
                                delete $info{'avatar'}{'type'};
                        }       
                        $info{"openiduser"}=1;
+                       $info{"registered"}=time; 
+                       print STDERR "forum $forum info ".\%info."\n";
+                       set_default_user_attrs($forum,\%info);
+                       $info{'status'} = $forum->{openid_status} if $forum->{openid_status};
                        $forum->{authenticated}=\%info;
                        $userbase{$username} = freeze(\%info);
                } else {
                        $forum->{authenticated} = thaw ($userbase{$username});
                }
                dbmclose %userbase;
+               if (defined $forum->{denied_status} && 
+                       ($forum->{authenticated}{status} eq $forum->{denied_status})) {
+                       show_error($forum,"Вход пользователя $username в систему заблокирован"); 
+               }       
                $forum->{"authenticated"}{"user"} = $username;
                newsession(undef,$forum,$user);
                # Если указан параметр reply, вызываем обработку реплики