NAME

Egg::Model::Auth::Base - Base class for AUTH controller.

SYNOPSIS

package MyApp::Model::Auth::Hooo;
use base qw/ Egg::Model::Auth::Base /;

__PACKAGE__->config ( ....... );

__PACKAGE__->setup_plugin( ...... );

__PACKAGE__->setup_session( ...... );

__PACKAGE__->setup_api( ...... );

DESCRIPTION

It is a base class to succeed to from the AUTH controller who outputs it with Egg::Helper::Model::Auth.

METHODS

Egg::Base and Egg::Component have been succeeded to.

setup_plugin ([PLUGIN_LIST])

It is made to use by registering Plugin system module in @ISA of this class.

PLUGIN_LIST is a list of the name of Plugin system module. The part of 'Egg::Model::Auth::Plugin' is omitted and specified.

__PACKAGE__->setup_plugin(qw/ Keep /);

setup_session ([SESSION_NAME] => [COMP_LIST])

It is made to use by registering Session system module in @ISA of this class.

SESSION_NAME is a name of Session system module. The part of 'Egg::Model::Auth::Session' is omitted and specified.

__PACKAGE__->setup_session('SessionKit');

COMP_LIST is passed by the list if there is a component module that wants to register in addition. The name that omits the part of 'Egg::Model::Auth' is specified.

__PACKAGE__->setup_session( FileCache => qw/ Bind::Cookie /);

setup_api ([API_NAME] => [COMP_LIST])

It is made to use by registering API system module to API class.

__PACKAGE__->setup_api('DBI');

Additionally, COMP_LIST is a list of the module name that wants to be built into API class. The name that omits the part of 'Egg::Model::Auth' is specified.

__PACKAGE__->setup_api( File => qw/ Crypt::SHA1 /);

To use a different kind of API module at the same time, setup_api is described. two or more.

However, the same kind of API module cannot be used at the same time.

__PACKAGE__->setup_api('DBI');
__PACKAGE__->setup_api( File => qw/ Crypt::SHA1 / );

# And, the API_NAME is specified by 'login_check' method.
$e->model('auth::hooo')->login_check('dbi');

new

Constructor.

my $auth= $e->model('auth_label_name');

api ([API_NAME])

API object set by 'setup_api' method is returned.

API_NAME passes the name passed to 'setup_api' method.

When API_NAME is total abbreviated, API object that default and has been treated is returned.

my $api= $auth->api('File');

login_check ([API_NAME], [USER_ID], [PASSWORD])

The argument is passed to API object, the attestation check is done, and if it is correct, the mass of the attestation data is returned by the HASH reference. When the attestation session is begun, it is necessary to call this method.

API_NAME passes the name passed to 'setup_api' method. When API_NAME is total abbreviated, API object of default is used.

When USER_ID is omitted, the acquisition of form input data of 'id_param' is tried.

When PASSWORD is omitted, the acquisition of form input data of 'password_param' is tried.

if (my $user= $auth->login_check('File', $user_id, $password)) {
   ...... It was possible to log it in.
} else {
   ...... It is not possible to log it in.
}

# When you omit API.
if (my $user= $auth->login_check($user_id, $password)) {
   ......
} .....

# It shortens further if ID and the password are obtained from the input of the form.
if (my $user= $auth->login_check) {
   ......
} ....

The content of the error can be acquired in 'is_error' and 'error_message' though 0 is returned when the attestation doesn't pass.

if (my $user= $auth->login_check) {
   ......
} else {
   # The error message buried under the template is set.
   $e->stash->{error_message}= $auth->error_message;
}

The error message can be customized.

see Egg::Model::Auth.

is_login

The attestation of the session begun on 'login_check' method is returned.

The cross-check with API object of the interval set in 'interval' is done.

if ($auth->is_login) {
  ...... The screen etc. only for the member are displayed.
} else {
  return $e->finished(403);
}

logout

It logs out annulling the attestation session.

$auth->logout;
$e->stash->{logout_message}= 'Thank you for use.';

user_name

ID under the attestation is returned.

If 'is_login' method has not been called yet, 'is_login' is called.

if (my $user_name= $auth->user_name) {
   $e->stash->{message}= "Mr. ${user_name} hello.";
} else {
   return $e->finished(403);
}

group_check ([GROUP_NAME])

User's authority etc. under the attestation are checked.

Invalidity always returns if 'group_field' is not set by the configuration.

$e->stash->{group_name}= 
   $auth->group_check('SYSOP') ? 'Manager' : 'General';

remove_session

The attestation session is annulled and 'reset' method is called. In a word the same thing as 'logout' method is done.

As for 'logout' method, the point to always return an effective value is different though this method always returns an invalid value.

$auth->remove_session;

reset

Login in 'login_check' method is invalidated. However, the session is not annulled.

$auth->reset;

get_bind_id, set_bind_id, remove_bind_id

Nothing is done.

see Egg::Model::Auth::Bind::Cookie.

data

HASH to refer to the data acquired after it attests it is restored.

It doesn't become, and do not change inside data about this data leading only, please.

my $email= $auth->data->{email};

is_error

When failing in the attestation because of 'login_check' and 'is_login', the error code is returned.

error_message

When failing in the attestation because of 'login_check' and 'is_login', the error message is returned.

Please set 'error_messages' of the configuration to customize the error message.

see Egg::Model::Auth.

error ([ERROR_CODE])

ERROR_CODE is set in 'is_error' method, and the error message of correspondence is set in 'error_message' method. And, an invalid value is returned.

When the error message corresponding to passed ERROR_CODE is not obtained, 400 is set in is_error, and ERROR_CODE is set in 'error_message' method.

If 'is_error' has defined it, an invalid value has been returned without doing anything.

error_*

Besides, the method of returning the following error codes is prepared.

  • error_undefind_id = 100

  • error_invalid_id = 110

  • error_not_registered = 120

  • error_id_empty = 130

  • error_not_active = 140

  • error_undefind_password = 200

  • error_invalid_password = 210

  • error_password_empty = 220

  • error_mistake_password = 230

  • error_invalid_session = 300

  • error_innternal = 400

  • error_method_not_allowd = 500

  • error_forbidden = 510

SEE ALSO

Egg::Release, Egg::Model::Auth, Egg::Model::Auth::Base::API, Egg::Base, Egg::Component,

AUTHOR

Masatoshi Mizuno <lushe@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2008 Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.