Skip to content

dflourusso/ng-tiddle

Repository files navigation

Ng Tiddle Auth

A simple implementation to integrate with the Rails Gem Tiddle


Installation

$ bower install ng-tiddle --save

Usage

Include the plugin in your application:

<script src="../dist/ng-tiddle.js"></script>`

And then include the AngularJs module:

angular.module('app', ['ng-tiddle']);

Configuration

Provider

Create a AngularJs run to set ngTiddleAuthProvider configurations.

angularApp.run(['ngTiddleAuthProvider', function(ngTiddleAuthProvider) {
    return ngTiddleAuthProvider.setApiRoot('http://localhost:3000');
  }
])

Available options:

  • ApiRoot -> API url used to authentication:

    ngTiddleAuthProvider.setApiRoot('http://localhost:3000');
  • SignInStrategy -> Devise strategy used to authentication. Default: email:

    ngTiddleAuthProvider.setSignInStrategy('email');
  • ApiResourcePath -> Url path used to authentication:

    ngTiddleAuthProvider.setApiResourcePath('users');
  • ModelName -> Name of your model:

    ngTiddleAuthProvider.setModelName('user');
  • KeepLoggedIn -> Set 'true', to keep logged after close and reopen the browser:

    ngTiddleAuthProvider.setKeepLoggedIn('true');
  • onUnauthorized: -> Callback to be called when the application receive some response with code 401 - Unauthorized from the server:

    ngTiddleAuthProvider.onUnauthorized = function(){$location.path('/auth/login');}
  • onAuthorize: -> Callback a ser executado quando login for realizado com sucesso.

    ngTiddleAuthProvider.onAuthorize = function(auth_data){
      $location.path('/app/home');
    }

Using the services

ngTiddleAuthService

Do SignIn:

ngTiddleAuthService.signIn({email: '', password: ''});

Do SignOut:

ngTiddleAuthService.signOut();

ngTiddleSessionService

Get user logged:

ngTiddleSessionService.getResource();

Author

Daniel Fernando Lourusso