Added token administration page set
This commit is contained in:
parent
61d609861a
commit
b10daa469a
5 changed files with 259 additions and 2 deletions
|
@ -101,6 +101,11 @@ sub startup {
|
|||
my $admin_routes = $r->under('/admin')->to('admin#under');
|
||||
|
||||
$admin_routes->get('/home')->to('admin#home');
|
||||
$admin_routes->get('/tokens')->to('admin-tokens#index');
|
||||
$admin_routes->post('/tokens')->to('admin-tokens#create');
|
||||
$admin_routes->get('/tokens/:id')->to('admin-tokens#read');
|
||||
$admin_routes->post('/tokens/:id')->to('admin-tokens#update');
|
||||
$admin_routes->post('/tokens/:id/delete')->to('admin-tokens#delete');
|
||||
|
||||
$self->hook( before_dispatch => sub {
|
||||
my $self = shift;
|
||||
|
|
82
lib/Pear/LocalLoop/Controller/Admin/Tokens.pm
Normal file
82
lib/Pear/LocalLoop/Controller/Admin/Tokens.pm
Normal file
|
@ -0,0 +1,82 @@
|
|||
package Pear::LocalLoop::Controller::Admin::Tokens;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
has result_set => sub {
|
||||
my $c = shift;
|
||||
return $c->schema->resultset('AccountToken');
|
||||
};
|
||||
|
||||
sub index {
|
||||
my $c = shift;
|
||||
|
||||
my $token_rs = $c->result_set;
|
||||
$token_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
|
||||
$c->stash( tokens => [ $token_rs->all ] );
|
||||
}
|
||||
|
||||
# POST
|
||||
sub create {
|
||||
my $c = shift;
|
||||
|
||||
my $token_name = $c->param('token-name');
|
||||
|
||||
my $token_rs = $c->result_set;
|
||||
|
||||
if ( $token_rs->find({ accounttokenname => $token_name }) ) {
|
||||
$c->flash( error => 'Token Already Exists' );
|
||||
} else {
|
||||
$c->flash( success => 'Token Created' );
|
||||
$token_rs->create({ accounttokenname => $token_name });
|
||||
}
|
||||
$c->redirect_to( '/admin/tokens' );
|
||||
}
|
||||
|
||||
# GET
|
||||
sub read {
|
||||
my $c = shift;
|
||||
|
||||
my $id = $c->param('id');
|
||||
|
||||
if ( my $token = $c->result_set->find($id) ) {
|
||||
$c->stash( token => $token );
|
||||
} else {
|
||||
$c->flash( error => 'No Token found' );
|
||||
$c->redirect_to( '/admin/tokens' );
|
||||
}
|
||||
}
|
||||
|
||||
# POST
|
||||
sub update {
|
||||
my $c = shift;
|
||||
|
||||
my $id = $c->param('id');
|
||||
|
||||
if ( my $token = $c->result_set->find($id) ) {
|
||||
$token->update({
|
||||
accounttokenname => $c->param('token-name'),
|
||||
used => $c->param('token-used'),
|
||||
});
|
||||
$c->flash( success => 'Token Updated' );
|
||||
$c->redirect_to( '/admin/tokens/' . $id );
|
||||
} else {
|
||||
$c->flash( error => 'No Token found' );
|
||||
$c->redirect_to( '/admin/tokens' );
|
||||
}
|
||||
}
|
||||
|
||||
# DELETE
|
||||
sub delete {
|
||||
my $c = shift;
|
||||
|
||||
my $id = $c->param('id');
|
||||
|
||||
if ( my $token = $c->result_set->find($id) ) {
|
||||
$token->delete;
|
||||
$c->flash( success => 'Token Deleted' );
|
||||
} else {
|
||||
$c->flash( error => 'No Token found' );
|
||||
}
|
||||
$c->redirect_to( '/admin/tokens' );
|
||||
}
|
||||
|
||||
1;
|
|
@ -22,7 +22,24 @@ body {
|
|||
% end
|
||||
% content_for javascript => begin
|
||||
% end
|
||||
<nav class="navbar fixed-top navbar-inverse bg-primary">
|
||||
<a class="navbar-brand" href="#"><%= title %></a>
|
||||
<nav class="navbar navbar-toggleable-md fixed-top navbar-inverse bg-primary">
|
||||
<button class="navbar-toggler navbar-toggler-right"
|
||||
type="button"
|
||||
data-toggle="collapse"
|
||||
data-target="#navbarNav"
|
||||
aria-controls="navbarNav"
|
||||
aria-expanded="false"
|
||||
aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<a class="navbar-brand" href="<%= url_for '/admin/home' %>"><%= title %></a>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<div class="navbar-nav">
|
||||
<a class="nav-item nav-link" href="<%= url_for '/admin/tokens' %>">Tokens</a>
|
||||
<a class="nav-item nav-link" href="#">Users</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</nav>
|
||||
<div>Admin Pages</div>
|
||||
|
|
77
templates/admin/tokens/index.html.ep
Normal file
77
templates/admin/tokens/index.html.ep
Normal file
|
@ -0,0 +1,77 @@
|
|||
% layout 'default';
|
||||
% title 'LocalLoop Admin - Login';
|
||||
% content_for css => begin
|
||||
<style>
|
||||
body {
|
||||
background: whitesmoke;
|
||||
padding-top: 70px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: white;
|
||||
padding: 16px;
|
||||
-webkit-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
-moz-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.login-form {
|
||||
margin-top: 20%;
|
||||
}
|
||||
</style>
|
||||
% end
|
||||
% content_for javascript => begin
|
||||
% end
|
||||
<nav class="navbar navbar-toggleable-md fixed-top navbar-inverse bg-primary">
|
||||
<button class="navbar-toggler navbar-toggler-right"
|
||||
type="button"
|
||||
data-toggle="collapse"
|
||||
data-target="#navbarNav"
|
||||
aria-controls="navbarNav"
|
||||
aria-expanded="false"
|
||||
aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<a class="navbar-brand" href="<%= url_for '/admin/home' %>"><%= title %></a>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<div class="navbar-nav">
|
||||
<a class="nav-item nav-link active" href="<%= url_for '/admin/tokens' %>">Tokens</a>
|
||||
<a class="nav-item nav-link" href="#">Users</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</nav>
|
||||
<div class="container">
|
||||
% if ( my $error = flash 'error' ) {
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<strong>Error!</strong> <%= $error %>
|
||||
</div>
|
||||
% } elsif ( my $success = flash 'success' ) {
|
||||
<div class="alert alert-success" role="alert">
|
||||
<strong>Success!</strong> <%= $success %>
|
||||
</div>
|
||||
% }
|
||||
<form action="<%= url_for %>" method="post">
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" placeholder="Token Text" name="token-name">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-primary" type="submit">Add</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="list-group">
|
||||
% for my $token (@$tokens) {
|
||||
<a href="<%= url_for . '/' . $token->{accounttokenid} %>" class="list-group-item list-group-item-action">
|
||||
<div>
|
||||
%= $token->{accounttokenname}
|
||||
</div>
|
||||
<div class="ml-auto">
|
||||
<%= $token->{used} == 1 ? 'Used' : 'Available' %>
|
||||
</div>
|
||||
</a>
|
||||
% }
|
||||
</div>
|
||||
</div>
|
76
templates/admin/tokens/read.html.ep
Normal file
76
templates/admin/tokens/read.html.ep
Normal file
|
@ -0,0 +1,76 @@
|
|||
% layout 'default';
|
||||
% title 'LocalLoop Admin - Login';
|
||||
% content_for css => begin
|
||||
<style>
|
||||
body {
|
||||
background: whitesmoke;
|
||||
padding-top: 70px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: white;
|
||||
padding: 16px;
|
||||
-webkit-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
-moz-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.login-form {
|
||||
margin-top: 20%;
|
||||
}
|
||||
</style>
|
||||
% end
|
||||
% content_for javascript => begin
|
||||
% end
|
||||
<nav class="navbar navbar-toggleable-md fixed-top navbar-inverse bg-primary">
|
||||
<button class="navbar-toggler navbar-toggler-right"
|
||||
type="button"
|
||||
data-toggle="collapse"
|
||||
data-target="#navbarNav"
|
||||
aria-controls="navbarNav"
|
||||
aria-expanded="false"
|
||||
aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<a class="navbar-brand" href="<%= url_for '/admin/home' %>"><%= title %></a>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<div class="navbar-nav">
|
||||
<a class="nav-item nav-link active" href="<%= url_for '/admin/tokens' %>">Tokens</a>
|
||||
<a class="nav-item nav-link" href="#">Users</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</nav>
|
||||
<div class="container">
|
||||
% if ( my $error = flash 'error' ) {
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<strong>Error!</strong> <%= $error %>
|
||||
</div>
|
||||
% } elsif ( my $success = flash 'success' ) {
|
||||
<div class="alert alert-success" role="alert">
|
||||
<strong>Success!</strong> <%= $success %>
|
||||
</div>
|
||||
% }
|
||||
<form action="<%= url_for %>" method="post">
|
||||
<div class="form-group">
|
||||
<label for="token-name">Token Name</label>
|
||||
<input id="token-name" type="text" class="form-control" placeholder="Token Text" name="token-name" value="<%= $token->accounttokenname %>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="token-used">Token Used?</label>
|
||||
<select id="token-used" class="form-control" name="token-used">
|
||||
<option value="0"<%= $token->used == 0 ? ' selected' : '' %>>Available</option>
|
||||
<option value="1"<%= $token->used == 1 ? ' selected' : '' %>>Used</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary form-control" type="submit">Update</button>
|
||||
</div>
|
||||
</form>
|
||||
<form action="<%= url_for . '/delete' %>" method="post">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-danger form-control" type="submit">Delete</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
Reference in a new issue