Universal check for form submission
This commit is contained in:
parent
90a75e4d30
commit
823888b0c1
10 changed files with 198 additions and 168 deletions
|
@ -70,7 +70,7 @@ $(function()
|
||||||
aDom.addClass('inactive');
|
aDom.addClass('inactive');
|
||||||
|
|
||||||
var url = $(this).attr('href') + '?json';
|
var url = $(this).attr('href') + '?json';
|
||||||
$.get(url, function(data)
|
$.get(url, {submit: 1}, function(data)
|
||||||
{
|
{
|
||||||
if (data['success'])
|
if (data['success'])
|
||||||
{
|
{
|
||||||
|
|
|
@ -82,6 +82,7 @@ $(function()
|
||||||
fd.append('tags', tags);
|
fd.append('tags', tags);
|
||||||
fd.append('safety', safety);
|
fd.append('safety', safety);
|
||||||
fd.append('source', source);
|
fd.append('source', source);
|
||||||
|
fd.append('submit', 1);
|
||||||
|
|
||||||
var ajaxData =
|
var ajaxData =
|
||||||
{
|
{
|
||||||
|
|
|
@ -203,7 +203,7 @@ class PostController
|
||||||
if ($this->config->registration->needEmailForUploading)
|
if ($this->config->registration->needEmailForUploading)
|
||||||
PrivilegesHelper::confirmEmail($this->context->user);
|
PrivilegesHelper::confirmEmail($this->context->user);
|
||||||
|
|
||||||
if (!empty($_FILES['file']['name']))
|
if (InputHelper::get('submit'))
|
||||||
{
|
{
|
||||||
/* file contents */
|
/* file contents */
|
||||||
$suppliedFile = $_FILES['file'];
|
$suppliedFile = $_FILES['file'];
|
||||||
|
@ -290,10 +290,10 @@ class PostController
|
||||||
{
|
{
|
||||||
$post = Model_Post::locate($id);
|
$post = Model_Post::locate($id);
|
||||||
R::preload($post, ['uploader' => 'user']);
|
R::preload($post, ['uploader' => 'user']);
|
||||||
$edited = false;
|
|
||||||
|
|
||||||
$this->context->transport->post = $post;
|
$this->context->transport->post = $post;
|
||||||
|
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
/* safety */
|
/* safety */
|
||||||
$suppliedSafety = InputHelper::get('safety');
|
$suppliedSafety = InputHelper::get('safety');
|
||||||
if ($suppliedSafety !== null)
|
if ($suppliedSafety !== null)
|
||||||
|
@ -352,12 +352,10 @@ class PostController
|
||||||
$edited = true;
|
$edited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* db storage */
|
|
||||||
if ($edited)
|
|
||||||
R::store($post);
|
R::store($post);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -368,10 +366,13 @@ class PostController
|
||||||
{
|
{
|
||||||
$post = Model_Post::locate($id);
|
$post = Model_Post::locate($id);
|
||||||
PrivilegesHelper::confirmWithException(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
PrivilegesHelper::confirmWithException(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
$post->hidden = true;
|
$post->hidden = true;
|
||||||
R::store($post);
|
R::store($post);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @route /post/{id}/unhide
|
* @route /post/{id}/unhide
|
||||||
|
@ -380,10 +381,13 @@ class PostController
|
||||||
{
|
{
|
||||||
$post = Model_Post::locate($id);
|
$post = Model_Post::locate($id);
|
||||||
PrivilegesHelper::confirmWithException(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
PrivilegesHelper::confirmWithException(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
$post->hidden = false;
|
$post->hidden = false;
|
||||||
R::store($post);
|
R::store($post);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @route /post/{id}/delete
|
* @route /post/{id}/delete
|
||||||
|
@ -392,6 +396,8 @@ class PostController
|
||||||
{
|
{
|
||||||
$post = Model_Post::locate($id);
|
$post = Model_Post::locate($id);
|
||||||
PrivilegesHelper::confirmWithException(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
PrivilegesHelper::confirmWithException(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
//remove stuff from auxiliary tables
|
//remove stuff from auxiliary tables
|
||||||
$post->ownFavoritee = [];
|
$post->ownFavoritee = [];
|
||||||
$post->sharedTag = [];
|
$post->sharedTag = [];
|
||||||
|
@ -399,6 +405,7 @@ class PostController
|
||||||
R::trash($post);
|
R::trash($post);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -410,7 +417,10 @@ class PostController
|
||||||
{
|
{
|
||||||
$post = Model_Post::locate($id);
|
$post = Model_Post::locate($id);
|
||||||
R::preload($post, ['favoritee' => 'user']);
|
R::preload($post, ['favoritee' => 'user']);
|
||||||
|
PrivilegesHelper::confirmWithException(Privilege::FavoritePost);
|
||||||
|
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
if (!$this->context->loggedIn)
|
if (!$this->context->loggedIn)
|
||||||
throw new SimpleException('Not logged in');
|
throw new SimpleException('Not logged in');
|
||||||
|
|
||||||
|
@ -418,11 +428,11 @@ class PostController
|
||||||
if ($fav->id == $this->context->user->id)
|
if ($fav->id == $this->context->user->id)
|
||||||
throw new SimpleException('Already in favorites');
|
throw new SimpleException('Already in favorites');
|
||||||
|
|
||||||
PrivilegesHelper::confirmWithException(Privilege::FavoritePost);
|
|
||||||
$post->link('favoritee')->user = $this->context->user;
|
$post->link('favoritee')->user = $this->context->user;
|
||||||
R::store($post);
|
R::store($post);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @route /post/{id}/rem-fav
|
* @route /post/{id}/rem-fav
|
||||||
|
@ -432,8 +442,10 @@ class PostController
|
||||||
{
|
{
|
||||||
$post = Model_Post::locate($id);
|
$post = Model_Post::locate($id);
|
||||||
R::preload($post, ['favoritee' => 'user']);
|
R::preload($post, ['favoritee' => 'user']);
|
||||||
|
|
||||||
PrivilegesHelper::confirmWithException(Privilege::FavoritePost);
|
PrivilegesHelper::confirmWithException(Privilege::FavoritePost);
|
||||||
|
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
if (!$this->context->loggedIn)
|
if (!$this->context->loggedIn)
|
||||||
throw new SimpleException('Not logged in');
|
throw new SimpleException('Not logged in');
|
||||||
|
|
||||||
|
@ -449,6 +461,7 @@ class PostController
|
||||||
R::store($post);
|
R::store($post);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,8 @@ class TagController
|
||||||
public function mergeAction()
|
public function mergeAction()
|
||||||
{
|
{
|
||||||
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
|
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
$sourceTag = Model_Tag::locate(InputHelper::get('source-tag'));
|
$sourceTag = Model_Tag::locate(InputHelper::get('source-tag'));
|
||||||
$targetTag = Model_Tag::locate(InputHelper::get('target-tag'));
|
$targetTag = Model_Tag::locate(InputHelper::get('target-tag'));
|
||||||
|
|
||||||
|
@ -66,6 +68,7 @@ class TagController
|
||||||
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('tag', 'list'));
|
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('tag', 'list'));
|
||||||
$this->view->context->success = true;
|
$this->view->context->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @route /tags/rename
|
* @route /tags/rename
|
||||||
|
@ -73,7 +76,8 @@ class TagController
|
||||||
public function renameAction()
|
public function renameAction()
|
||||||
{
|
{
|
||||||
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
|
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
$suppliedSourceTag = InputHelper::get('source-tag');
|
$suppliedSourceTag = InputHelper::get('source-tag');
|
||||||
$suppliedSourceTag = Model_Tag::validateTag($suppliedSourceTag);
|
$suppliedSourceTag = Model_Tag::validateTag($suppliedSourceTag);
|
||||||
|
|
||||||
|
@ -88,3 +92,4 @@ class TagController
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -128,10 +128,13 @@ class UserController
|
||||||
{
|
{
|
||||||
$user = Model_User::locate($name);
|
$user = Model_User::locate($name);
|
||||||
PrivilegesHelper::confirmWithException(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($user));
|
PrivilegesHelper::confirmWithException(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($user));
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
$user->banned = true;
|
$user->banned = true;
|
||||||
R::store($user);
|
R::store($user);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @route /post/{name}/unban
|
* @route /post/{name}/unban
|
||||||
|
@ -141,10 +144,13 @@ class UserController
|
||||||
{
|
{
|
||||||
$user = Model_User::locate($name);
|
$user = Model_User::locate($name);
|
||||||
PrivilegesHelper::confirmWithException(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($user));
|
PrivilegesHelper::confirmWithException(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($user));
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
$user->banned = false;
|
$user->banned = false;
|
||||||
R::store($user);
|
R::store($user);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @route /post/{name}/accept-registration
|
* @route /post/{name}/accept-registration
|
||||||
|
@ -154,11 +160,13 @@ class UserController
|
||||||
{
|
{
|
||||||
$user = Model_User::locate($name);
|
$user = Model_User::locate($name);
|
||||||
PrivilegesHelper::confirmWithException(Privilege::AcceptUserRegistration);
|
PrivilegesHelper::confirmWithException(Privilege::AcceptUserRegistration);
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
$user->staff_confirmed = true;
|
$user->staff_confirmed = true;
|
||||||
R::store($user);
|
R::store($user);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,7 +189,7 @@ class UserController
|
||||||
|
|
||||||
$this->context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
|
$this->context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
|
||||||
|
|
||||||
if (InputHelper::get('remove'))
|
if (InputHelper::get('submit'))
|
||||||
{
|
{
|
||||||
if ($this->context->user->id == $user->id)
|
if ($this->context->user->id == $user->id)
|
||||||
{
|
{
|
||||||
|
@ -217,9 +225,7 @@ class UserController
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
$user = Model_User::locate($name);
|
$user = Model_User::locate($name);
|
||||||
$edited = false;
|
|
||||||
PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user));
|
PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user));
|
||||||
|
|
||||||
$this->context->handleExceptions = true;
|
$this->context->handleExceptions = true;
|
||||||
|
@ -237,12 +243,13 @@ class UserController
|
||||||
$this->context->suppliedAccessRank = $suppliedAccessRank = InputHelper::get('access-rank');
|
$this->context->suppliedAccessRank = $suppliedAccessRank = InputHelper::get('access-rank');
|
||||||
$currentPasswordHash = $user->pass_hash;
|
$currentPasswordHash = $user->pass_hash;
|
||||||
|
|
||||||
|
if (InputHelper::get('submit'))
|
||||||
|
{
|
||||||
if ($suppliedName != '' and $suppliedName != $user->name)
|
if ($suppliedName != '' and $suppliedName != $user->name)
|
||||||
{
|
{
|
||||||
PrivilegesHelper::confirmWithException(Privilege::ChangeUserName, PrivilegesHelper::getIdentitySubPrivilege($user));
|
PrivilegesHelper::confirmWithException(Privilege::ChangeUserName, PrivilegesHelper::getIdentitySubPrivilege($user));
|
||||||
$suppliedName = Model_User::validateUserName($suppliedName);
|
$suppliedName = Model_User::validateUserName($suppliedName);
|
||||||
$user->name = $suppliedName;
|
$user->name = $suppliedName;
|
||||||
$edited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($suppliedPassword1 != '')
|
if ($suppliedPassword1 != '')
|
||||||
|
@ -252,7 +259,6 @@ class UserController
|
||||||
throw new SimpleException('Specified passwords must be the same');
|
throw new SimpleException('Specified passwords must be the same');
|
||||||
$suppliedPassword = Model_User::validatePassword($suppliedPassword1);
|
$suppliedPassword = Model_User::validatePassword($suppliedPassword1);
|
||||||
$user->pass_hash = Model_User::hashPassword($suppliedPassword, $user->pass_salt);
|
$user->pass_hash = Model_User::hashPassword($suppliedPassword, $user->pass_salt);
|
||||||
$edited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($suppliedEmail != '' and $suppliedEmail != $user->email_confirmed)
|
if ($suppliedEmail != '' and $suppliedEmail != $user->email_confirmed)
|
||||||
|
@ -269,7 +275,6 @@ class UserController
|
||||||
{
|
{
|
||||||
$user->email_confirmed = $suppliedEmail;
|
$user->email_confirmed = $suppliedEmail;
|
||||||
}
|
}
|
||||||
$edited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($suppliedAccessRank != '' and $suppliedAccessRank != $user->access_rank)
|
if ($suppliedAccessRank != '' and $suppliedAccessRank != $user->access_rank)
|
||||||
|
@ -277,11 +282,8 @@ class UserController
|
||||||
PrivilegesHelper::confirmWithException(Privilege::ChangeUserAccessRank, PrivilegesHelper::getIdentitySubPrivilege($user));
|
PrivilegesHelper::confirmWithException(Privilege::ChangeUserAccessRank, PrivilegesHelper::getIdentitySubPrivilege($user));
|
||||||
$suppliedAccessRank = Model_User::validateAccessRank($suppliedAccessRank);
|
$suppliedAccessRank = Model_User::validateAccessRank($suppliedAccessRank);
|
||||||
$user->access_rank = $suppliedAccessRank;
|
$user->access_rank = $suppliedAccessRank;
|
||||||
$edited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($edited)
|
|
||||||
{
|
|
||||||
if ($this->context->user->id == $user->id)
|
if ($this->context->user->id == $user->id)
|
||||||
{
|
{
|
||||||
$suppliedPasswordHash = Model_User::hashPassword($suppliedCurrentPassword, $user->pass_salt);
|
$suppliedPasswordHash = Model_User::hashPassword($suppliedCurrentPassword, $user->pass_salt);
|
||||||
|
@ -291,7 +293,6 @@ class UserController
|
||||||
R::store($user);
|
R::store($user);
|
||||||
$this->context->transport->success = true;
|
$this->context->transport->success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,6 +81,8 @@
|
||||||
<label class="left">Source:</label>
|
<label class="left">Source:</label>
|
||||||
<div class="input-wrapper"><input type="text" name="source" placeholder="where did you get this from? (optional)"/></div>
|
<div class="input-wrapper"><input type="text" name="source" placeholder="where did you get this from? (optional)"/></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="submit" value="1"/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -252,6 +252,8 @@
|
||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
<input type="hidden" name="submit" value="1"/>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="left"> </label>
|
<label class="left"> </label>
|
||||||
<button type="submit">Submit</button>
|
<button type="submit">Submit</button>
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
<div class="input-wrapper"><input type="text" name="target-tag" id="merge-target-tag"></div>
|
<div class="input-wrapper"><input type="text" name="target-tag" id="merge-target-tag"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="submit" value="1"/>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="left"> </label>
|
<label class="left"> </label>
|
||||||
<button type="submit">Merge!</button>
|
<button type="submit">Merge!</button>
|
||||||
|
@ -47,6 +49,8 @@
|
||||||
<div class="input-wrapper"><input type="text" name="target-tag" id="rename-target-tag"></div>
|
<div class="input-wrapper"><input type="text" name="target-tag" id="rename-target-tag"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="submit" value="1"/>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="left"> </label>
|
<label class="left"> </label>
|
||||||
<button type="submit">Rename!</button>
|
<button type="submit">Rename!</button>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<form action="<?php echo \Chibi\UrlHelper::route('user', 'delete', ['name' => $this->context->transport->user->name]) ?>" method="post" class="edit aligned" autocomplete="off" data-confirm-text="Are you sure you want to delete your account?">
|
<form action="<?php echo \Chibi\UrlHelper::route('user', 'delete', ['name' => $this->context->transport->user->name]) ?>" method="post" class="delete aligned" autocomplete="off" data-confirm-text="Are you sure you want to delete your account?">
|
||||||
<?php if ($this->context->user->id == $this->context->transport->user->id): ?>
|
<?php if ($this->context->user->id == $this->context->transport->user->id): ?>
|
||||||
<div class="current-password">
|
<div class="current-password">
|
||||||
<label class="left" for="current-password">Current password:</label>
|
<label class="left" for="current-password">Current password:</label>
|
||||||
|
@ -6,7 +6,7 @@
|
||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<input type="hidden" name="remove" value="1"/>
|
<input type="hidden" name="submit" value="1"/>
|
||||||
|
|
||||||
<?php if ($this->context->transport->success === true): ?>
|
<?php if ($this->context->transport->success === true): ?>
|
||||||
<p class="alert alert-success">Account settings updated!</p>
|
<p class="alert alert-success">Account settings updated!</p>
|
||||||
|
|
|
@ -50,6 +50,8 @@
|
||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
<input type="hidden" name="submit" value="1"/>
|
||||||
|
|
||||||
<?php if ($this->context->transport->success === true): ?>
|
<?php if ($this->context->transport->success === true): ?>
|
||||||
<p class="alert alert-success">Account settings updated! <?php if (!empty($this->context->mailSent)) echo 'You will be sent new e-mail address confirmation message soon.' ?></p>
|
<p class="alert alert-success">Account settings updated! <?php if (!empty($this->context->mailSent)) echo 'You will be sent new e-mail address confirmation message soon.' ?></p>
|
||||||
<?php elseif (isset($this->context->transport->errorMessage)): ?>
|
<?php elseif (isset($this->context->transport->errorMessage)): ?>
|
||||||
|
|
Loading…
Reference in a new issue