| 1 | package Moxy::Plugin::Filter::UserID; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use base qw/Moxy::Plugin/; |
|---|
| 5 | use HTTP::MobileAgent; |
|---|
| 6 | use URI::Escape; |
|---|
| 7 | use CGI; |
|---|
| 8 | |
|---|
| 9 | sub register { |
|---|
| 10 | my ($class, $context) = @_; |
|---|
| 11 | |
|---|
| 12 | $context->register_hook( |
|---|
| 13 | request_filter => sub { |
|---|
| 14 | my ($context, $args) = @_; |
|---|
| 15 | |
|---|
| 16 | if ($args->{agent} && $args->{agent}->{agent}) { |
|---|
| 17 | my $carrier = HTTP::MobileAgent->new($args->{agent}->{agent})->carrier; |
|---|
| 18 | my $key = join(',', __PACKAGE__, $args->{user}, $args->{agent}->{agent}); |
|---|
| 19 | my $user_id = $context->storage->get($key); |
|---|
| 20 | if ($user_id) { |
|---|
| 21 | # au subscriber id. |
|---|
| 22 | if ($carrier eq 'E') { |
|---|
| 23 | $args->{request}->header('X-Up-Subno' => $user_id); |
|---|
| 24 | } |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | }, |
|---|
| 28 | request_filter => sub { |
|---|
| 29 | my ($context, $args) = @_; |
|---|
| 30 | |
|---|
| 31 | if ($args->{request}->uri =~ m{^http://userid\.moxy/(.+)} && $args->{agent}) { |
|---|
| 32 | my $back = uri_unescape($1); |
|---|
| 33 | |
|---|
| 34 | my $r = CGI->new($args->{request}->content); |
|---|
| 35 | |
|---|
| 36 | # store to user stash. |
|---|
| 37 | my $key = join(',', __PACKAGE__, $args->{user}, $args->{agent}->{agent}); |
|---|
| 38 | $context->storage->set($key => $r->param('user_id')); |
|---|
| 39 | |
|---|
| 40 | my $response = HTTP::Response->new( 302, 'Moxy(UserID)' ); |
|---|
| 41 | $response->header(Location => $back); |
|---|
| 42 | $response; |
|---|
| 43 | } |
|---|
| 44 | }, |
|---|
| 45 | control_panel => sub { |
|---|
| 46 | my ($context, $args) = @_; |
|---|
| 47 | |
|---|
| 48 | if ($args->{agent} && $args->{agent}->{agent}) { |
|---|
| 49 | my $key = join(',', __PACKAGE__, $args->{user}, $args->{agent}->{agent}); |
|---|
| 50 | my $user_id = $context->storage->get($key); |
|---|
| 51 | |
|---|
| 52 | return $class->render_template( |
|---|
| 53 | $context, |
|---|
| 54 | 'panel.tt' => { |
|---|
| 55 | user_id => $user_id, |
|---|
| 56 | referer => $args->{response}->request->uri |
|---|
| 57 | } |
|---|
| 58 | ); |
|---|
| 59 | } else { |
|---|
| 60 | return ''; |
|---|
| 61 | } |
|---|
| 62 | }, |
|---|
| 63 | ); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | 1; |
|---|
| 67 | __END__ |
|---|
| 68 | |
|---|
| 69 | =head1 NAME |
|---|
| 70 | |
|---|
| 71 | Moxy::Plugin::Filter::UserID |
|---|
| 72 | |
|---|
| 73 | =head1 SYNOPSIS |
|---|
| 74 | |
|---|
| 75 | - module: UserID |
|---|
| 76 | |
|---|
| 77 | =head1 DESCRIPTION |
|---|
| 78 | |
|---|
| 79 | Send X-Up-Subno |
|---|
| 80 | |
|---|
| 81 | =head1 AUTHOR |
|---|
| 82 | |
|---|
| 83 | Tokuhiro Matsuno |
|---|
| 84 | |
|---|
| 85 | =head1 SEE ALSO |
|---|
| 86 | |
|---|
| 87 | L<Moxy>, L<Moxy::Plugin::Filter::ControlPanel> |
|---|