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
<!DOCTYPE html> | |
<html data-ng-app="angular-client-side-auth" lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Angular Auth Example</title> | |
<link href="/css/app.css" rel="stylesheet"> | |
<link href="/components/bootstrap/dist/css/bootstrap.min.css" rel= | |
"stylesheet"> |
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
// First creates a shallow copy of array, | |
// then shifts contents circularly according to | |
// number of steps and direction given | |
function circularShift(arrayPar, steps, shiftLeft) { | |
var array = arrayPar.slice(0); | |
for(var i = 0; i < steps; i++) { | |
if(shiftLeft) | |
array.push(array.shift()); | |
else |
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
import SystemConfiguration | |
public class Reachability { | |
class func isConnectedToNetwork() -> Bool { | |
var zeroAddress = sockaddr_in() | |
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress)) | |
zeroAddress.sin_family = sa_family_t(AF_INET) | |
let defaultRouteReachability = withUnsafePointer(&zeroAddress) { | |
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) | |
} |
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
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('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 |
OlderNewer