This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
mongoose.Model.seed = function(entities) { | |
var promise = new mongoose.Promise; | |
this.create(entities, function(err) { | |
if(err) { promise.reject(err); } | |
else { promise.resolve(); } | |
}); | |
return promise; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(exports){ | |
exports.config = { | |
apiKey: "sgsag", | |
foo: "bar | |
}; | |
})(typeof exports === 'undefined'? this['routingConfig']={}: exports); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div accessLevel="{{ accessLevels.anon }}"> | |
<!-- ... Login stuff --> | |
</div> | |
<div accessLevel="{{ accessLevels.user }}"> | |
Welcome {{ user.name }}! | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.allowCrossDomain = function(req, res, next) { | |
var oneof = false | |
, clientUrl = 'http://myclient.com'; | |
if (req.headers.origin) { | |
res.header('Access-Control-Allow-Origin', clientUrl); | |
res.header('Access-Control-Allow-Credentials', true); | |
oneof = true; | |
} | |
if (req.headers['access-control-request-method']) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(exports){ | |
var userRoles = { | |
public: 1, // 001 | |
user: 2, // 010 | |
admin: 4 // 100 | |
}; | |
exports.userRoles = userRoles; | |
exports.accessLevels = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp', ['myApp.services', 'ngCookies']) | |
.config(['$routeProvider', '$locationProvider', | |
function ($routeProvider, $locationProvider) { | |
// ... | |
var access = routingConfig.accessLevels; | |
$routeProvider.when('/register', | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/*', function(req, res){ | |
var role = userRoles.public, username = ''; | |
if(req.user) { | |
role = req.user.role; | |
username = req.user.username; | |
} | |
res.cookie('user', JSON.stringify({ | |
'username': username, | |
'role': role |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('angular-client-side-auth') | |
.factory('Auth', function($http, $rootScope, $cookieStore){ | |
var accessLevels = routingConfig.accessLevels | |
, userRoles = routingConfig.userRoles | |
, currentUser = $cookieStore.get('user') || | |
{ username: '', role: userRoles.public }; | |
// ... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('angular-client-side-auth') | |
.factory('Auth', function($http, $rootScope, $cookieStore){ | |
// ... | |
$rootScope.accessLevels = accessLevels; | |
$rootScope.userRoles = userRoles; | |
return { | |
authorize: function(accessLevel, role) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('angular-client-side-auth', ['ngCookies']) | |
.run(['$rootScope', '$location', 'Auth', function ($rootScope, $location, Auth) { | |
$rootScope.$on("$routeChangeStart", function (event, next, current) { | |
if (!Auth.authorize(next.access)) { | |
if(Auth.isLoggedIn()) $location.path('/'); | |
else $location.path('/login'); | |
} | |
}); |
OlderNewer