changeset 233:3cebcf6fdb9b

refactoring, cleaning code
author sergey
date Thu, 11 Oct 2012 04:53:08 +0400
parents 5c82eec23bb6
children 2530d1bb9638
files Lib/IMPL/Web/Application.pm Lib/IMPL/Web/Handler/ErrorHandler.pm Lib/IMPL/Web/Handler/JSONView.pm Lib/IMPL/Web/Handler/RestController.pm Lib/IMPL/Web/Handler/SecureCookie.pm Lib/IMPL/Web/Handler/TTView.pm Lib/IMPL/Web/Handler/ViewSelector.pm Lib/IMPL/Web/Security.pm
diffstat 8 files changed, 109 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application.pm	Tue Oct 09 20:12:47 2012 +0400
+++ b/Lib/IMPL/Web/Application.pm	Thu Oct 11 04:53:08 2012 +0400
@@ -2,9 +2,9 @@
 use strict;
 use warnings;
 
-use IMPL::lang qw(:declare :constants);
 use CGI;
 use Carp qw(carp);
+use IMPL::Const qw(:prop);
 
 use IMPL::declare {
 	require => {
@@ -20,12 +20,12 @@
 		'IMPL::Object::Singleton' => '@_'
 	  ],
 	  props => [
-		actionFactory      => PROP_ALL,
-		handlers           => PROP_ALL | PROP_LIST,
-		security           => PROP_ALL,
-		options            => PROP_ALL,
-		fetchRequestMethod => PROP_ALL,
-		output             => PROP_ALL
+		actionFactory      => PROP_RW,
+		handlers           => PROP_RW | PROP_LIST,
+		security           => PROP_RW,
+		options            => PROP_RW,
+		fetchRequestMethod => PROP_RW,
+		output             => PROP_RW
 	  ]
 };
 
--- a/Lib/IMPL/Web/Handler/ErrorHandler.pm	Tue Oct 09 20:12:47 2012 +0400
+++ b/Lib/IMPL/Web/Handler/ErrorHandler.pm	Thu Oct 11 04:53:08 2012 +0400
@@ -1,7 +1,7 @@
 package IMPL::Web::Handler::ErrorHandler;
 use strict;
 
-use IMPL::lang qw(:declare :constants is);
+use IMPL::Const qw(:prop);
 use IMPL::Exception();
 use IMPL::declare {
 	require => {
@@ -14,16 +14,15 @@
 		'IMPL::Object' => undef,
 		'IMPL::Object::Autofill' => '@_',
 		'IMPL::Object::Serializable' => undef
-	}
+	},
+	props => [
+        errors => PROP_RW,
+        loader => PROP_RW,
+        fallback => PROP_RW,
+        contentType => PROP_RW
+	]
 };
 
