Skip to content

Commit

Permalink
Merge pull request #136 from vhs/payments
Browse files Browse the repository at this point in the history
Admin profile fixes & user payment history
  • Loading branch information
JarrettR committed Nov 19, 2015
2 parents 6f12bb7 + 0110ee1 commit 01ea022
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 48 deletions.
8 changes: 8 additions & 0 deletions app/contracts/IUserService1.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,12 @@ public function UpdateStatus($userid, $status);
* @return mixed
*/
public function GetStatuses();

/**
* @permission administrator
* @param $userid
* @param $date
* @return mixed
*/
public function UpdateExpiry($userid, $date);
}
14 changes: 11 additions & 3 deletions app/services/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

use app\contracts\IPaymentService1;
use app\domain\Payment;
use app\endpoints\web\UserService1;
use app\schema\SettingsSchema;
use Aws\CloudFront\Exception\Exception;
use vhs\database\Database;
use vhs\domain\Filter;
use vhs\security\CurrentUser;
Expand All @@ -31,10 +33,16 @@ public function GetPayment($id) {
}

public function ListUserPayments($userid, $page, $size, $columns, $order, $filters) {
if (!(CurrentUser::getIdentity() == $userid || CurrentUser::hasAnyPermissions("administrator")))
return null;
$userService = new UserService();
$user = $userService->GetUser($userid);

if (is_string($filters)) //todo total hack.. this is to support GET params for downloading payments
$filters = json_decode($filters);

if (is_null($user))
throw new \Exception("User not found or you do not have access");

$userFilter = Filter::Equal("user_id", $userid);
$userFilter = Filter::_Or(Filter::Equal("user_id", $user->id), Filter::Equal("payer_email", $user->email));

if (is_null($filters) || $filters == "")
$filters = $userFilter;
Expand Down
22 changes: 18 additions & 4 deletions app/services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public function GetUser($userid) {
}

public function UpdatePassword($userid, $password) {
if (CurrentUser::getIdentity() != $userid || CurrentUser::hasAnyPermissions("administrator") != true) {
return;
}

$user = $this->GetUser($userid);

if(is_null($user)) return;
Expand Down Expand Up @@ -295,4 +291,22 @@ public function ListUsers($page, $size, $columns, $order, $filters)
{
return User::page($page, $size, $columns, $order, $filters);
}

/**
* @permission administrator
* @param $userid
* @param $date
* @return mixed
*/
public function UpdateExpiry($userid, $date)
{
$user = User::find($userid);

if (is_null($user))
return;

$user->mem_expire = (new DateTime($date))->format("Y-m-d H:i:s");

$user->save();
}
}
37 changes: 33 additions & 4 deletions web/admin/users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h2 class="page-header">Edit User</h2>
<div class="col-lg-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
Profile
Profile - Userid {{profile.id}}
</div>
<div class="panel-body">
<form role="form" name="profileForm" ng-submit="updateProfile(profileForm.$valid)" novalidate>
Expand Down Expand Up @@ -119,7 +119,7 @@ <h4 class="modal-title" id="pin{{key.id}}ModalLabel">PIN {{key.pinid}}{{key.pin}

<label>Membership Expiry</label>
<p class="form-control-static">{{profile.mem_expire}}</p>

<input class="form-control" placeholder="Membership Expiry" ng-model="profile.mem_expire">
</div>
</div>
</div>
Expand Down Expand Up @@ -332,7 +332,7 @@ <h4>Privileges</h4>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6" ng-repeat="privilege in currentUser.privileges">
<div class="col-lg-6 col-md-6" ng-repeat="privilege in currentProfile.privileges">
<div class="panel panel-green">
<div class="panel-heading">
<div class="row">
Expand All @@ -353,7 +353,7 @@ <h4>Privileges</h4>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6" ng-repeat="privilege in currentUser.membership.privileges">
<div class="col-lg-6 col-md-6" ng-repeat="privilege in currentProfile.membership.privileges">
<div class="panel panel-green">
<div class="panel-heading">
<div class="row">
Expand All @@ -375,3 +375,32 @@ <h4>Privileges</h4>
</div>
</div>

<div class="modal fade" id="passwordChange" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button ng-click="resetPasswordForm()" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Change Password</h4>
</div>
<form name="changePasswordForm" ng-submit="changePassword(changePasswordForm.$valid)" novalidate>
<div class="modal-body">
<div class="form-group" ng-class="{ 'has-error' : changePasswordForm.newPassword.$invalid && !changePasswordForm.newPassword.$pristine }">
<input class="form-control" type="password" placeholder="New Password" name="newPassword" ng-model="newPassword" ng-minlength="4" required ng-change="comparePasswords()">
<p class="help-block" ng-show="changePasswordForm.newPassword.$error.minlength">Passwords must be at least 4 characters long</p>
</div>
<div class="form-group" ng-class="{ 'has-error' : (changePasswordForm.rePassword.$invalid && !changePasswordForm.rePassword.$pristine) || !passwordsMatch }">
<input class="form-control" type="password" placeholder="Confirm Password" name="rePassword" ng-model="rePassword" ng-minlength="4" required ng-change="comparePasswords()">
<p class="help-block" ng-show="!passwordsMatch">Passwords must match</p>
<p class="help-block" ng-show="changePasswordForm.rePassword.$error.minlength">Passwords must be at least 4 characters long</p>
</div>
</div>
<div class="modal-footer">
<button ng-click="resetPasswordForm()" type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" ng-disabled="changePasswordForm.$invalid || !passwordsMatch">Change Password</button>
</div>
</form>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
80 changes: 52 additions & 28 deletions web/admin/users/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,45 @@ angular
$scope.profile.username
).then(function() {

if ($scope.currentUser.hasPrivilege("full-profile")) {
$scope.pendingUpdate += 1;
UserService1.UpdateName(
$scope.currentUser.id,
$scope.profile.fname,
$scope.profile.lname
).then(function() { $scope.pendingUpdate -= 1; });

$scope.pendingUpdate += 1;
UserService1.UpdateEmail(
$scope.currentUser.id,
$scope.profile.email
).then(function() { $scope.pendingUpdate -= 1; });
}
if ($scope.currentUser.hasPrivilege("full-profile")) {
$scope.pendingUpdate += 1;
UserService1.UpdateName(
$scope.currentUser.id,
$scope.profile.fname,
$scope.profile.lname
).then(function() { $scope.pendingUpdate -= 1; });

$scope.pendingUpdate += 1;
UserService1.UpdateNewsletter(
$scope.profile.id,
$scope.profile.newsletter
UserService1.UpdateEmail(
$scope.currentUser.id,
$scope.profile.email
).then(function() { $scope.pendingUpdate -= 1; });
}

$scope.profile.keys.forEach(function(key) {
if(key.type == 'pin' && key.pin) {
$scope.pendingUpdate += 1;
$scope.PinService1.UpdatePin(key.id, key.pin).then(function() {
$scope.pendingUpdate -= 1;
});
}
});

$scope.checkUpdated();
$scope.pendingUpdate -= 1;
$scope.pendingUpdate += 1;
UserService1.UpdateNewsletter(
$scope.profile.id,
$scope.profile.newsletter
).then(function() { $scope.pendingUpdate -= 1; });

$scope.profile.keys.forEach(function(key) {
if(key.type == 'pin' && key.pin) {
$scope.pendingUpdate += 1;
$scope.PinService1.UpdatePin(key.id, key.pin).then(function() {
$scope.pendingUpdate -= 1;
});
}
});

$scope.pendingUpdate += 1;
UserService1.UpdateExpiry(
$scope.profile.id,
$scope.profile.mem_expire
).then(function() { $scope.pendingUpdate -= 1; });

$scope.checkUpdated();
$scope.pendingUpdate -= 1;
});
};

$scope.checkUpdated = function() {
Expand Down Expand Up @@ -156,8 +162,14 @@ angular
}
});

