зеркало из https://github.com/mozilla/gecko-dev.git
Implemented logout and explicit new account creation in the login service. Had to add removeObject() to the Controller module (the opposite of the exisiting addObject()).
This commit is contained in:
Родитель
9b4ac10992
Коммит
004b78a163
|
@ -89,6 +89,17 @@ sub addObject {
|
|||
}
|
||||
}
|
||||
|
||||
sub removeObject {
|
||||
my $self = shift;
|
||||
foreach my $object (@_) {
|
||||
foreach my $index (0..$#{$self->objects}) {
|
||||
if ($self->objects->[$index] == $object) {
|
||||
delete($self->objects->[$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub getService {
|
||||
my $self = shift;
|
||||
my($name) = @_;
|
||||
|
|
|
@ -337,7 +337,7 @@ sub setupInstall {
|
|||
# +-------------------+
|
||||
# | userID K1 | auto_increment
|
||||
# | password |
|
||||
# | mode | active, disabled, logging out, etc
|
||||
# | mode | 0 = active, 1 = logging out, 2 = account disabled
|
||||
# | adminMessage | string displayed when user (tries to) log in
|
||||
# | newFieldID | \
|
||||
# | newFieldValue | > used when user tries to change his e-mail
|
||||
|
|
|
@ -59,10 +59,11 @@ sub verifyInput {
|
|||
# now let's see what that gave us
|
||||
if (@result) {
|
||||
# horrah, somebody knew what to do!
|
||||
if (defined($result[0])) {
|
||||
if ((defined($result[0])) and ($result[0]->checkLogin())) {
|
||||
$app->addObject($result[0]); # they will have returned a user object
|
||||
} else {
|
||||
# hmm, so apparently user is not authentic
|
||||
$self->errorState(\@result);
|
||||
return $self; # supports user.login (reportInputVerificationError)
|
||||
}
|
||||
}
|
||||
|
@ -84,12 +85,37 @@ sub authenticateUser {
|
|||
sub reportInputVerificationError {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
$app->output->loginFailed(1); # 1 means 'unknown username/password'
|
||||
my $message = '';
|
||||
if (defined($self->errorState) and defined($self->errorState->[0])) {
|
||||
$message = $self->errorState->[0]->adminMessage;
|
||||
}
|
||||
$self->errorState(undef);
|
||||
$app->output->loginFailed(1, $message); # 1 means 'unknown username/password'
|
||||
}
|
||||
|
||||
# cmdSendPassword could also be called 'cmdNewUser'
|
||||
# dispatcher.commands
|
||||
sub cmdSendPassword {
|
||||
sub cmdLoginRequestAccount {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
$app->output->loginRequestAccount();
|
||||
}
|
||||
|
||||
# dispatcher.commands
|
||||
sub cmdLoginLogout {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
# mark the user as logged out and then return to the main index page
|
||||
my $user = $app->getObject('user');
|
||||
if (defined($user)) {
|
||||
$user->logout();
|
||||
$app->removeObject($user);
|
||||
}
|
||||
$app->noCommand();
|
||||
}
|
||||
|
||||
# cmdLoginSendPassword could also be called 'cmdLoginNewUser'
|
||||
# dispatcher.commands
|
||||
sub cmdLoginSendPassword {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
my $protocol = $app->input->getArgument('protocol');
|
||||
|
@ -102,13 +128,13 @@ sub cmdSendPassword {
|
|||
} else {
|
||||
($user, $password) = $self->createUser($app, $protocol, $address);
|
||||
if (not defined($user)) {
|
||||
$app->output->loginFailed(2); # 2 means 'invalid protocol/username'
|
||||
$app->output->loginFailed(2, ''); # 2 means 'invalid protocol/username'
|
||||
return;
|
||||
}
|
||||
}
|
||||
$self->sendPassword($app, $user, $protocol, $password);
|
||||
} else {
|
||||
$app->output->loginFailed(0); # 0 means 'no username/password'
|
||||
$app->output->loginFailed(0, ''); # 0 means 'no username/password'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +167,7 @@ sub requireLogin {
|
|||
my($user, $password) = $self->createUser($app, $app->input->protocol, $address);
|
||||
$self->sendPassword($app, $user, $app->input->protocol, $password);
|
||||
} else {
|
||||
$app->output->loginFailed(0);
|
||||
$app->output->loginFailed(0, '');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,10 +183,20 @@ sub outputLoginInsufficient {
|
|||
# dispatcher.output.generic
|
||||
sub outputLoginFailed {
|
||||
my $self = shift;
|
||||
my($app, $output, $tried) = @_;
|
||||
my($app, $output, $tried, $message) = @_;
|
||||
$output->output('login.failed', {
|
||||
'tried' => $tried, # 0 = no username; 1 = unknown username; 2 = invalid username
|
||||
'contacts' => [$app->getService('dataSource.user')->getFieldNamesByCategory($app, 'contact')],
|
||||
'message' => $message,
|
||||
});
|
||||
}
|
||||
|
||||
# dispatcher.output.generic
|
||||
sub outputLoginRequestAccount {
|
||||
my $self = shift;
|
||||
my($app, $output, $tried) = @_;
|
||||
$output->output('login.requestAccount', {
|
||||
'contacts' => [$app->getService('dataSource.user')->getFieldNamesByCategory($app, 'contact')],
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -187,10 +223,11 @@ sub outputLoginDetails {
|
|||
# dispatcher.output
|
||||
sub strings {
|
||||
return (
|
||||
'login.accessDenied' => 'Displayed when the user does not have the requisite right (namely, data.right)',
|
||||
'login.failed' => 'Displayed when the user has not logged in (data.tried is false) or when the credentials were wrong (data.tried is true)',
|
||||
'login.detailsSent' => 'The password was sent to data.address using data.protocol',
|
||||
'login.details' => 'The message containing the data.username and data.password of a new account or when the user has forgotten his password (only required for contact protocols, e.g. e-mail)',
|
||||
'login.accessDenied' => 'Displayed when the user does not have the requisite right (namely, data.right).',
|
||||
'login.failed' => 'Displayed when the user has not logged in (data.tried is false) or when the credentials were wrong (data.tried is true). A message may be given in data.message.',
|
||||
'login.requestAccount' => 'Displayed when the user requests the form to enter a new account (should display the same form as login.failed, basically).',
|
||||
'login.detailsSent' => 'The password was sent to data.address using data.protocol.',
|
||||
'login.details' => 'The message containing the data.username and data.password of a new account or when the user has forgotten his password (only required for contact protocols, e.g. e-mail).',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ sub objectInit {
|
|||
$self->{'_DIRTY'} = {}; # make sure propertySet is happy
|
||||
$self->SUPER::objectInit(@_);
|
||||
$self->userID($userID);
|
||||
$self->mode($mode); # active (0), disabled (1), logging out (2) XXX need a way to make this extensible
|
||||
$self->mode($mode); # 0=active, 1=logging out, 2=disabled XXX need a way to make this extensible
|
||||
$self->password($password);
|
||||
$self->adminMessage($adminMessage);
|
||||
$self->newFieldID($newFieldID);
|
||||
|
@ -288,6 +288,24 @@ sub checkPassword {
|
|||
return $self->app->getService('service.passwords')->checkPassword($self->password, $password);
|
||||
}
|
||||
|
||||
sub logout {
|
||||
my $self = shift;
|
||||
if ($self->mode == 0) {
|
||||
$self->mode(1);
|
||||
}
|
||||
}
|
||||
|
||||
sub checkLogin {
|
||||
my $self = shift;
|
||||
# check to see if the account is disabled
|
||||
my $enabled = $self->mode == 0;
|
||||
# if user is logging out, clear flag
|
||||
if ($self->mode == 1) {
|
||||
$self->mode(0);
|
||||
}
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
sub joinGroup {
|
||||
my $self = shift;
|
||||
my($groupID, $level) = @_;
|
||||
|
|
Загрузка…
Ссылка в новой задаче