Files
dojo/lib/Dojo/Controller/Home.pm
2019-03-28 04:06:59 -06:00

252 lines
6.7 KiB
Perl
Executable File

package Dojo::Controller::Home;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Template;
use Dojo::Support qw{ log get_names};
# estos son paypal=======:w
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;
use Data::Dumper;
#=========================
sub tst{
my $c=shift;
#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/2';
#=================
#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);
#==============
my $ub = LWP::UserAgent->new;
$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
my $resb=$ub->get($porder);
log("paypal checkout error!") unless ($resb->is_success );
my $jsonb = JSON->new->utf8;
my $s=$jsonb->decode($resb->decoded_content);
$c->stash(res=>" $r->{expires_in} $s->{name}");
$c->stash(layout=>'default');
#$c->render(text=> $c->config->{radio}{'channel'});
}
# User ========================================================================
sub home_ {
my $c = shift;
$c->redirect_to("/home") ;
}
sub home {
my $c = shift;
# por hacer: par evitar la animacion del intro
# $c->stash(moda=>$c->req->headers->referrer );
$c->stash( $c->dbv->mod) ;
$c->stash(layout=>'default');
}
sub pang {
my $c = shift;
my $h=$c->dbv->pang_md;
map { $c->stash( $_ => $h->{$_}) } keys %$h;
$c->stash(layout=>'default');
}
sub cal {
my $c = shift;
my $data=$c->dbv->calendar_events;
my $block=$c->dbv->calendar_monthblock;
my %h;
map{ push @{ $h{$_->{bid}} },$_; }(@$data);
$c->stash( r=>\%h, b=>$block);
$c->stash(layout=>'default');
}
sub event{
my $c = shift;
$c->stash($c->dbv->event($c->param("id")));
$c->stash(layout=> "defaultContact");
}
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{
$c->stash(layout=>'default');
}
}
sub contact2{
my $c = shift;
$c->redirect_to("home") unless $c->flash('mname');
$c->stash( mname=>$c->flash('mname'));
$c->stash(layout=>'default');
}
sub store{
my $c = shift;
$c->stash( r=>$c->dbv->store);
$c->stash(layout=> "defaultContact");
}
sub tv{
my $c = shift;
$c->stash( videos=>$c->dbv->tv_videos, table=>$c->dbv->tv_series);
$c->stash(layout=> "defaultContact");
}
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");
}
sub radio{
my $c=shift;
$c->stash(layout=> "defaultContact");
$c->stash($c->dbv->mod);
$c->stash(nick=>$c->session("nick"));
}
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"]);
$c->stash(layout=> "clean");
$c->stash(nick=>$c->session("nick"));
}
#==============================================================================
# Admin =======================================================================
sub admin{
my $c= shift;
$c->redirect_to('/admin/home');
}
sub admin_home{
my $c=shift;
$c->dbv->umod($c->param('link'),$c->param('update'))
if (($c->param("hup") // " " )=~/Cambiar/);
$c->stash(template=>"home/admin/home");
$c->stash(layout=>"admin");
$c->stash( $c->dbv->mod);
}
sub admin_radio{
my $c=shift;
$c->dbv->umod($c->param('link'),'rmod')
if (($c->param("hup") // " " )=~/Cambiar/);
$c->dbg->ugrulla_pass($c->param('gpass'))
if (($c->param("pup") // " " )=~/Cambiar/);
$c->stash($c->dbv->mod);
$c->stash($c->dbg->grulla_pass);
$c->stash(apend => ["home/admin/candySwitch"]);
$c->stash(template=>"home/admin/radio");
$c->stash(layout=>"admin");
}
sub admin_mensajes{
my $c=shift;
$c->stash( h=>$c->dbv->msg_heads);
$c->stash(template=>"home/admin/mensajes");
$c->stash(layout=>"admin");
}
sub admin_eventos{
my $c=shift;
if ( (my $t=$c->param('type') // "") =~/[ecp]/){
my $id=$c->param('id');
my $req=$c->param('req');
if ( $req eq "Eliminar"){
$c->dbv->event_del($id) if ($t eq 'e');
$c->dbv->course_del($id) if ($t eq 'c');
$c->dbv->place_del($id) if ($t eq 'p');
}
elsif( $req eq "Aceptar"){
if($t eq 'e'){
my @list=map{$c->param($_)}qw/eplace yini mini dini yend mend dend cost promo pen ecourse eimg een id/;
$c->dbv->event_up(@list) if ($id ==0);
$c->dbv->event_ch(@list) if ($id >0);
}
if($t eq 'c'){
my @list=map{$c->param($_)}qw/cname csubjects cservices cen id/;
$c->dbv->course_up(@list) if ($id ==0);
$c->dbv->course_ch(@list) if ($id >0);
}
if($t eq 'p'){
my @list=map{$c->param($_)}qw/pname paddr pobs pto pst pco plat plng pen id/;
$c->dbv->place_up(@list) if ($id ==0);
$c->dbv->place_ch(@list) if ($id >0);
}
}
$c->redirect_to("/admin/eventos");
}
$c->stash(
courses=>$c->dbv->courses,
places=>$c->dbv->places,
months=>$c->dbv->months,
events=>$c->dbv->events,
img=>$c->dbv->eimgList,
);
$c->stash(template=>"home/admin/event");
$c->stash(layout=>"admin");
}
sub admin_tienda{
my $c=shift;
$c->stash(u=>$c->dbv->user_heads);
$c->stash(s=>$c->dbv->store_heads);
$c->stash(template=>"home/admin/tienda");
$c->stash(layout=>"admin");
}
sub admin_json{
my $c=shift;
my $id = $c->param('id');
my $req = $c->param('dreq');
my $json = "304";
$json = $c->dbv->msg($id) if $req=~/mensaje/;
$json = $c->dbv->user($id) if $req=~/usuarios/;
$json = $c->dbv->astore($id) if $req=~/tienda/;
$json = $c->dbv->course($id) if $req=~/course/;
$json = $c->dbv->place($id) if $req=~/place/;
$json = $c->dbv->eventa($id) if $req=~/event/;
$c->render(json=>$json);
}
#==============================================================================
1;