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
### | |
I have an AngularJS application that requires authentication. It's | |
part of a larger project served from Express and lives at its own | |
base path: `<base href="/path/to/app/">`, not `/`. The existing | |
application already has a round trip login. Users need to be logged | |
in before they can access the Angular app. This works fine, except | |
for e2e testing with testacular. | |
With authentication on the server disabled, e2e tests run without | |
problems. For example: |
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
describe('SomeService', function () { | |
var SomeService, $window; | |
beforeEach(module('app.services')); | |
beforeEach(inject(function ($injector) { | |
SomeService = $injector.get('SomeService'); | |
$window = $injector.get('$window'); | |
})); |
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('app.services') | |
.factory('SomeService', function ($q, $http) { | |
function withQuery(path, options) { | |
if (options) { | |
var params = []; | |
for (var key in options) { | |
params.push(key + '=' + options[key]); | |
} |
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
User.create = function (data, callback) { | |
var user = new User(data) | |
, validation = user.validate(); | |
if (!user.id) { user.id = uuid.v4(); } | |
if (!user.created) { user.created = Date.now() } | |
if (!validation.valid) { return callback(validation); } | |
async.parallel({ |
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
'use strict'; | |
angular.module('authentication') | |
.factory('CurrentUser', function ($http, $location) { | |
function CurrentUser () {} | |
CurrentUser.isAuthenticated = false; | |
CurrentUser.requiresAuthentication = false; |
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 express = require('express') | |
, RedisStore = require('connect-redis')(express) | |
, authorize = require('oauth2resource')({ | |
uri: 'https://authserver.tld/access', | |
cache: new RedisStore({ prefix: 'auth' }) | |
}).authorize | |
, app = express(); | |
app.configure(function () { |
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 dependencies | |
*/ | |
var _ = require('underscore') | |
, validate = require('../lib/validate'); | |
/** | |
* User constructor |
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 _ = require('underscore') | |
, fs = require('fs') | |
, path = require('path') | |
, crypto = require('crypto') | |
; | |
function JSONFile (config) { | |
this.config = config; |
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
# ... | |
practice () | |
{ | |
practicedir=~/Projects/practice/$(date +%Y-%m-%d)/$1 | |
mkdir -p $practicedir && cd $practicedir | |
echo "" | |
echo "Welcome to $practicedir" | |
echo "" | |
echo "May you become less dumb through deliberate practice." |
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
sip = 1 | |
slurp = 2 | |
gulp = 3 | |
class EarlyRiser | |
constructor: (@config) -> | |
@caffeinated = false | |
@cupsRequired = @config.cupsRequired | |
@cupsConsumed = |
OlderNewer