$scope.updating = true;
$scope.pendingUpdate = 1;

PrivilegeService1.PutUserPrivileges(profile.id, codes).then(function(){
$scope.privilegeDirty = false;

$scope.checkUpdated();
$scope.pendingUpdate -= 1;
});
};

Expand Down Expand Up @@ -193,8 +205,14 @@ angular

if (membership == null) return;

$scope.updating = true;
$scope.pendingUpdate = 1;

UserService1.UpdateMembership(profile.id, membership.id).then(function(){
$scope.membershipDirty = false;

$scope.checkUpdated();
$scope.pendingUpdate -= 1;
});
};

Expand Down Expand Up @@ -230,8 +248,14 @@ angular

if (status == null) return;

$scope.updating = true;
$scope.pendingUpdate = 1;

UserService1.UpdateStatus(profile.id, status.code).then(function(){
$scope.statusDirty = false;

$scope.checkUpdated();
$scope.pendingUpdate -= 1;
});
};

Expand Down
Binary file added web/images/provider/pin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/images/provider/rfid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions web/providers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ angular
.then(function(response) {
return response.data;
});
},
UpdateExpiry: function(userid, date) {
return $http.post("/services/web/UserService1.svc/UpdateExpiry", {userid: userid, date: date})
.then(function(response) {
return response.data;
});
}
};
}]);
6 changes: 3 additions & 3 deletions web/user/getinvolved/getinvolved.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ <h1 class="page-header">Get involved!</h1>
<p>Great, here's how you can help</p>
<h3>Source Code</h3>
<p>The code for this web app (Nomos) is located on Github: </p>
<p><a href="https://github.com/vhs/membership-manager-pro">https://github.com/vhs/membership-manager-pro</a></p>
<p><a href="https://github.com/vhs/nomos">https://github.com/vhs/nomos</a></p>
<p>
It is a private repo, so you will need to be added to the VHS account. Contact Jarrett, Funvill, or
It is a private repo, so you will need to be added to the VHS account. Contact Jarrett, Laftho, Funvill, or
Garthomite on the forums to get access.
</p>

<h3>Development</h3>

<p>
Check the <a href="https://github.com/vhs/membership-manager-pro/wiki">Project GitHub wiki</a> for instructions on how to get started.
Check the <a href="https://github.com/vhs/nomos/wiki">Project GitHub wiki</a> for instructions on how to get started.
Nomos testing is done with a Vagrant file that automagically sets up a test VM with the proper settings.
</p>

Expand Down
Loading

0 comments on commit 01ea022

Please sign in to comment.