Skip to content

Commit

Permalink
Integrated User Member Edit page with backend. (#112)
Browse files Browse the repository at this point in the history
* show member page to currently logged in user

* show member page to currently logged in user

* semicolon

* user object to string

* things to make angualr behave

* filepath fix

* filepath fix

* dev

* semicolon

* waiting on Angular to get out of the way

* Fixing submit with Angular

* Fixing submit with Angular

* Fixing submit with Angular

* Fixing submit with Angular

* Fixing submit with Angular

* Fixing submit with Angular

* dev

* Fixing submit with Angular

* Fixing submit with Angular

* removing material

* make admin edit fields not required

* more remove material edits

* panel for payment info

* more stuff

* full removal of angular

* add redirect back

* more edits

* Fixing submit

* add redirect back

* Fixing submit

* add redirect back

* Fixing submit
  • Loading branch information
cmowenby authored Apr 3, 2017
1 parent 8166f60 commit f4e63e0
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<div class="form-group">
<label for="rfidNumber" class="control-label">RFID Number</label>
<input required name="rfidNumber" class="form-control" value="<?php echo $user->getCustomSchemas()['roles']['rfid-id'];?>">
<input name="rfidNumber" class="form-control" value="<?php echo $user->getCustomSchemas()['roles']['rfid-id'];?>">
</div>

<div class="form-group">
Expand All @@ -60,7 +60,7 @@

<div class="form-group">
<label for="subscriptionExp" class="control-label">Subscription Expiration Date</label>
<input required type="date" name="subscriptionExp" class="form-control" value= <?php echo $expDate; ?> >
<input type="date" name="subscriptionExp" class="form-control" value= <?php echo $expDate; ?> >
</div>

<button class="mas-button" type="submit">Save Changes</button>
Expand All @@ -76,5 +76,4 @@
?>
</div>
</div>

</body>
5 changes: 5 additions & 0 deletions front-end-pages/member-page/member-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ img {
font-weight: bold;
padding: 10px;
margin-bottom: 10px;
}

.panel-info .panel-heading {
color: white !important;
background-color: #0085A7 !important;
}
184 changes: 81 additions & 103 deletions front-end-pages/member-page/member-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

$admin_post = admin_url( 'admin-post.php' );

include_once dirname(__DIR__).'../../../resources/GSuiteAPI.php';
include_once dirname(__DIR__).'../../../resources/StripeAPI.php';
require_once dirname(__DIR__).'/resources/GSuiteAPI.php';
require_once dirname(__DIR__).'/resources/StripeAPI.php';

$email = wp_get_current_user()->user_email;

#TODO: get email from currently logged in wp user
$email = 'apb@decaturmakers.org';
$user = getUser($email);
$firstName = $user->getName()->getGivenName();
$lastName = $user->getName()->getFamilyName();
$personalEmail = $user->getEmails()[0]['address'];
$sub_mgmt = $user->getCustomSchemas()['Subscription_Management'];
$stripe_id = !empty($sub_mgmt['Stripe_ID']) ? $sub_mgmt['Stripe_ID'] : '';
$dm_email = $user->getPrimaryEmail();


$card;
Expand All @@ -20,106 +24,80 @@
}
?>

<!--
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
-->

<!-- <script src="../member-page/member-page.js"></script>
The script is all set in this file but needs to be special phped to be accessed correctly.
Therefore it is also below just for deving.
-->
<script language="javascript">
angular
.module('memberProfile', ['ngMaterial'])
.controller('DemoCtrl', function($scope) {
$scope.editing = false;
});
</script>

<div ng-app="memberProfile" ng-controller="DemoCtrl">

<div class="mas-title">
Welcome, <?php echo $user->getName()->getFullName(); ?>!
</div>

<div layout="row" layout-sm="column">
<div flex>
<div style="text-align:center">
<?php
echo '<img src="' . plugins_url( '../images/female-placeholder.png', __FILE__ ) . '" id="profilePic" alt="Profile Picture">' . "\n";
<div>
<div class="row">
<div class="mas-title col-md-12">
Welcome, <?php echo $user->getName()->getFullName(); ?>!
</div>
</div>

<div class="row">
<!-- PICTURE, BUTTONS -->
<div style="text-align: center" class="col-md-4">
<?php echo '<img src="' . plugins_url( '../images/female-placeholder.png', __FILE__ ) . '" id="profilePic" alt="Profile Picture">' . "\n";
?>
<br>
<button type="edit" class="btn mas-button" ng-click="editing = true" ng-show="editing == false">Edit Profile</button>
<button type="save" class="btn mas-button" ng-click="editing = false" ng-show="editing == true">Save Changes</button>
<br>
<button type="password" class="btn mas-button">Change Password</button>
<br>
<button type="password" class="btn mas-button">Change Password</button>
</div>

<!-- PERSONAL INFO FORM -->
<div style="text-align: center" class="col-md-4">
<form name="userForm" method="POST" action="<?php echo admin_url( 'admin-post.php') ?>">
<div class="form-group">
<label for="firstName">First Name</label>
<input name="firstName" class="form-control" value="<?php echo $firstName; ?>">
</div>

