« OpenInteract2/Manage/Website/InstallPackageStructure.pm
↑ Summary
OpenInteract2/FullTextIndexer.pm »
| 1 | package OpenInteract2::Manage::Website::CreateSuperuserPassword; | ||
| 2 | |||
| 3 | # $Id: CreateSuperuserPassword.pm,v 1.12 2005/03/18 04:09:50 lachoy Exp $ | ||
| 4 | |||
| 5 | 87 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 87 | ▶ | use base qw( OpenInteract2::Manage::Website ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 87 | ▶ | use OpenInteract2::Context qw( CTX ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 87 | ▶ | use OpenInteract2::Exception qw( oi_error ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 0 | ▶ | use SPOPS::Utility; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | $OpenInteract2::Manage::Website::CreateSuperuserPassword::VERSION = sprintf("%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/); | ||
| 12 | |||
| 13 | # METADATA | ||
| 14 | |||
| 15 | sub get_name { | ||
| 16 | return 'create_password'; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub get_brief_description { | ||
| 20 | return q{Change the superuser password. Disable this from working } . | ||
| 21 | q{by setting 'login.disable_superuser_password_change' to } . | ||
| 22 | q{a true value.}; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub get_parameters { | ||
| 26 | my ( $self ) = @_; | ||
| 27 | return { | ||
| 28 | password => { | ||
| 29 | description => "New password for superuser", | ||
| 30 | is_required => 'yes', | ||
| 31 | }, | ||
| 32 | website_dir => $self->_get_website_dir_param, | ||
| 33 | }; | ||
| 34 | } | ||
| 35 | |||
| 36 | # VALIDATE | ||
| 37 | |||
| 38 | sub validate_param { | ||
| 39 | my ( $self, $param_name, $value ) = @_; | ||
| 40 | if ( $param_name eq 'password' ) { | ||
| 41 | unless ( $value ) { | ||
| 42 | return ( "Parameter 'password' must be defined" ); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | return $self->SUPER::validate_param( $param_name, $value ); | ||
| 46 | } | ||
| 47 | |||
| 48 | # ensure we can actually set the password from here... | ||
| 49 | |||
| 50 | sub setup_task { | ||
| 51 | my ( $self ) = @_; | ||
| 52 | $self->SUPER::setup_task(); | ||
| 53 | my $login_config = CTX->lookup_login_config; | ||
| 54 | if ( $login_config->{disable_superuser_password_change} ) { | ||
| 55 | oi_error "Changing superuser password from management task ", | ||
| 56 | "is disabled. See administrator and/or docs for details."; | ||
| 57 | } | ||
| 58 | my $user_class = CTX->lookup_object( 'user' ); | ||
| 59 | if ( $user_class->isa( 'SPOPS::LDAP' ) ) { | ||
| 60 | oi_error "Sorry, you cannot change passwords for a user in an LDAP ", | ||
| 61 | "directory. Please use another tool to do change the password." | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | # RUN | ||
| 66 | |||
| 67 | sub run_task { | ||
| 68 | my ( $self ) = @_; | ||
| 69 | my $action = 'create password'; | ||
| 70 | |||
| 71 | my $password = $self->param( 'password' ); | ||
| 72 | my $root_id = CTX->lookup_default_object_id( 'superuser' ); | ||
| 73 | my $root = eval { | ||
| 74 | CTX->lookup_object( 'user' ) | ||
| 75 | ->fetch( $root_id, { skip_security => 1 } ) | ||
| 76 | }; | ||
| 77 | if ( $@ ) { | ||
| 78 | $self->_fail( $action, "Error fetching superuser: $@" ); | ||
| 79 | } | ||
| 80 | else { | ||
| 81 | my $set_password = ( CTX->lookup_login_config->{crypt_password} ) | ||
| 82 | ? SPOPS::Utility->crypt_it( $password ) | ||
| 83 | : $password; | ||
| 84 | $root->{password} = $set_password; | ||
| 85 | eval { $root->save({ skip_security => 1 }) }; | ||
| 86 | if ( $@ ) { | ||
| 87 | $self->_fail( $action, | ||
| 88 | "Error saving superuser with new password: $@" ); | ||
| 89 | } | ||
| 90 | else { | ||
| 91 | my $msg = join( '', | ||
| 92 | 'Changed password for superuser; you may wish to disable ', | ||
| 93 | 'further changes by setting the server configuration key ', | ||
| 94 | "'login.disable_superuser_password_change' to a true value" ); | ||
| 95 | $self->_ok( $action, $msg ); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | $self->notify_observers( progress => 'Password change complete' ); | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ ); | ||
| 103 | |||
| 104 | 1; | ||
| 105 | |||
| 106 | __END__ | ||