소스 검색

fix more bugs with useradd code

George Baugh 2 년 전
부모
커밋
50609de02a
2개의 변경된 파일26개의 추가작업 그리고 3개의 파일을 삭제
  1. 22 2
      bin/tcms-useradd
  2. 4 1
      lib/Trog/DataModule.pm

+ 22 - 2
bin/tcms-useradd

@@ -8,8 +8,11 @@ use warnings;
 use FindBin::libs;
 use Getopt::Long;
 use Pod::Usage;
+use List::Util qw{first};
 
 use Trog::Auth;
+use Trog::Data;
+use Trog::Config;
 
 =head1 SYNOPSIS
 
@@ -70,8 +73,25 @@ sub main {
     $options{acl} = [$options{acl}] if $options{acl} && ref $options{acl} ne 'ARRAY';
     $options{acl} = ['admin'] unless @{$options{acl}};
 
-    Trog::Auth::killsession($options{user});
-    Trog::Auth::useradd( $options{user}, $options{display_name}, $options{password}, $options{acl}, $options{contactemail} );
+    #Trog::Auth::killsession($options{user});
+    #Trog::Auth::useradd( $options{user}, $options{display_name}, $options{password}, $options{acl}, $options{contact_email} );
+
+    # Find the user's post and edit it
+    my $conf = Trog::Config::get();
+    my $data = Trog::Data->new($conf);
+
+    my @userposts = $data->get( tags => ['about'], acls => [qw{admin}]);
+    my $user_obj = first { ($_->{user} || '') eq $options{user} } @userposts;
+    my %merged = (
+        %$user_obj,
+        %options,
+    );
+    # We don't want the password in plain text
+    delete $merged{password};
+    # The ACLs a user posesses is not necessarily what ACLs you need to view a user's profile.
+    delete $merged{acl};
+
+    $data->add(\%merged);
     return 0;
 }
 

+ 4 - 1
lib/Trog/DataModule.pm

@@ -10,6 +10,9 @@ use Mojo::File;
 use Plack::MIME;
 use Path::Tiny();
 
+use Trog::Utils;
+use Trog::Auth();
+
 no warnings 'experimental';
 use feature qw{signatures};
 
@@ -110,7 +113,7 @@ sub _fixup ( $self, @filtered ) {
 
             #XXX this needs to be correctly populated in the form?
             if ($is_user_page) {
-                my $display_name = $subj->{display_name} || Trog::Auth::username2display( $subj->{user} );
+                my $display_name = $subj->{display_name} || Trog::Auth::username2display( $subj->{user} ) || $subj->{title};
                 die "No display name for user!" unless $display_name;
                 $subj->{local_href} = "/users/$display_name";
             }