Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Friendly green button for admins to "Renew Membership" of users whose accounts are "Expiring" or "Expired". #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ static public function handleEditUser($app, $twig, $username) {
$temppassword = $user->resetPassword();
$successmessage = "Password for $username reset to '$temppassword'.";
}

if (isset($_POST['renewmembership'])) {
$user->renewMembership();
$nextExpiry = date("Y-m-d", strtotime($user->expiry));
$successmessage = "Membership renewed until $nextExpiry.";
}

if (isset($_POST['update'])) {
$user->displayname = $_POST["displayname"];
Expand Down
39 changes: 38 additions & 1 deletion model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function save() {
global $conf;

if (self::get($this->username) == null) {
//create new user (POST)
//create new user (POST)
$details = get_object_vars($this);

$user = $_SESSION['username'];
Expand All @@ -190,6 +190,17 @@ public function save() {
if ($response->headers['Status'] != "200 OK") {
return false;
} else {

/* There is a bug in the API's use of computeExpiry. The
* subroutine itself works and is passing unit tests but
* somewhere in the user creation process the expiry date is
* getting decremented by one day. So call renewMembership
* here to compensate for that until the bug is fixed.
*/
// TODO: Fix the API's createUser computeExpiry bug

$this->renewMembership();

return true;
}
} else {
Expand All @@ -212,10 +223,36 @@ public function save() {
}
}

public function renewMembership() {
$this->expiry = $this->computeExpiry();
$this->paid = "TRUE";
return $this->save();
}

public function isAdmin() {
return $this->isAdmin;
}

// Maybe this could be done in the API
public function computeExpiry() {
$now = time();
$thisYear = date("Y", $now);
$nextYear = $thisYear + 1;

$newYearsDay = mktime(0, 0, 0, 1, 1, $thisYear);
$hogmanay = mktime(0, 0, 0, 12, 31, $thisYear);
$threshold = strtotime("last Friday of May $thisYear");

$nextExpiryString = 'first Friday of October';

if ($now >= $newYearsDay and $now < $threshold) {
$nextExpiryString .= " $thisYear";
} else {
$nextExpiryString .= " $nextYear";
}

return $nextExpiryString;
}

}

Expand Down
10 changes: 9 additions & 1 deletion views/admin/editUser.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
<span class="input-xlarge uneditable-input">{{ user.status }}</span>
</div>
</div>
{{ user.status == 'Expired' or user.status == 'Expiring' ? "
<div class=\"control-group\">
<label class=\"control-label\"><!--Renew--></label>
<div class=\"controls\">
<button name=\"renewmembership\" type=\"submit\" class=\"btn btn-small btn-success\" >Renew Membership</button>
</div>
</div>
": null }}
<div class="control-group">
<label class="control-label">Expiry</label>
<div class="controls">
Expand Down Expand Up @@ -124,4 +132,4 @@ <h3>Are you sure?</h3>
</div><!--/span-->
</div><!--/row-->
</div><!--/span-->
{% endblock %}
{% endblock %}