Skip to content

Instantly share code, notes, and snippets.

@simonmorley
Last active August 29, 2015 14:13
Show Gist options
  • Save simonmorley/675b9e5c7e7583d92ebf to your computer and use it in GitHub Desktop.
Save simonmorley/675b9e5c7e7583d92ebf to your computer and use it in GitHub Desktop.
Medium, creating a splash, welcome directive
app.directive('welcome', ['$routeParams', '$location', '$window', 'Login', '$timeout', function($routeParams, $location, $window, Login, $timeout) {
var link = function(scope,element,attrs) {
scope.loading = true;
var request_uri = $location.host();
var apMac = $routeParams.mac || $routeParams.sip;
Login.welcome({request_uri: request_uri, mac: apMac}).$promise.then(function(results) {
scope.loading = undefined;
scope.welcome = results.welcome;
if (results.timeout > 0) {
var timeout = results.timeout * 1000;
var redirectTo = results.success_url || 'https://google.com';
$timeout(function() {
$window.location.href = redirectTo;
},timeout);
}
});
};
return {
link: link,
replace: true,
scope: false,
template: '<div><p ng-bind-html="welcome"></p></div>'
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment