Hi,

I am working in one of the leading Healthcare company and am making an 
internal Business Intelligence application using Mojolicious with data 
support from Django API.

Even though I could have made the entire application in Django itself, 
because I love perl and Mojolicious, I would like to get this done in 
Mojolicious and want my application to go live and serve top leaders.

While I am able to get what I want, I am struggling to fulfill the need of 
writing Async action in Mojolicious::Controller class.
I have hosted my application in Ubuntu machine and running in Hypnotoad 
with help of 'Carton'.


[2020-05-26 23:18:18.85262] [-16240] [error] syntax error at 
C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 39, near "async on_user_login_p"
Can't redeclare "my" in "my" at 
C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 44, near "my"
syntax error at 
C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 58, near "}"
Can't redeclare "my" in "my" at 
C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 62, near "my"
syntax error at 
C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 75, near "}"
syntax error at 
C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 86, near "}"
Compilation failed in require at (eval 659) line 1.


==========================CODES=================================
package ConvergeAtCommex::Controller::Sessions;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Base -async_await;
use Mojo::UserAgent;
use Mojo::Promise;

# This action will render a template
async on_user_login_p => sub {
    my $self = shift;
    
    # Authenticate by sending the request parameters directly
    if ($self->authenticate($self->param('username'), 
$self->param('password'))) {
        my $access_token = 
$self->access_token($self->session('refresh_token'));
        my $user = await $self->user_data_p($access_token);
        return $self->render(text => 'Unauthenticated Access', status => 
403) unless ($user->{is_staff});
        return $self->render(text => 'You are not an active User', status 
=> 403) unless ($user->{is_active});
        $self->set_authorization($user);
        $self->flash(message_type => 'success');
        $self->flash(message => 'Congratulations ' . 
$self->session('full_name') . '!');
        $self->redirect_to('bi-home');
    } else {
        $self->flash(message_type => 'danger');
        $self->flash(message => 'Wrong SSOID/Password!');
        return $self->redirect_to('login', status => 403);
        #return $self->render(text => 'wrong ssoid/password', status => 
403);
    }
};

async sub user_data_p () {
    my ($c, $access_token) = @_;
    my $ua = Mojo::UserAgent->new;
    my $tx = await $ua->post_p(
        'http://' . $c->config->{API_IP} . '/api-converge/auth/user/',
        {
            Authorization => 'Bearer ' . $access_token,
        },
        form => {username => $c->session('username')}, 

    );
    if ($tx->is_success) {
        return from_json($tx->result->body);
    }
    $c->render(text => 'User Data can not be obtained', status => 500);
}


-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/d935de8d-2e54-4589-8afc-4a2dd988d6d8%40googlegroups.com.

Reply via email to