Skip to content

Commit

Permalink
Impl basic func
Browse files Browse the repository at this point in the history
  • Loading branch information
moznion committed Mar 5, 2014
1 parent 51d788b commit 30e4d18
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 106 deletions.
62 changes: 50 additions & 12 deletions lib/OAuth1TokenVendingServer/Web/Dispatcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,65 @@ use strict;
use warnings;
use utf8;
use Amon2::Web::Dispatcher::RouterBoom;
use OAuth::Lite::Consumer;
use OAuth::Lite::Token;
use OAuth1TokenVendingServer;

any '/' => sub {
my $config = OAuth1TokenVendingServer->load_config;

my $app_name = $config->{app_name};
my $description = $config->{description};
my $callback_url = $config->{callback_url};
my $scope = join(',', @{$config->{scope}});

my $consumer = OAuth::Lite::Consumer->new(
consumer_key => $config->{consumer_key},
consumer_secret => $config->{consumer_secret},
site => $config->{site},
request_token_path => $config->{request_token_path},
access_token_path => $config->{access_token_path},
authorize_path => $config->{authorize_path},
);

get '/' => sub {
my ($c) = @_;
my $counter = $c->session->get('counter') || 0;
$counter++;
$c->session->set('counter' => $counter);

return $c->render('index.tx', {
counter => $counter,
app_name => $app_name,
description => $description,
});
};

post '/reset_counter' => sub {
my $c = shift;
$c->session->remove('counter');
return $c->redirect('/');
get '/auth' => sub {
my ($c) = @_;

my $request_token = $consumer->get_request_token(
callback_url => $callback_url,
scope => $scope,
) or die $consumer->errstr;

$c->session->set(request_token => $request_token->as_encoded);
$c->redirect($consumer->url_to_authorize(token => $request_token));
};

post '/account/logout' => sub {
get '/token' => sub {
my ($c) = @_;
$c->session->expire();
return $c->redirect('/');

my $verifier = $c->req->param('oauth_verifier');
my $request_token = OAuth::Lite::Token->from_encoded($c->session->get('request_token'));

my $access_token = $consumer->get_access_token(
token => $request_token,
verifier => $verifier,
) or die $consumer->errstr;

$c->session->expire;

return $c->render('token.tx', {
app_name => $app_name,
token => $access_token->token,
token_secret => $access_token->secret
});
};

1;
8 changes: 1 addition & 7 deletions tmpl/include/layout.tx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="./"><: $app_name :></a></li>
</ul>
</div>
</div><!-- /.container -->
Expand All @@ -43,9 +40,6 @@
<div id="main">
<: block content -> { } :>
</div>
<footer class="footer">
Powered by <a href="http://amon.64p.org/">Amon2</a>
</footer>
</div>
</body>
</html>
93 changes: 6 additions & 87 deletions tmpl/index.tx
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,13 @@

: override content -> {

<h1 style="padding: 70px; text-align: center; font-size: 80px; line-height: 1; letter-spacing: -2px;">Hello, Amon2 world!</h1>
<h1 style="margin-top: 20px; text-align: center; font-size: 80px; line-height: 1; letter-spacing: -2px;"><: $app_name :></h1>

<hr />
<p style="text-align: center; font-size: 20px">
<: $description :>
</p>

<style>
.marketing .row {
margin-top: 20px;
}
</style>
<div class="marketing">
<h1 style="text-align: center; font-size: 280%;">Battery Included?</h1>

<div class="row">
<div class="col-lg-4">
<h2><i class="glyphicon glyphicon-ok"></i> CSS Library</h2>
<div>
Current version of Amon2 using twitter's bootstrap.css as a default CSS library.<br />
If you want to learn it, please access to <a href="http://getbootstrap.com/">getbootstrap.com/</a>
</div>
</div>

<div class="col-lg-4">
<h2><i class="glyphicon glyphicon-ok"></i> JS Library</h2>
<div>
<a href="http://jquery.com/">jQuery</a> included.
<ul>
<li>es5-shim.min.js</li>
<li>micro-location.js</li>
<li>micro_template.js</li>
<li>sprintf-0.7-beta1.js</li>
<li>strftime.js</li>
</ul>
</div>
</div>

<div class="col-lg-4">
<h2><i class="glyphicon glyphicon-ok"></i> Template Engine</h2>
<div>
Amon2 uses <B>Text::Xslate</B>(Kolon) as a primary template engine.<br />
But you can use any template engine easily.
</div>
</div>
</div>

<div class="row">
<div class="col-lg-4">
<h2><i class="glyphicon glyphicon-ok"></i> O/R Mapper?</h2>
<div>
There is no O/R Mapper support. But I recommend use Teng.<br />
You can integrate Teng very easily.<br />
Refer to <a href="http://amon.64p.org/database.html#teng">this page</a> for more details.
</div>
</div>
</div>
</div>

<hr />

<div class="row">
<h1 style="text-align: center;">Amon2 is right for you if ...</h1>
<div class="col-lg-24">
<ul>
<li>You need exceptional performance.</li>
<li>You want a framework with a small footprint.</li>
<li>You want a framework that requires nearly zero configuration.</li>
</ul>
</div>
<div style="text-align: center; margin-top: 40px">
<a href="./auth"><button class="btn btn-default">Authenticate</button></a>
</div>

<hr />

<section class="row">
<div class="col-lg-12">
<h1>Documents?</h1>
<p>Complete docs are available on <a href="http://amon.64p.org/">amon.64p.org</a></p>
<p>And there are module specific docs on <a href="https://metacpan.org/release/Amon2">CPAN</a></p>
</div>
</section>

<hr>

<h2>Session counter demo</h2>

<p>You seen this page <: $counter :> times.</p>

<form method="post" action="/reset_counter">
<input type="submit" name="Reset counter." class="btn btn-default">
</form>


: }
27 changes: 27 additions & 0 deletions tmpl/token.tx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
: cascade "include/layout.tx"

: override content -> {

<h1 style="margin-top: 20px; text-align: center; font-size: 80px; line-height: 1; letter-spacing: -2px;"><: $app_name :></h1>

<div style="text-align: center; margin-top: 40px">
<table class="table">
<tr>
<th>
Token:
</th>
<td>
<: $token :>
</td>
</tr>
<tr>
<th>
Token Secret:
</th>
<td>
<: $token_secret :>
</td>
</tr>
</table>
</div>
: }

0 comments on commit 30e4d18

Please sign in to comment.