Skip to content

Commit

Permalink
Finished subscribe button
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwohlbruck committed May 16, 2019
1 parent 440679c commit e7a05b7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/routes/recipient.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ router.delete('/me', isAuthenticated, async (req, res) => {

const submittedCode = req.query.verificationCode.trim();
const verificationCode = await VerificationCode.findOne({code: submittedCode});
const number = verificationCode.data;
const number = verificationCode ? verificationCode.data : undefined;

if (!verificationCode || !verificationCode.user.equals(req.user._id)) {
return res.status(403).json({
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<md-icon class="material-icons">arrow_back</md-icon>
</md-button>

<md-menu md-position-mode="target-left target" ng-if="authenticatedUser">
<md-menu md-position-mode="target-left target">
<span
class="title pointer"
ng-mouseover="$mdMenu.open()"
Expand Down
27 changes: 21 additions & 6 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,26 @@ app.run(['$rootScope', '$state', '$window', '$location', '$mdToast', 'ApiService
};

$rootScope.toast = function(options) {
$mdToast.show(
$mdToast.simple()
.textContent(options.message)
.position('bottom right')
.hideDelay(5000)
);
if (options.action && options.actionText) {
$mdToast.show(
$mdToast.simple()
.textContent(options.message)
.action(options.actionText)
.highlightAction(true)
.position('bottom right')
.hideDelay(10000)
).then(response => {
if (response === 'ok') {
options.action();
}
});
} else {
$mdToast.show(
$mdToast.simple()
.textContent(options.message)
.position('bottom right')
.hideDelay(5000)
);
}
};
}]);
10 changes: 7 additions & 3 deletions public/js/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ app.controller('HomeCtrl', ['$scope', '$rootScope', '$http', '$state', '$window'
$http.defaults.useXDomain = true;

$scope.openApp = function() {
$state.go('facts');
};

$scope.signIn = function() {
if ($rootScope.authenticatedUser) {
$state.go('facts');
$scope.openApp();
} else {
$window.location.href = '/auth/google';
}
Expand Down Expand Up @@ -43,7 +47,7 @@ app.controller('HomeCtrl', ['$scope', '$rootScope', '$http', '$state', '$window'

ApiService.unsubscribe($scope.code).then(res => {
$rootScope.toast({message: res.data.message});
$mdDialog.close();
$mdDialog.hide();
}, err => {
$rootScope.toast({
message: err.data.message || "Error unsubscribing"
Expand Down Expand Up @@ -72,7 +76,7 @@ app.controller('HomeCtrl', ['$scope', '$rootScope', '$http', '$state', '$window'
method: 'GET',
url: 'https://api.imgur.com/3/gallery/r/cats',
headers: {
'Authorization': 'Client-ID 9350ca7bffa3250'
'Authorization': 'Client-ID 160806899cb2d43'
}
}).then(function(response) {
var images = response.data.data;
Expand Down
14 changes: 13 additions & 1 deletion public/js/controllers/recipients.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,19 @@ app.controller('RecipientsCtrl', ['$scope', '$rootScope', '$state', 'ApiService'
};

function getMyRecipients() {
$scope.promise = ApiService.getMyRecipients({animalType: $state.params.animal}).then(response => {
if (!$rootScope.authenticatedUser) {
$rootScope.toast({
message: "Sign in to access this page",
actionText: "Sign in",
action: function() {
window.location.replace('/auth');
}
});
}

$scope.promise = ApiService.getMyRecipients({
animalType: $state.params.animal
}).then(response => {
$scope.recipients = response.data;
}, err => {
$rootScope.toast({message: err.data.message});
Expand Down
7 changes: 5 additions & 2 deletions public/views/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span id="app-slogan" class="md-headline">{{fact}}</span>
<div id="call-to-action" layout="row">
<md-button
ng-click=""
ng-click="signIn()"
class="md-button md-raised md-primary">

Sign in
Expand All @@ -16,7 +16,10 @@
Open App
</md-button>

<md-button ng-click="openUnsubscribe()" class="md-button">
<md-button
ng-click="openUnsubscribe()"
class="md-button md-raised md-accent">

Unsubscribe
</md-button>
</div>
Expand Down

0 comments on commit e7a05b7

Please sign in to comment.