Skip to content

Commit

Permalink
Add allow all emails option to admin settings techx#15
Browse files Browse the repository at this point in the history
Add allow/dissallow all emails button in the admin settings panel.
  • Loading branch information
jeremy-melnyk committed Oct 28, 2017
1 parent 851e1c9 commit 9fb3da3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/client/src/services/SettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ angular.module('reg')
allowMinors: allowMinors
});
},
updateAllowAllEmails: function(allowAllEmails){
return $http.put(base + 'allEmails', {
allowAllEmails: allowAllEmails
});
},
};

}
Expand Down
12 changes: 12 additions & 0 deletions app/client/views/admin/settings/adminSettingsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ angular.module('reg')
});
};

$scope.updateAllowAllEmails = function () {
SettingsService
.updateAllowAllEmails($scope.settings.allowAllEmails)
.success(function (data) {
$scope.settings.allowAllEmails = data.allowAllEmails;
const successText = $scope.settings.allowAllEmails ?
"All emails are now allowed to register." :
"Only whitelisted emails are now allowed to register."
swal("Looks good!", successText, "success");
});
};

// Whitelist --------------------------------------

SettingsService
Expand Down
11 changes: 11 additions & 0 deletions app/client/views/admin/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@
<label>Allow minors</label>
</div>
</div>
<div class="field">
<div class="ui toggle checkbox">
<input
type="checkbox"
name="allowAllEmails"
ng-class="{true: 'checked', false: ''}[settings.allowAllEmails]"
ng-model="settings.allowAllEmails"
ng-change="updateAllowAllEmails()">
<label>Allow all emails</label>
</div>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions app/server/models/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ var schema = new mongoose.Schema({
},
allowMinors: {
type: Boolean
},
allowAllEmails: {
type: Boolean
}
});

Expand Down
13 changes: 13 additions & 0 deletions app/server/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,17 @@ module.exports = function(router) {
SettingsController.updateField('allowMinors', allowMinors, defaultResponse(req, res));
});

/**
* [ADMIN ONLY]
* {
* allowAllEmails: Boolean
* }
* res: Settings
*
*/
router.put('/settings/allEmails', isAdmin, function(req, res){
var allowAllEmails = req.body.allowAllEmails;
SettingsController.updateField('allowAllEmails', allowAllEmails, defaultResponse(req, res));
});

};

0 comments on commit 9fb3da3

Please sign in to comment.