<div class="form-group">
<label for="lastName">Last Name</label>
<input name="lastName" class="form-control" value="<?php echo $lastName; ?>">
</div>

<div class="form-group">
<label for="inputEmail" class="control-label">Personal Email</label>
<input type="email" name="personalEmail" class="form-control" id="inputEmail" placeholder="Email" required value="<?php echo $personalEmail; ?>">
</div>
</div>

<div flex id="inputContainer" class="inputDemo" ng-cloak>
<md-content layout-padding>
<form name="projectForm">
<md-input-container class="md-block">
<label>First Name</label>
<input required name="firstName" ng-model="project.firstName" ng-disabled="!editing">
<div ng-messages="projectForm.firstName.$error">
<div ng-message="required">This is required.</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>Last Name</label>
<input required name="lastName" ng-model="project.lastName" ng-disabled="!editing">
<div ng-messages="projectForm.lastName.$error">
<div ng-message="required">This is required.</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>Personal Email</label>
<input required type="email" name="userEmail" ng-model="project.userEmail"
minlength="10" maxlength="100" ng-pattern="/^.+@.+\..+$/" ng-disabled="!editing"/>
<div ng-messages="projectForm.userEmail.$error" role="alert">
<div ng-message-exp="['required', 'minlength', 'maxlength', 'pattern']">
Your email must be between 10 and 100 characters long and should be a valid email address.
</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>DM Email</label>
<input required type="email" name="dmEmail" ng-model="project.dmEmail" disabled/>
</md-input-container>
</form>
</md-content>
</div>

<div flex style="text-align:center">
<div class="mas-title">
Member Payment Information
</div>
<md-content layout-padding>
<form name="paymentInformation">
<md-input-container class="md-block">
<label>Last 4 Digits: <?php echo $card->last4; ?></label>
<input required type="card" name="cardNum" ng-model="project.cardNum" disabled/>
</md-input-container>
<md-input-container class="md-block">
<label>Expiration Date: <?php echo $card->exp_month."/".$card->exp_year; ?></label>
<input required type="date" name="expirationDate" ng-model="project.expirationDate" disabled/>
</md-input-container>
<md-input-container class="md-block">
<label>Card Type: <?php echo $card->brand; ?></label>
<input required type="brand" name="cardBrand" ng-model="project.cardBrand" disabled/>
</md-input-container>
<input type="hidden" value="<?php echo $stripe_id ?>" name="customer-id">
<input type="hidden" name="action" value="update_card">
<?php getStripeUpdateCard($email); ?>
</form>
</md-content>

</div>
<div class="form-group">
<label class="dmEmail">DM Email</label>
<input type="text" class="form-control" id="username" value="<?php echo $dm_email; ?>" disabled>
</div>

<input type="hidden" name="action" value="update_self">

<button type="submit" class="btn mas-button">Update Info</button>
</form>
</div>

<!-- PAYMENT INFO -->
<div style="text-align: center" class="panel panel-default col-md-4">

<div class="panel-heading">
<h3 class="panel-title mas-title">Card Details</h3>
</div>

<div class="panel-body">
<form name="payment">
<div class="form-group">
<label for="cardNum">Last 4 Digits:</label>
<input type="card" name="cardNum" class="form-control" disabled value="****-****-****-<?php echo $card->last4; ?>">
</div>

<div class="form-group">
<label for="expirationDate">Expiration Date:</label>
<input required type="text" name="expirationDate" class="form-control" disabled value="<?php echo $card->exp_month."/".$card->exp_year; ?>" />
</div>

<div class="form-group">
<label for="cardBrand">Card Type:</label>
<input required type="brand" name="cardBrand" class="form-control" disabled value=" <?php echo $card->brand; ?>" />
</div>

<input type="hidden" value="<?php echo $stripe_id ?>" name="customer-id">
<input type="hidden" name="action" value="update_card">
<?php getStripeUpdateCard($personalEmail); ?>
</form>
</div>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion postable/admin-member-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


function prefix_admin_update_member() {
error_log("Function Called");

$username = $_POST['username'];

$firstName = $_POST['firstName'];
Expand Down
1 change: 1 addition & 0 deletions postable/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
// Including postable actions
include_once plugin_dir_path( __FILE__ ) . 'update-card.php';
include_once plugin_dir_path( __FILE__ ) . 'admin-member-edit.php';
include_once plugin_dir_path( __FILE__ ) . 'user-member-edit.php';
36 changes: 36 additions & 0 deletions postable/user-member-edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

defined( 'ABSPATH' ) or die();

require_once dirname(__DIR__).'/front-end-pages/resources/GSuiteAPI.php';

// Adding the action to the wordpress hooks
add_action('admin_post_update_self', 'prefix_user_update_self');


function prefix_user_update_self() {

$username = wp_get_current_user()->user_email;

$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$personalEmail = $_POST['personalEmail'];


$properties = array(
'name' => array(
'givenName' => $firstName,
'familyName' => $lastName
),
'emails' => array(
array(
'address' => $personalEmail
)
)
);

updateUser($username, $properties);

wp_redirect('member');
exit("User updated succesfully");
}

0 comments on commit f4e63e0

Please sign in to comment.