Permalink
Browse files

Completed implementation of gulpfile to handle the new module pattern…

…, ignored dist dir, implemented travis deployment with pr-bumper checker, reverted package name, removed redundant webpack configs, updated examples & readme
  • Loading branch information...
1 parent 4ef05c8 commit 103cb1e62ce408340c5ecb347abcdd923f54e6c3 @zakhenry zakhenry committed Apr 6, 2016
View
@@ -4,4 +4,5 @@ node_modules
reports
tmp
.idea
-typings
+typings
+dist
View
@@ -1,23 +1,41 @@
-sudo: false #use container based infrastructure
+sudo: false
language: node_js
node_js:
- - "5.4.1"
-
+- 5.4.1
addons:
apt:
sources:
- - libnotify-bin
+ - libnotify-bin
cache:
directories:
- - node_modules
+ - node_modules
+
+branches:
+ except:
+ - /^v[0-9\.]+/
+
+before_install:
+ - npm install -g pr-bumper
+ - pr-bumper check
install:
- - travis_retry npm install -g gulp
- - travis_retry npm install
+- travis_retry npm install -g gulp
+- travis_retry npm install
script:
- - npm test
+- npm test
+- npm run build
after_script:
- - gulp coveralls
+- gulp coveralls
+
+before_deploy:
+ - pr-bumper bump
+
+deploy:
+ provider: npm
+ on:
+ tags: true
+ api_key:
+ secure: aQCcMzb4VCbedVdkz75n7/hN+ovFz8iOKdApcA1VvyP2j/CudOyCbTr8BGB48K7YTs83ZYWeTSXSU/lC3/b8Z8C768nWW6gK9e15lx5+ENFBfMyRI5CY84z6AfW3dNB3vmUObKeEACSJGuchldKtPE1B2+Ysmw5h9qH9kEjoJpRxMalg2bSlbvA1ZMPjnLk4Mr0sOVPGtQaEtR7VZOmpQNxPfyTDEAFxZlMYjJOWFpH9987tkgyYmTI9n5J74zb8hQLwLEJ3D7GWOf/skJ37/IDOsqpncxOGGvqrvvC1uCJHAPm/Qx1vbrILv8bU5b08kfBP8Zbkf/4qfH/N7eeBu32CUU3yXCVh1WKW/eSeBwq7giP0YXPlEiFZrWVNdzJc2vmdR4ZihgTL2OOj+ThYIGhZWaJRhYUBOrJRYM5nhDkudOcDEylH3hLrLVZnzHJDrZ2yAtLyOfqRmHLTwITTEMO+RvzD5oPoYX69ZJ6EBn18Fr6LHlM1Xo3WlwuXugdC76fUM1UxtmW0OKNROCXF+zUHxc8lOBBHLhsI1pLR5R/khj1zuQwhYp5YL+ly2lxWhCR9DSySBWbbW4Yj7m8e0Sg7gKkcvx9JTzHSkcWfnvRJDXDk0FMZF9S71ldBwgPH2s9FjjU4lXMf0PglvTcJbQIxT/byMZCEnarFb3Fqe5s=
View
@@ -19,25 +19,30 @@ The module has the following features
## Installation
-Install through bower:
+Install through npm:
```sh
-bower install angular-jwt-auth --save
+npm install angular-jwt-auth --save
```
## Usage
* Require the `ngJwtAuth` module in your angular application
-```js
+```ts
+import "angular"
+import "angular-jwt-auth"
angular.module('app', ['ngJwtAuth'])
```
* (Optionally) configure the service provider
-```js
+```ts
+
+import {NgJwtAuthServiceProvider} from "angular-jwt-auth"
+
angular.module('app', ['ngJwtAuth'])
-.config(['ngJwtAuthServiceProvider', function(ngJwtAuthServiceProvider){
+.config(['ngJwtAuthServiceProvider', function(ngJwtAuthServiceProvider:NgJwtAuthServiceProvider){
ngJwtAuthServiceProvider
.configure({
tokenLocation: 'token-custom',
@@ -60,7 +65,7 @@ It is _highly_ recommended that you register a login prompt factory (See below),
this will allow the interceptor to prompt your users for their login details when an api
request that returns status code 401.
-```js
+```ts
angular.module('app', ['ngJwtAuth'])
.run(['ngJwtAuthService', function(ngJwtAuthService){
ngJwtAuthService.init();
@@ -96,101 +101,96 @@ Full typescript example from the [Spira](https://github.com/spira/spira) project
Note this example is in typescript, but it is the same process in plain javascript.
```ts
-namespace app.guest.login {
+
+ namespace app.guest.login {
export const namespace = 'app.guest.login';
class LoginConfig {
- static $inject = ['ngJwtAuthServiceProvider'];
-
- constructor(private ngJwtAuthServiceProvider:NgJwtAuth.NgJwtAuthServiceProvider) {
-
- let config:NgJwtAuth.INgJwtAuthServiceConfig = {
- refreshBeforeSeconds: 60 * 10, //10 mins
- checkExpiryEverySeconds: 60, //1 min
- apiEndpoints: {
- base: '/api/auth/jwt',
- login: '/login',
- tokenExchange: '/token',
- refresh: '/refresh',
- },
- };
-
- ngJwtAuthServiceProvider.configure(config);
-
+ static $inject:string[] = ['ngJwtAuthServiceProvider',];
+ constructor(private ngJwtAuthServiceProvider:NgJwtAuthServiceProvider) {
+
+ ngJwtAuthServiceProvider
+ .configure({
+ tokenLocation: 'token-custom',
+ apiEndpoints: {
+ base: '/api',
+ login: '/login-custom',
+ tokenExchange: '/token-custom',
+ refresh: '/refresh-custom',
+ }
+ });
+
}
}
- export class LoginController {
-
- public socialLogin;
-
+ class LoginController {
+
static $inject = ['$rootScope', '$mdDialog', '$mdToast', 'ngJwtAuthService', 'deferredCredentials', 'loginSuccess', 'userService'];
-
constructor(private $rootScope:global.IRootScope,
private $mdDialog:ng.material.IDialogService,
private $mdToast:ng.material.IToastService,
- private ngJwtAuthService:NgJwtAuth.NgJwtAuthService,
+ private ngJwtAuthService:NgJwtAuthService,
private deferredCredentials:ng.IDeferred<NgJwtAuth.ICredentials>,
private loginSuccess:{promise:ng.IPromise<NgJwtAuth.IUser>},
private userService:common.services.user.UserService) {
-
+
this.handleLoginSuccessPromise();
-
+
}
-
+
/**
* Register the login success promise handler
*/
private handleLoginSuccessPromise() {
-
+
//register error handling and close on success
this.loginSuccess.promise
.then(
- (user) => this.$mdDialog.hide(user), //on success hide the dialog, pass through the returned user object
- null,
- (err:Error) => {
- if (err instanceof NgJwtAuth.NgJwtAuthCredentialsFailedException) {
- this.$mdToast.show(
- (<any>this.$mdToast).simple()
- .hideDelay(2000)
- .position('top')
- .content(err.message)
- .parent('#loginDialog')
- );
- } else {
- console.error(err);
+ (user) => this.$mdDialog.hide(user), //on success hide the dialog, pass through the returned user object
+ null,
+ (err:Error) => {
+ if (err instanceof NgJwtAuthCredentialsFailedException) {
+ this.$mdToast.show(
+ (<any>this.$mdToast).simple()
+ .hideDelay(2000)
+ .position('top')
+ .content(err.message)
+ .parent('#loginDialog')
+ );
+ } else {
+ console.error(err);
+ }
}
- }
- );
+ );
}
-
+
/**
* allow the user to manually close the dialog
*/
public cancelLoginDialog() {
this.ngJwtAuthService.logout(); //make sure the user is logged out
this.$mdDialog.cancel('closed');
}
-
+
/**
* Attempt login
* @param username
* @param password
*/
public login(username, password) {
-
- let credentials:NgJwtAuth.ICredentials = {
+
+ let credentials:ICredentials = {
username: username,
password: password,
};
-
+
this.deferredCredentials.notify(credentials); //resolve the deferred credentials with the passed creds
-
+
}
-
+
}
angular.module(namespace, [])
View
@@ -1,9 +0,0 @@
-{
- "name": "test",
- "description": "testing our component",
- "main": "index.html",
- "private": true,
- "dependencies": {
- "angular-jwt-auth": "~0.0.0"
- }
-}
View
@@ -0,0 +1,105 @@
+/**
+ * This is an example of all the base features of the ngJwtAuth service.
+ * @todo A full demo running in github.io would be preferred
+ */
+import "angular"
+import "angular-material"
+
+// import {NgJwtAuthServiceProvider} from "angular-jwt-auth"
+import {NgJwtAuthServiceProvider} from "../dist"
+import {NgJwtAuthCredentialsFailedException} from "../src/provider/ngJwtAuthServiceProvider";
+import {NgJwtAuthService} from "../src/service/ngJwtAuthService";
+import {ICredentials} from "../src/ngJwtAuthInterfaces";
+
+class ExampleConfig {
+
+ static $inject:string[] = ['ngJwtAuthServiceProvider',];
+ constructor(private ngJwtAuthServiceProvider:NgJwtAuthServiceProvider) {
+
+ ngJwtAuthServiceProvider
+ .configure({
+ tokenLocation: 'token-custom',
+ apiEndpoints: {
+ base: '/api',
+ login: '/login-custom',
+ tokenExchange: '/token-custom',
+ refresh: '/refresh-custom',
+ }
+ });
+
+ }
+
+}
+
+class ExampleController {
+
+ static $inject = ['$rootScope', '$mdDialog', '$mdToast', 'ngJwtAuthService', 'deferredCredentials', 'loginSuccess', 'userService'];
+ constructor(private $rootScope:global.IRootScope,
+ private $mdDialog:ng.material.IDialogService,
+ private $mdToast:ng.material.IToastService,
+ private ngJwtAuthService:NgJwtAuthService,
+ private deferredCredentials:ng.IDeferred<NgJwtAuth.ICredentials>,
+ private loginSuccess:{promise:ng.IPromise<NgJwtAuth.IUser>},
+ private userService:common.services.user.UserService) {
+
+ this.handleLoginSuccessPromise();
+
+ }
+
+ /**
+ * Register the login success promise handler
+ */
+ private handleLoginSuccessPromise() {
+
+ //register error handling and close on success
+ this.loginSuccess.promise
+ .then(
+ (user) => this.$mdDialog.hide(user), //on success hide the dialog, pass through the returned user object
+ null,
+ (err:Error) => {
+ if (err instanceof NgJwtAuthCredentialsFailedException) {
+ this.$mdToast.show(
+ (<any>this.$mdToast).simple()
+ .hideDelay(2000)
+ .position('top')
+ .content(err.message)
+ .parent('#loginDialog')
+ );
+ } else {
+ console.error(err);
+ }
+ }
+ );
+ }
+
+ /**
+ * allow the user to manually close the dialog
+ */
+ public cancelLoginDialog() {
+ this.ngJwtAuthService.logout(); //make sure the user is logged out
+ this.$mdDialog.cancel('closed');
+ }
+
+ /**
+ * Attempt login
+ * @param username
+ * @param password
+ */
+ public login(username, password) {
+
+ let credentials:ICredentials = {
+ username: username,
+ password: password,
+ };
+
+ this.deferredCredentials.notify(credentials); //resolve the deferred credentials with the passed creds
+
+ }
+
+}
+
+angular.module('example', [
+ 'ngJwtAuth',
+ ])
+ .config(ExampleConfig)
+ .controller('ExampleController', ExampleController);
View
@@ -1,10 +0,0 @@
-<html>
-<head>
- <script src="bower_components/angular-jwt-auth/dist/main.js"></script>
- <script>
- AngularJwtAuth.init();
- </script>
-</head>
-<body>
-</body>
-</html>
Oops, something went wrong.

0 comments on commit 103cb1e

Please sign in to comment.