diff options
author | Buchan Milne <buchan@mageia.org> | 2010-11-04 11:59:43 +0000 |
---|---|---|
committer | Buchan Milne <buchan@mageia.org> | 2010-11-04 11:59:43 +0000 |
commit | f867429bab6efe18a21c4fd531ecbe4eff8cff40 (patch) | |
tree | 79950a5bc6548e151b149022def27119811accf4 /lib/CatDap/Controller/admin.pm | |
parent | 171bd5f8e175faa05549ff53ed43e134a5543354 (diff) | |
download | identity-f867429bab6efe18a21c4fd531ecbe4eff8cff40.tar identity-f867429bab6efe18a21c4fd531ecbe4eff8cff40.tar.gz identity-f867429bab6efe18a21c4fd531ecbe4eff8cff40.tar.bz2 identity-f867429bab6efe18a21c4fd531ecbe4eff8cff40.tar.xz identity-f867429bab6efe18a21c4fd531ecbe4eff8cff40.zip |
Switch to View::Email::Template for emails
Complete password reset by admin, and localise in user's preferredLanguage
Localise all /user content
Require re-entry of current password on password change
Clean up debugging
Diffstat (limited to 'lib/CatDap/Controller/admin.pm')
-rw-r--r-- | lib/CatDap/Controller/admin.pm | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/lib/CatDap/Controller/admin.pm b/lib/CatDap/Controller/admin.pm index 19fa15f..7632df4 100644 --- a/lib/CatDap/Controller/admin.pm +++ b/lib/CatDap/Controller/admin.pm @@ -48,11 +48,11 @@ sub auto : Private { my $mesg; my $dn; my $keyprefix = sprintf( "%02x%02x%02x", split /\./, $c->req->address ); - if ( !defined $c->user ) { + if ( !defined $c->user or not $c->req->cookie('key') ) { $c->detach('/user/login') if ( not $c->req->param('username') or not $c->req->param('password') ); - $c->log->info("No session, logging user in"); + $c->log->debug("No session, logging user in"); if ( !$c->authenticate( { @@ -67,7 +67,7 @@ sub auto : Private { #TODO: ppolicy .... $c->stash( errors => ['Incorrect username or password'] ); $c->stash( template => 'index.tt' ); - $c->log->info("Logging user in failed, forwarding to login page"); + $c->log->debug("Logging user in failed, forwarding to login page"); $c->visit('/user/login'); $c->detach; return 1; @@ -78,7 +78,7 @@ sub auto : Private { # $c->res->redirect('/user'); #} #$c->persist_user; - $c->log->info('Logging user in to LDAP'); + $c->log->debug('Logging user in to LDAP'); my $ug = Data::UUID->new; my $key = $ug->create_str(); $cipher = Crypt::CBC->new( @@ -103,7 +103,7 @@ sub auto : Private { -cipher => 'Blowfish' ) or die $!; $password = $cipher->decrypt( $c->session->{enc_password} ); - $c->log->info( "Re-authenticating user " . $c->session->{user} ); + $c->log->debug( "Re-authenticating user " . $c->session->{user} ); $c->authenticate( { username => $c->session->{user}, password => $password } ) or $c->view('/user/login'); @@ -126,7 +126,7 @@ sub account : Local { #my $attribute =~ m/^([\w\d]*)/,$c->req->param('attribute'); my $attribute = $c->req->param('attribute'); - $c->log->info("Searching for account using attribute $attribute"); + $c->log->debug("Searching for account using attribute $attribute"); #my $value =~ /^[\w\d]*/,$c->req->param('attribute'); my $value = $c->req->param('value'); @@ -180,13 +180,14 @@ sub account_promote : Local { $idpool->replace( uidNumber => $newuidnum ); $idpool->update; - $mesg = $entry->update or $c->log->info("LDAP update failed: $!"); + $mesg = $entry->update; if ($mesg->code) { + $c->log->info('LDAP update failed: ' . $mesg->error); push @errors, $mesg->error; #reverse idpool update $idpool->replace( uidNumber => $uidnum ); $mesg = $idpool->update; - $c->log->info("ERROR IdPool could not be reset to $uidnum"); + $c->log->info("ERROR IdPool could not be reset to $uidnum: ", $mesg->error) if $mesg->code; } } } @@ -221,7 +222,7 @@ sub account_modify : Local { my $attrdef; my $entry; - $c->log->info("Searching for user $user"); + $c->log->debug("Searching for user $user"); $mesg = $c->model('User')->search("(&(objectclass=inetOrgPerson)(uid=$user))"); $entry = $mesg->entry; @@ -241,7 +242,7 @@ sub account_modify : Local { next if $req !~ /(.+)_new/; my $attrname = $1; next if $params{ $attrname . '_new' } eq $params{ $attrname . '_old' }; - $c->log->info("Received update request for attribute $attrname"); + $c->log->debug("Received update request for attribute $attrname"); $update = 1; $attrdef = $schema->attribute($attrname) or die("getting schema failed: $!"); @@ -261,9 +262,9 @@ sub account_modify : Local { $mesg = $c->model('User')->search("(&(objectclass=inetOrgPerson)(uid=$user))"); - $c->log->info( $mesg->error ) if $mesg->code; + $c->log->debug( $mesg->error ) if $mesg->code; $entry = $mesg->entry; - $c->log->info( $mesg->error ) if $mesg->code; + $c->log->debug( $mesg->error ) if $mesg->code; my @values; my @attributes = $entry->attributes; @@ -421,9 +422,9 @@ sub account_addoc : Local { my $schema = $schemaldap->schema or die("Searching schema failed: $!"); $mesg = $c->model('user')->search("(&(objectclass=inetOrgPerson)(uid=$uid))"); - $c->log->info( $mesg->error ) if $mesg->code; + $c->log->debug( $mesg->error ) if $mesg->code; my $entry = $mesg->entry; - $c->log->info( $mesg->error ) if $mesg->code; + $c->log->debug( $mesg->error ) if $mesg->code; foreach my $attr ( $schema->must($objectclass) ) { push @must, $$attr{name} if not $entry->get_value( $$attr{name} ); @@ -439,14 +440,14 @@ sub account_addoc : Local { $entry->add( $addattr => $c->req->param($addattr) ); } else { - $c->log->info("Missing attribute $addattr"); + $c->log->debug("Missing attribute $addattr"); $haveall = 0; } } if ($haveall) { $entry->add( objectClass => [$objectclass] ); - $c->log->info("About to push updates to $dn"); - $c->log->info( Dumper( \$entry->changes ) ); + $c->log->debug("About to push updates to $dn"); + $c->log->debug( Dumper( \$entry->changes ) ); $mesg = $entry->update; push @errors, $mesg->error if $mesg->code; $c->stash( template => 'admin/account.tt', errors => @errors ); @@ -490,7 +491,7 @@ sub password : Local { $c->stash( uid => $uid, txnid => $txnid, mails => @mail); return 1; } - if ($c->req->param('txnid') != $c->session->{txnid}) { + if ($c->req->param('txnid') ne $c->session->{txnid}) { push @errors,'Transaction ID mismatch'; $c->detach; } @@ -501,13 +502,35 @@ sub password : Local { push @errors,"Password reset failed: " . $mesg->error; $c->detach; } - $c->stash->{email} = { - to => join ',',@mail, - subject => $c->config->{apptitle} . " - " . $c->loc('password reset'), - from => $c->config->{emailfrom}, - template => 'admin/password.tt', - }; - $c->forward( $c->view('Email::Template') ); + my $email = join(',',@mail); + # send the mail in the users preferred language + my @oldlang = $c->languages; + if ($entry->preferredLanguage) { + $c->log->debug("Setting languages to: " . Dumper($entry->preferredLanguage)); + $c->languages([$entry->preferredLanguage]); + } + $c->stash( + email => { + 'to' => $email, + 'subject' => $c->config->{apptitle} . " - " + . $c->loc('password reset'), + 'from' => $c->config->{emailfrom}, + 'template' => 'admin/password.tt', + 'content_type' => 'text/plain', + }, + entry => $entry, + url => $c->uri_for('/user/firstlogin') . "/?username=$uid&key=$newpass", + ); + $c->forward( $c->view('Email::Template') ); + $c->languages(@oldlang); + if ( @{ $c->error } ) { + my $errors = join "\n",@{ $c->error }; + $c->log->info("Sending reset mail to $email failed: $errors"); + $c->response->body($c->loc('An error occured sending the email, but your account was created. Please try the password recovery process f you entered the correct email address: [_1]', $errors)); + $c->error(0); # Reset the error condition if you need to + } + push @errors,$c->loc('Password reset and email sent'); + $c->res->redirect($c->uri_for('/admin/account_modify') . "/$uid"); } @@ -560,6 +583,8 @@ sub group_modify : Local { sub index : Path : Args(0) { my ( $self, $c ) = @_; + $c->detach('/index') if not $c->user; + $c->assert_user_roles('Account Admins'); $c->stash( pages => roles2pages( $c->user->roles ) ); #$c->response->body("Matched CatDap::Controller::admin in admin, roles $rolelist"); |