Created action for creating new mods
This commit is contained in:
parent
829be876c1
commit
25f47ce80d
|
@ -32,7 +32,8 @@ Run the tests locally (against development environment):
|
|||
|
||||
## TODOs
|
||||
|
||||
1. Actions for creating moderators and resetting passwords
|
||||
1. Action for resetting passwords
|
||||
1. Action for locking/unlocking accounts
|
||||
1. CSS
|
||||
1. "All new posts flagged" mode (require approval for new posts)
|
||||
|
||||
|
|
|
@ -58,10 +58,6 @@ sub startup($self) {
|
|||
return undef;
|
||||
});
|
||||
|
||||
$self->helper(is_admin => sub ($c) {
|
||||
$self->session->{'is_admin'} || undef
|
||||
});
|
||||
|
||||
# Finish configuring some things
|
||||
$self->secrets($self->config->{'secrets'}) || die $@;
|
||||
|
||||
|
@ -160,6 +156,10 @@ sub startup($self) {
|
|||
->to('moderator#hidden')
|
||||
->name('hidden_list');
|
||||
|
||||
$moderator->any([qw{GET POST}], '/create')
|
||||
->to('moderator#create')
|
||||
->name('create_mod');
|
||||
|
||||
my $mod_thread = $moderator->under('/thread');
|
||||
|
||||
$mod_thread->get('/unflag/:thread_id', [thread_id => qr/\d+/])
|
||||
|
@ -188,9 +188,6 @@ sub startup($self) {
|
|||
->to('moderator#unhide_remark')
|
||||
->name('unhide_remark');
|
||||
|
||||
# under() for admins
|
||||
|
||||
# Actions to create mods...
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -91,7 +91,7 @@ sub unflag_thread($self) {
|
|||
my $redirect_url = $self->url_for('threads_list')->fragment('info')->to_abs;
|
||||
|
||||
$self->moderator->unflag_thread($thread_id);
|
||||
$self->flash(info => "Thread #$thread_id has been unflagged. ◀️");
|
||||
$self->flash(info => "Thread #$thread_id has been unflagged. ◀");
|
||||
|
||||
$self->redirect_to($redirect_url);
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ sub unflag_remark($self) {
|
|||
->fragment('info')->to_abs;
|
||||
|
||||
$self->moderator->unflag_remark($remark_id);
|
||||
$self->flash(info => "Remark #$remark_id has been unflagged. ◀️");
|
||||
$self->flash(info => "Remark #$remark_id has been unflagged. ◀");
|
||||
|
||||
$self->redirect_to($redirect_url);
|
||||
}
|
||||
|
@ -152,4 +152,32 @@ sub unhide_remark($self) {
|
|||
$self->redirect_to($redirect_url);
|
||||
}
|
||||
|
||||
sub create($self) {
|
||||
my $v;
|
||||
|
||||
$v = $self->validation if $self->req->method eq 'POST';
|
||||
|
||||
if ($v && $v->has_data) {
|
||||
$v->required('name' );
|
||||
$v->required('email' );
|
||||
$v->required('password');
|
||||
|
||||
if ($v->has_error) {
|
||||
$self->stash(status => 400)
|
||||
}
|
||||
else {
|
||||
my ($name, $email, $password);
|
||||
|
||||
$name = $self->param('name');
|
||||
$email = $self->param('email');
|
||||
$password = $self->param('password');
|
||||
|
||||
$self->moderator->create($name, $email, $password);
|
||||
$self->stash(info => "Created moderator account for $name 🧑🏭");
|
||||
}
|
||||
}
|
||||
|
||||
return $self->render;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -83,6 +83,7 @@ subtest Login => sub {
|
|||
->element_exists('a[href*="/moderator/flagged"]')
|
||||
->element_exists('a[href*="/moderator/hidden"]' )
|
||||
->element_exists('a[href*="/logout"]' )
|
||||
->element_exists('a[href*="/moderator/create"]' )
|
||||
};
|
||||
|
||||
subtest Hidden => sub {
|
||||
|
@ -92,6 +93,17 @@ subtest Login => sub {
|
|||
->element_exists('a[href*="/moderator/flagged"]')
|
||||
->element_exists('a[href*="/moderator/hidden"]' )
|
||||
->element_exists('a[href*="/logout"]' )
|
||||
->element_exists('a[href*="/moderator/create"]' )
|
||||
};
|
||||
|
||||
subtest Create => sub {
|
||||
$t->get_ok('/moderator/create')
|
||||
->status_is(200)
|
||||
->text_like(h2 => qr/Create Moderator/)
|
||||
->element_exists('a[href*="/moderator/flagged"]')
|
||||
->element_exists('a[href*="/moderator/hidden"]' )
|
||||
->element_exists('a[href*="/logout"]' )
|
||||
->element_exists('a[href*="/moderator/create"]' )
|
||||
};
|
||||
|
||||
# Mod session ends
|
||||
|
@ -125,6 +137,10 @@ subtest Login => sub {
|
|||
$t->get_ok('/moderator/hidden')
|
||||
->status_is(302)
|
||||
->header_like(Location => qr/login/);
|
||||
|
||||
$t->get_ok('/moderator/create')
|
||||
->status_is(302)
|
||||
->header_like(Location => qr/login/);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,16 +7,28 @@
|
|||
<body>
|
||||
<h1>Post::Text</h1>
|
||||
<nav>
|
||||
<div>
|
||||
<span>Navigate:</span>
|
||||
<%= link_to List => 'threads_list' %>
|
||||
<%= link_to New => 'post_thread' %>
|
||||
<% unless (is_mod) { =%>
|
||||
<%= link_to Login => 'mod_login' %>
|
||||
<% } =%>
|
||||
</div>
|
||||
<div>
|
||||
<% if (is_mod) { =%>
|
||||
<span>Moderate:</span>
|
||||
<%= link_to Flagged => 'flagged_list' %>
|
||||
<%= link_to Hidden => 'hidden_list' %>
|
||||
<%= link_to Logout => 'mod_logout' %>
|
||||
<% } =%>
|
||||
</div>
|
||||
<div>
|
||||
<% if (is_mod && session->{'is_admin'}) { =%>
|
||||
<span>Admin:</span>
|
||||
<%= link_to Create => 'create_mod' %>
|
||||
<% } =%>
|
||||
</div>
|
||||
</nav>
|
||||
<hr>
|
||||
<% if (flash 'error') { =%>
|
||||
|
@ -27,6 +39,9 @@
|
|||
<% if (flash 'info') { =%>
|
||||
<p class="field-with-info" id="info"><%= flash 'info' %></p>
|
||||
<% } =%>
|
||||
<% if (stash 'info') { =%>
|
||||
<p class="field-with-info" id="info"><%= stash 'info' %></p>
|
||||
<% } =%>
|
||||
<%= content =%>
|
||||
<footer>
|
||||
<p>In UTF-8 we trust. 🫡</p>
|
||||
|
|
18
templates/moderator/create.html.ep
Normal file
18
templates/moderator/create.html.ep
Normal file
|
@ -0,0 +1,18 @@
|
|||
% layout 'default';
|
||||
% title 'Create Moderator';
|
||||
<h2><%= title %></h2>
|
||||
<form method="post">
|
||||
<div class="name field">
|
||||
<%= label_for name => 'Name' %>
|
||||
<%= text_field 'name' %>
|
||||
</div>
|
||||
<div class="email field">
|
||||
<%= label_for email => 'Email' %>
|
||||
<%= email_field 'email' %>
|
||||
</div>
|
||||
<div class="password field">
|
||||
<%= label_for password => 'Password' %>
|
||||
<%= password_field 'password' %>
|
||||
</div>
|
||||
<%= submit_button 'Create' %>
|
||||
</form>
|
Loading…
Reference in New Issue
Block a user