Tadashi Okoshi
slash****@users*****
2005年 12月 16日 (金) 18:04:32 JST
Index: affelio/lib/Affelio/Managing/SessionManager.pm
diff -u /dev/null affelio/lib/Affelio/Managing/SessionManager.pm:1.1
--- /dev/null Fri Dec 16 18:04:32 2005
+++ affelio/lib/Affelio/Managing/SessionManager.pm Fri Dec 16 18:04:32 2005
@@ -0,0 +1,115 @@
+# Copyright (C) 2005 FishGrove Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id: SessionManager.pm,v 1.1 2005/12/16 09:04:32 slash5234 Exp $
+
+package Affelio::Managing::SessionManager;
+{
+ use strict;
+ use lib("../../../extlib");
+ use Error qw(:try);
+ use CGI::Session;
+ use DBI;
+ use Jcode;
+ use lib("../../");
+ use Affelio::misc::CGIError;
+ use Affelio::misc::Debug qw(debug_print);
+
+ #######################################################################
+ #Constructor
+ #######################################################################
+ sub new{
+ my $class = shift;
+ my $af = shift;
+
+ debug_print("SessionManager::new: start.");
+ my $cgi = $af->{cgi};
+ my $sid = $cgi->cookie("affelio-$af->{user__nickname}");
+
+ my $session="";
+ if($sid){
+ $session = new CGI::Session(undef,
+ $sid,
+ {Directory=> $af->{site__session_dir}});
+ debug_print("SessionManager::new: Existing session: [" . $session->id . "]");
+ }
+ my $self = {af => $af,
+ ss => $session
+ };
+
+ bless $self, $class;
+
+ debug_print("SessionManager::new: end.");
+ return $self;
+ }
+
+ ######################################################################
+ #get_userclass
+ ######################################################################
+ sub get_userclass{
+ my $self = shift;
+ my $af = $self->{af};
+
+ if(!$self->{ss}) {return undef;}
+
+ return ($self->{ss}->param("type"));
+ }
+
+ ######################################################################
+ #get_session
+ ######################################################################
+ sub get_session{
+ my $self = shift;
+ return($self->{ss});
+ }
+
+ ######################################################################
+ #startup_session
+ ######################################################################
+ sub startup_session{
+ my $self = shift;
+ my $af = $self->{af};
+ #
+ my %param = @_;
+
+ $self->{ss} = new CGI::Session("driver:File",
+ undef,
+ {Directory=> $af->{site__session_dir}});
+
+ #Set values into session
+ $self->{ss}->param("user_afid", $param{user_afid});
+ $self->{ss}->param("user_nickname", $param{user_nickname});
+ $self->{ss}->param("type", $param{type});
+ #current time
+ #expire time
+ }
+
+ ######################################################################
+ #issue_cookie
+ ######################################################################
+ sub issue_cookie{
+ my $self = shift;
+ my $af = $self->{af};
+
+ my $cookie = $af->{cgi}->cookie(
+ -name => "affelio-$af->{user__nickname}",
+ -value => $self->{ss}->id(),
+ -path => URL2path($af->{site__web_root}));
+
+ return($cookie);
+ }
+}
+1;