Skip to content

Commit

Permalink
Merge pull request #44 from spira/feature/module-pattern-refactor
Browse files Browse the repository at this point in the history
Module pattern refactor
  • Loading branch information
zakhenry committed Apr 6, 2016
2 parents 7b7bfc4 + 2890a5a commit d2f02bd
Show file tree
Hide file tree
Showing 48 changed files with 1,830 additions and 16,371 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules
reports
tmp
.idea
typings
dist
40 changes: 26 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
sudo: false #use container based infrastructure
sudo: false
language: node_js
node_js:
- "5.4.0"

- 5.4.1
addons:
apt:
sources:
- libnotify-bin

- libnotify-bin
cache:
directories:
- node_modules
- bower_components

- 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:
- gulp 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=
env:
global:
secure: fR7p8Kvm6kvnh9A/o0UKFAIp7Bi/v8JsytkUfBo6zhQM7W2s26wmLIz87fowq7icVSbQ3ICh1jTyN50THyBkwXUYERNkqy5IfK0MZFE8UixWUH9b4XhW9LXfxwqfhqwGFEz7Ebm/0jlbpF+A6qOWhgt8LYfJ1yEcj9RxIomlwYPflCDxECQ545/AxMXoDNkh/qvQdwzO20pmfQFRfYtAtFmWKcAsQOuA00SpkH/3LP/Bg6OGF50SozFbj7/dSW7y8quLqUh48AWSbufOwB8ZPZRf9qV0SfunC5Feo3/ZnJ9kodJUjqwVZ90XZwSeH7dS0tDUqNn4KbQHFyyGboABR1eov/F8xOZqq5utLwqd0iAGQDWS+EQMZyRrLD5yFIqu28i+TRKoWJNSvY2QOIeoSTOEufk7Z5Scj88j273b19eclWQE5ztc9zfpWggquzp3RcSKinXC7OWvTdLFGcBb0wgbq0hzx431AsdcFd/81WptJZgIeMWzMT7zqQznhUn6lIGn7/mMyS4DADfJkYSRqcAYIySvgjCteFfmrURU2TJTtBZ9z0cHIXGm0n1cFftNHcvNSenqjX8S3w4uaTLYtVkoxFiZUd6R9hNnz2AnISTBKsn63qLym/4Q1+n3sjYMNbxNaplav66YjuFN5fuVXDyzmLCV51CX8mmqT4X29Ck=
3 changes: 0 additions & 3 deletions .yo-rc.json

This file was deleted.

112 changes: 56 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
Expand Down Expand Up @@ -102,95 +107,89 @@ 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, [])
Expand All @@ -201,4 +200,5 @@ namespace app.guest.login {
```

## Todo
Better documentation with examples in javascript.
* Better documentation with examples in typescript.
* Site hosted on github showing off examples with material
26 changes: 0 additions & 26 deletions bower.json

This file was deleted.

Loading

0 comments on commit d2f02bd

Please sign in to comment.