Bladeren bron

fix bug with tcms-useradd not preserving totp

George Baugh 2 jaren geleden
bovenliggende
commit
d8901bc99b
4 gewijzigde bestanden met toevoegingen van 11 en 5 verwijderingen
  1. 5 1
      bin/tcms-useradd
  2. 3 2
      bin/totp
  3. 1 1
      lib/Trog/Auth.pm
  4. 2 1
      lib/Trog/DataModule.pm

+ 5 - 1
bin/tcms-useradd

@@ -77,7 +77,11 @@ sub main {
     $options{acl} = ['admin'] unless @{$options{acl}};
 
     Trog::Auth::killsession($options{user});
-    Trog::Auth::useradd( $options{user}, $options{display_name}, $options{password}, $options{acl}, $options{contact_email} );
+    eval {
+        Trog::Auth::useradd( $options{user}, $options{display_name}, $options{password}, $options{acl}, $options{contact_email} )
+    } or do {
+        return 1;
+    };
 
     # Find the user's post and edit it
     my $conf = Trog::Config::get();

+ 3 - 2
bin/totp

@@ -6,12 +6,13 @@ use warnings;
 use FindBin::libs;
 
 use Trog::Auth;
+use Trog::Config;
 
 my $user   = shift @ARGV;
-my $domain = shift @ARGV;
+my $domain = Trog::Config->get()->param('general.hostname');
 
 die "Must provide a user"   unless $user;
-die "Must provide a domain" unless $domain;
+die "Must Set domain in configuration file" unless $domain;
 
 my ( $uri, $qr, $failure, $message, $totp ) = Trog::Auth::totp($user,$domain);
 print "TOTP URI: $uri\n";

+ 1 - 1
lib/Trog/Auth.pm

@@ -299,7 +299,7 @@ sub useradd ( $user, $displayname, $pass, $acls, $contactemail ) {
         $salt = Trog::Utils::uuid();
         $hash = sha256( $pass . $salt );
     }
-    my $res  = $dbh->do( "INSERT OR REPLACE INTO user (name, display_name, salt,hash,contact_email, totp_secret) VALUES (?,?,?,?,?)", undef, $user, $displayname, $salt, $hash, $contactemail, $t_secret );
+    my $res  = $dbh->do( "INSERT OR REPLACE INTO user (name, display_name, salt, hash, contact_email, totp_secret) VALUES (?,?,?,?,?,?)", undef, $user, $displayname, $salt, $hash, $contactemail, $t_secret );
     return unless $res && ref $acls eq 'ARRAY';
 
     #XXX this is clearly not normalized with an ACL mapping table, will be an issue with large number of users

+ 2 - 1
lib/Trog/DataModule.pm

@@ -10,6 +10,7 @@ use Plack::MIME;
 use Path::Tiny();
 use Ref::Util();
 
+use Trog::Log qw{:all};
 use Trog::Utils;
 use Trog::Auth();
 
@@ -297,7 +298,7 @@ our %schema = (
 	'data' => $not_ref,
 	'version' => $not_ref,
 	'visibility' => $not_ref,
-	'aliases' => \&Ref::Util::Is_arrayref,
+	'aliases' => \&Ref::Util::is_arrayref,
 );
 
 sub add ( $self, @posts ) {