blib/lib/App/MatrixTool/Command/client/login.pm

filter: Statementstmt 48.5% 17 / 35 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 1 totaltotal 48.8% 22 / 45 SCAR 9.7
CC
2
Cov
46%
run
6.0
__ANON__
2.0
BEGIN
1.0
CRAP 2.6
« blib/lib/App/MatrixTool/Command/directory.pm ↑ Summary blib/lib/App/MatrixTool/SubCommands.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2016 -- leonerd@leonerd.org.uk
5  
6 package App::MatrixTool::Command::client::login;
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use base qw( App::MatrixTool::Command::client );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '0.06';
13  
14 1 ▶use constant DESCRIPTION => "Obtain a client authentication token";
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use constant ARGUMENTS => ( "user", "password?" );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 matrixtool client login - Obtain a client authentication token
20  
21 =head1 SYNOPSIS
22  
23 $ matrixtool client login @me:example.com
24  
25 =head1 DESCRIPTION
26  
27 This command performs the C</login> steps of the Matrix client API, obtaining
28 an access token for the given user ID. This requires a password - either
29 provided on the commandline as a second argument, or requested interactively
30 on the terminal.
31  
32 Once the access token is obtained it is stored in the token cache, which lives
33 in F<$HOME/.matrix/client-tokens>. This cache will be consulted by other
34 C<matrixtool client> sub-commands to automatically provide the access token if
35 required.
36  
37 Note that the interactive terminal method requires the optional dependency of
38 L<IO::Termios> to be installed, so that local echo can temporarily be disabled
39 while the user types in the password.
40  
41 =cut
42  
43 sub run
44 {
45 0 ▶ my $self = shift;
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
46 0 my ( $opts, $user, $password ) = @_;
47  
48 0 $self->{user_id} = $user;
49  
50 0 ▶ if( !defined $password ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $password) 0 0 0
51 0 require IO::Termios;
52 0 my $stdin = IO::Termios->new( \*STDIN );
53  
54 0 STDOUT->autoflush(1);
55 0 print "Password: ";
56  
57 0 $stdin->setflag_echo( 0 );
58 0 $password = <$stdin>; chomp $password; print "\n";
59 0 $stdin->setflag_echo( 1 );
60 }
61  
62 $self->do_json( POST => "/_matrix/client/r0/login",
63 content => {
64 type => "m.login.password",
65 user => $user,
66 password => $password,
67 }
68 )->then( sub {
69 0 ▶ my ( $body ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
70  
71 $self->client_token_store->put(
72 server => $self->{server},
73 id => $user,
74 data => $body->{access_token},
75 0 );
76  
77 0 $self->output_ok( "Obtained access token" );
78  
79 0 Future->done();
80 0 });
81 }
82  
83 =head1 AUTHOR
84  
85 Paul Evans <leonerd@leonerd.org.uk>
86  
87 =cut
88  
89 1 0x55AA;
« blib/lib/App/MatrixTool/Command/directory.pm ↑ Summary blib/lib/App/MatrixTool/SubCommands.pm »