From 5618c77b777ac650fea4a83610003746dd857ee3 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 10 Feb 2015 02:06:06 +0100 Subject: [PATCH] auth command --- ...mand.php.swp => .AuthLoginCommand.php.swp} | Bin 12288 -> 12288 bytes src/Console/Command/AuthLoginCommand.php | 67 ++++++++++++++++++ 2 files changed, 67 insertions(+) rename src/Console/Command/{.AuthCommand.php.swp => .AuthLoginCommand.php.swp} (79%) create mode 100644 src/Console/Command/AuthLoginCommand.php diff --git a/src/Console/Command/.AuthCommand.php.swp b/src/Console/Command/.AuthLoginCommand.php.swp similarity index 79% rename from src/Console/Command/.AuthCommand.php.swp rename to src/Console/Command/.AuthLoginCommand.php.swp index 7fd81e8736bbda85511d99fb9a8ac61deda606d4..7e576d69a3d9b5f88c9795750c0dc91dbe879128 100644 GIT binary patch literal 12288 zcmeI2&u`pB6vroAfR+LRfw+LC=|=XV{gKi_QL^1CB#{VeX{EMErKzfkJ)0fHJGRDS zHcJUykoX&V;f4ek_zQX}HxLpMAb|=OZisRMBoGI_Gxl!nO+wD7GtwvajNd%ZeBbkn zqRhtp8*At2sn$t?_BbI=U-|yhJFgs?`S2-1QZb0789$&&u_ZJ+zzC1uwGP`!wh@Wo zdS4Hs_Ha0CE1tw{ee(G6W)RCXj(9s&L3_ElUycU@Cd2kpru%2(O(BbcR?<%nex|vk1)Ks-0jGddz$xGqa0)mDoB~b(r+`zyDeym3fQ5t{evpt8 z4`K26|Nr>!|Gyt2pQm_JA;5qOt`14Uheg|KJFTgEu6KsKb@I0u4AC3_6 z4fq%&-~u=gX2Cy?5b`tF0Rp@Uu7G3UkHhc}?trhr=ioMYAFP5E@DjLth>%~wZEzF3 z2A%=GJWR-U;9GDDd4USYev^^{d76YmL2UXCnNMx#sB}Gd+gWjCLARijDk=>l%(h z_QdAdn1x(5yD58%`-NG>?p_4OTTxtRN-mO$nR&RE8fLt@;Z+lzv=w!Ow~eWQ0J;Q!iKyNPrYlq#h&tFJi(rrYq@!s`kdz3pD7yv+C%107Aelc z5#`$=)oF{a#B>yAbjYNpIyN)xD$Y=U)Rqkz@*c|~y+B8Gs7%UlF!$qNR31#WGOhi@ z%BEKJ)69FTc2!d;R-_cXNj{``z4A*k6zO5!ru!nbsrM?660ReWSaYH5>RlSo%XvNj zc&a&t+QhY4v_ESC*AcQ8cjwGEj04*(^VQ6C+IEo6mbPwUV5hF|G*H4;aNo--1!}oD z3GP)3khOjt{(M_F7w}yPS+cPb+Cc5Q?QvF_+IE8k5k5mYeWV=urMV1KS{yOQq1lwv zr9`af@msvtFDagnUK|a2u^g>qDt?2YqT$XSW;Y{7kMZ>&^E?3SQ*k(GmW}3mHKzDI TU}BIaCcaav!L!a8bAtX~>KBQl delta 419 zcmZojXh;xEG6?hZRWR2xVE_UF28NHmH$!SCiq7D6&d<$F%uCTL$SBy%$YRL6`6aVD z52NO0L4nWwyn5UW4DWy#q(gJEpn`I}Gd}}^A`r_1@gF`0hHpUp0*H?Q@iZWg2I5d4 z4gq3TApXzGz;GFeF9GpVAT9>tC?GZg;(I&{42OYuH4x7L;$|Q&0pemH4h3R$AXWon zJ|JcQ;&0px+zcO}PI}7?bglvSWMd7v$-6bRC$H2JoGhjz$ElK>pI4HZSDHFGR7b_X zq^LBNK>-bD>RsetName('auth:login') + ->setDescription('Login on t411') + ->setHelp("The %command.name% "); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $configLoader = new ConfigLoader(); + $dialog = $this->getHelperSet()->get('dialog'); + $client = new Client(); + + if ($configLoader->configExists()) { + $continue = $dialog->ask( + $output, + 'The configuration file already exists. Do you want to continue? (y/n, default: y) ', + 'y' + ); + + if (!in_array($continue, ['y', 'yes'])) { + $output->writeln('Aborded.'); + + return; + } + } + + $username = $dialog->ask($output, 'Username: ', null); + $password = $dialog->ask($output, 'Password: ', null); + + try { + $response = $client->getAuthorization($username, $password); + + if ($response->hasError()) { + $output->writeln(sprintf( + 'Login failed: %s (%d)', + $response->getErrorMessage(), + $response->getErrorCode() + )); + + return; + } + + $configLoader->save(array( + 'auth' => array( + 'uid' => $response->getData()['uid'], + 'token' => $response->getData()['token'], + ) + )); + } catch (ClientException $e) { + $output->writeln(sprintf('An error occured. %s', $e->getMessage())); + } + } +}