-BEGIN {
-	public property errors => PROP_ALL;
-	public property loader => PROP_ALL;
-	public property fallback => PROP_ALL;
-	public property contentType => PROP_ALL;
-}
-
 sub CTOR {
 	my ($this) = @_;
 	
--- a/Lib/IMPL/Web/Handler/JSONView.pm	Tue Oct 09 20:12:47 2012 +0400
+++ b/Lib/IMPL/Web/Handler/JSONView.pm	Thu Oct 11 04:53:08 2012 +0400
@@ -2,13 +2,15 @@
 use strict;
 use JSON;
 
-use IMPL::lang qw(:declare :constants);
 use IMPL::declare {
-	base => {
+    require => {
+        HttpResponse => 'IMPL::Web::HttpResponse'        
+    },
+	base => [
 		'IMPL::Object' => undef,
 		'IMPL::Object::Serializable' => undef,
 		'IMPL::Object::Autofill' => '@_'
-	}
+	]
 };
 
 sub contentType {
@@ -23,9 +25,11 @@
 	
 	$action->response->contentType($this->contentType);
     
-    my $hout = $action->response->streamBody;
-    
-    print $hout JSON->new->utf8->pretty->encode($result);
+    return HttpResponse->new({
+        type => $this->contentType,
+        charset => 'utf-8',             
+        body => JSON->new->utf8->pretty->encode($result)
+    });
 }
 
 1;
--- a/Lib/IMPL/Web/Handler/RestController.pm	Tue Oct 09 20:12:47 2012 +0400
+++ b/Lib/IMPL/Web/Handler/RestController.pm	Thu Oct 11 04:53:08 2012 +0400
@@ -1,7 +1,7 @@
 package IMPL::Web::Handler::RestController;
 use strict;
 
-use IMPL::lang qw(:declare :constants);
+use IMPL::Const qw(:prop);
 use IMPL::declare {
 	require => {
 	    ResourceInterface => 'IMPL::Web::Application::ResourceInterface', 
@@ -15,8 +15,8 @@
 		'IMPL::Object::Serializable' => undef
 	},
 	props => [
-	   rootResource => PROP_GET | PROP_OWNERSET,
-	   trailingSlash => PROP_GET | PROP_OWNERSET
+	   rootResource => PROP_RO,
+	   trailingSlash => PROP_RO
 	]	
 };
 
--- a/Lib/IMPL/Web/Handler/SecureCookie.pm	Tue Oct 09 20:12:47 2012 +0400
+++ b/Lib/IMPL/Web/Handler/SecureCookie.pm	Thu Oct 11 04:53:08 2012 +0400
@@ -95,7 +95,7 @@
     my $context = $this->$manager->CreateSession(
         sessionId => $sid,
         principal => $user,
-        auth => AuthSimple->new(password => $cookie),
+        auth => AuthSimple->Create(password => $cookie),
         authority => $this,
         assignedRoles => $roles
     );
@@ -152,6 +152,11 @@
 
 Скаляр, использующийся для подписи данных.
 
+=head2 C<[get,set] manager>
+
+Реализация менеджера безопасности, отвечающая за реализацию взаимодействия с
+моделью безопасности. 
+
 =head2 C<InitSession($user,$auth,$roles)>
 
 =cut
--- a/Lib/IMPL/Web/Handler/TTView.pm	Tue Oct 09 20:12:47 2012 +0400
+++ b/Lib/IMPL/Web/Handler/TTView.pm	Thu Oct 11 04:53:08 2012 +0400
@@ -2,7 +2,7 @@
 use strict;
 
 use List::Util qw(first);
-use IMPL::lang qw(:declare :constants);
+use IMPL::Const qw(:prop);
 use IMPL::declare {
     require => {
         Factory      => 'IMPL::Object::Factory',
@@ -15,14 +15,14 @@
       ],
 
       props => [
-        contentType     => PROP_GET | PROP_OWNERSET,
-        contentCharset  => PROP_GET | PROP_OWNERSET,
-        loader          => PROP_GET | PROP_OWNERSET,
-        selectors       => PROP_GET | PROP_LIST | PROP_OWNERSET,
-        defaultDocument => PROP_ALL,
-        indexResource   => PROP_ALL,
-        _selectorsCache => PROP_ALL,
-        _classTemplates => PROP_ALL
+        contentType     => PROP_RO,
+        contentCharset  => PROP_RO,
+        loader          => PROP_RO,
+        selectors       => PROP_RO | PROP_LIST,
+        defaultDocument => PROP_RW,
+        indexResource   => PROP_RW,
+        _selectorsCache => PROP_RW,
+        _classTemplates => PROP_RW
       ]
 };
 
--- a/Lib/IMPL/Web/Handler/ViewSelector.pm	Tue Oct 09 20:12:47 2012 +0400
+++ b/Lib/IMPL/Web/Handler/ViewSelector.pm	Thu Oct 11 04:53:08 2012 +0400
@@ -1,7 +1,7 @@
 package IMPL::Web::Handler::ViewSelector;
 use strict;
 
-use IMPL::lang qw(:declare :constants);
+use IMPL::Const qw(:prop);
 
 use IMPL::declare {
     require => {
@@ -14,9 +14,9 @@
         'IMPL::Object::Serializable' => undef
       ],
       props => [
-        views    => PROP_ALL | PROP_LIST,
-        fallback => PROP_ALL,
-        types    => PROP_ALL
+        views    => PROP_RW | PROP_LIST,
+        fallback => PROP_RW,
+        types    => PROP_RW
       ]
 };
 
--- a/Lib/IMPL/Web/Security.pm	Tue Oct 09 20:12:47 2012 +0400
+++ b/Lib/IMPL/Web/Security.pm	Thu Oct 11 04:53:08 2012 +0400
@@ -10,11 +10,20 @@
     },
 };
 
+use constant {
+    ERR_NO_SUCH_USER => -1,
+    ERR_NO_SEC_DATA => -2,
+    ERR_AUTH_FAIL => -3
+};
+
 sub AuthUser {
     my ($this,$name,$package,$challenge) = @_;
     
     my $user = $this->FindUserByName($name)
-        or return { status => AUTH_FAIL, answer => "Can't find a user '$name'" };
+        or return {
+            status => AUTH_FAIL,
+            code => ERR_NO_SUCH_USER
+        };
     
     my $auth;
     if ( my $secData = $user->GetSecData($package) ) {
@@ -22,6 +31,7 @@
     } else {
         return {
             status => AUTH_FAIL,
+            code => ERR_NO_SEC_DATA,
             user => $user
         };
     }
@@ -34,6 +44,7 @@
     
     return {
         status => $status,
+        code => ($status == AUTH_FAIL ? ERR_AUTH_FAIL : 0),
         user => $user
     };
 }
@@ -93,4 +104,54 @@
 
 =head1 MEMBERS
 
+=head2 C<AuthUser($name,$package,$challenge)>
+
+Инициирует создание новой сессии используя провайдера безопасности текущего
+контекста безопасности.
+
+=over
+
+=item C<$name>
+
+Имя пользователя, которое будет использоваться при поиске его в БД. 
+
+=item C<$package>
+
+Имя модуля аутентификации, например, C<IMPL::Security::Auth::Simple>.
+
+=item C<$challenge>
+
+Данные, полученные от клиента, которые будут переданы модулю аутентификации для
+начала процесса аутентификации и создания сессии.
+
+=back
+
+Функция возвращает хеш с элементами
+
+=over
+
+=item C<status>
+
+Статус аутентификации - отражает общее состояние процесса ацтентификации,
+
+=over
+
+=item C<AUTH_FAIL>
+
+Аутентификация неудачная, сессия не создана.
+
+=item C<AUTH_INCOMPLETE>
+
+Аутентификация требует дополнительных шагов, сессия создана, но еще не доверена.
+
+=item C<AUTH_SUCCESS>
+
+Аутентификация успешно проведена, сессия создана.
+
+=back
+
+=item C<code>
+
+=back
+
 =cut