Files
dojo/lib/Dojo/Controller/Home.pm

139 lines
3.8 KiB
Perl
Raw Normal View History

2018-07-13 19:06:08 -05:00
package Dojo::Controller::Home;
use Mojo::Base 'Mojolicious::Controller';
2018-07-18 04:28:26 -05:00
use Mojo::Template;
2020-01-22 18:22:31 -06:00
use Dojo::Support qw{send_mail log get_names};
2019-03-28 04:06:59 -06:00
use JSON;
use Data::Dumper;
#=========================
2018-07-13 19:06:08 -05:00
sub tst{
my $c=shift;
2019-04-02 19:19:41 -06:00
if( defined($c->req->json) ){
my $oid = $c->req->json->{'orderID'} //0;
log( $oid );
#credentials====
my $client='AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7';
my $secter='EBn8CNOCrJbVZ_fNllXB7oUIm9_vhtqrJMm2zSBGbxSyiiych3cHOIWOLAD5NVw4Z3dmNhmsHQwPsrZ0';
my $pauth='https://api.sandbox.paypal.com/v1/oauth2/token/';
my $porder='https://api.sandbox.paypal.com/v2/checkout/orders/';
#=================
#pre auth ====
my $ua = LWP::UserAgent->new;
my $req=POST $pauth, ["grant_type"=>"client_credentials"];
$req->authorization_basic($client,$secter);
$req->content_type('application/x-www-form-urlencoded');
my $res=$ua->request($req);
log("paypal pre auth error! $res->status_line") unless ($res->is_success );
my $json = JSON->new->utf8;
my $r=$json->decode($res->decoded_content);
#==============
2019-03-28 04:06:59 -06:00
2019-04-02 19:19:41 -06:00
#order details ====
my $ub = LWP::UserAgent->new;
$ub->default_header('Content-Type'=> 'application/json' );
$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
my $resb=$ub->get($porder.$oid);
log("paypal checkout error!") unless ($resb->is_success );
my $jsonb = JSON->new->utf8;
my $s=$jsonb->decode($resb->decoded_content);
#===================
$c->rendered(200); #es default,nomas para enfatizar que puede ser 400 o 500
# interesan create time, id, payer: email address, shippng address
}
else{
2019-04-04 19:45:51 -06:00
my $data=$c->dbg->store_id($c->param('id'));
$c->redirect_to('store') unless ($data->{'id'});
$c->stash($data);
2019-04-02 19:19:41 -06:00
$c->stash(layout=>'default');
}
2019-03-28 04:06:59 -06:00
#$c->render(text=> $c->config->{radio}{'channel'});
2018-07-19 03:45:46 -05:00
2018-07-13 19:06:08 -05:00
}
2018-07-20 05:16:47 -05:00
# User ========================================================================
2019-03-14 03:19:54 -06:00
sub home_ {
my $c = shift;
$c->redirect_to("/home") ;
}
2018-07-27 16:45:29 -05:00
2019-03-14 03:19:54 -06:00
sub home {
my $c = shift;
2019-03-15 19:33:38 -06:00
# por hacer: par evitar la animacion del intro
# $c->stash(moda=>$c->req->headers->referrer );
2019-03-14 03:19:54 -06:00
$c->stash( $c->dbv->mod) ;
$c->stash(layout=>'default');
}
2018-07-13 19:06:08 -05:00
2019-03-14 03:19:54 -06:00
sub pang {
my $c = shift;
my $h=$c->dbv->pang_md;
map { $c->stash( $_ => $h->{$_}) } keys %$h;
$c->stash(layout=>'default');
}
2018-07-13 19:06:08 -05:00
2019-03-14 03:19:54 -06:00
sub contact{
my $c = shift;
if ($c->param("mup")){
$c->flash(mname => $c->param("mname"));
$c->dbv->contact(
$c->param("mname"),
$c->param("mail"),
$c->match->stack->[-1]{action},
$c->param("msg")
);
$c->redirect_to('contact2');
}else{
2019-03-12 19:20:30 -06:00
$c->stash(layout=>'default');
2018-07-20 05:16:47 -05:00
}
2019-03-14 03:19:54 -06:00
}
2018-07-13 19:06:08 -05:00
2019-03-14 03:19:54 -06:00
sub contact2{
my $c = shift;
$c->redirect_to("home") unless $c->flash('mname');
$c->stash( mname=>$c->flash('mname'));
$c->stash(layout=>'default');
}
2018-07-13 19:06:08 -05:00
2019-03-14 03:19:54 -06:00
sub tv{
my $c = shift;
$c->stash( videos=>$c->dbv->tv_videos, table=>$c->dbv->tv_series);
$c->stash(layout=> "defaultContact");
}
2018-07-13 19:06:08 -05:00
2019-03-14 03:19:54 -06:00
sub podcast{
my $c = shift;
$c->stash(layout=> "defaultContact");
$c->stash( t=>$c->dbv->podcast_txt, pod=>$c->dbv->podcast_infoHash);
}
sub bcast{
my $c = shift;
$c->stash(layout=> "defaultContact");
}
2018-07-27 16:45:29 -05:00
2020-01-15 23:42:58 -06:00
sub radio{
my $c=shift;
$c->stash(layout=> "defaultContact");
$c->stash($c->dbv->mod);
$c->stash(nick=>$c->session("nick"));
}
2020-05-27 15:28:41 -05:00
sub radiop{
my $c=shift;
$c->stash(layout=> "defaultContact");
$c->stash($c->dbv->mod);
$c->stash(nick=>$c->session("nick"));
}
2018-07-25 20:48:58 +00:00
2020-01-15 23:42:58 -06:00
sub candy{
my $c=shift;
$c->stash( css=>["/ext/candy/libs.min.css","/home/candy/default.css"]);
$c->stash( js=>["/home/candy/loader.js","/ext/candy/libs.min.js","/ext/candy/candy.min.js"]);
2018-07-25 20:48:58 +00:00
2020-01-15 23:42:58 -06:00
$c->stash(layout=> "clean");
$c->stash(nick=>$c->session("nick"));
}
2018-07-25 20:48:58 +00:00
2018-07-20 05:16:47 -05:00
#==============================================================================
2018-07-18 04:28:26 -05:00
2018-07-13 19:06:08 -05:00
1;