ckc-angularjs-auth

An Angularjs module for authentication with JSON web tools

Added by: Sam Deering

GitHub

Repository

ckelsey/ckc-angularjs-auth

Stats

Stars: 0

Watchers: 0

Forks: 0

Module Description

ckc-angularjs-auth

An Angularjs module for a phpSlim based API authentication

###Example ####HTML

<form ng-submit="app.Auth.login(user)">
    <div class="form-group">
        <label>Username (testuser)</label>
        <input class="form-control" ng-model="user.username" type="text" style="display:block;" />
    </div>
    <div class="form-group">
        <label>Password (changeme)</label>
        <input class="form-control" ng-model="user.password" type="password" style="display:block;" />
    </div>
    <br />
    <input type="submit" value="Login" class="btn btn-primary" />
</form>
<br />
<div><label>Logged in as: <span ng-bind-html="app.Auth.user.username" style="color: #428bca;font-style:italic;"></span><input ng-if="app.Auth.user.username" type="submit" ng-click="app.Auth.logout()" style="margin-left: 14px;" value="Logout" class="btn btn-primary btn-sm" /></label></div>

####Javascript

angular.module('st4rtApp',[
    'auth_module'
]).controller('AppCtlr', ['Auth', function (Auth){
    var self = this;
    this.Auth = Auth;
    this.Auth.get(null);
}]);

###Options

  • auth_base - The url path to the phpSlim index.php file. The phpSlim application can be used for the API or a url to point to an existing API can be used. This should be defined in a constant named 'CONF' with 'auth_base':'/bower_components/ckc-angularjs-auth/'
  • default_auth_endpoint - The API endpoint that decrypts and parses a JSON web tools. This should be defined in a constant named 'CONF' with 'default_auth_endpoint':'users/auth'
  • default_login_endpoint - The API endpoint that logs a user in and returns a JWT token. This should be defined in a constant named 'CONF' with 'default_login_endpoint':'users/login'

###Angular Methods

  • .get(params, auth_endpoint, cache)
  • .login(object, login_endpoint, cache)
  • .logout()

###API Methods

  • isJson(string) - Returns decoded json if valid, else returns json error

  • create_SQL(array) - Creates an insert SQL string from the below array 'fields'=>array( 'key'=>'value' ), 'model'=>'table_name'

  • read_SQL(array) - Creates a select SQL string from the below array 'conditions'=>array( 'key'=>'value', 'IN'=>array( 'key'=>'value', 'key'=>'value' ) ), 'fields'=>array('key'), 'model'=>'table_name', 'limit'=>'integer', 'order'=>'key', 'direction'=>'default:DESC'

  • update_SQL(array) - Creates an update SQL string from the below array 'conditions'=>array( 'key'=>'value', 'IN'=>array( 'key'=>'value', 'key'=>'value' ) ), 'fields'=>array( 'key'=>'value'), 'model'=>'table_name'

  • delete_SQL(array) - Creates a delete SQL string from the below array 'conditions'=>array( 'key'=>'value', 'IN'=>array( 'key'=>'value', 'key'=>'value' ) ), 'model'=>'table_name'

  • total(string) - Returns the number of rows from supplied SQL string

  • fields(string) - Returns the columns names of a supplied table name

  • create(string) - Returns 1 if a create is successful from supplied SQL string

  • read(string) - Returns the rows from supplied SQL string

  • update(string) - Returns 1 if an update is successful from supplied SQL string

  • delete(string) - Returns 1 if a delete is successful from supplied SQL string

###Use

  • Bower - ckc-angularjs-api
  • Add "auth_module" to your app's dependencies
  • Add "js/dist/auth.min.js" and "bower_components/ngstorage/ngStorage.min.js" to your scripts
  • Add 'CONF' constant with 'auth_base':'/bower_components/ckc-angularjs-auth/', 'default_auth_endpoint':'users/auth', 'default_login_endpoint':'users/login' or a custom url to the API endpoint of your choice
  • Config databases in a file named "ckc-angularjs-auth-config.php" just outside the bower folder. In here you can also require additional custom models
  • Run composer install just inside the bower package. This installs the necessary PHP packages

Module stats last updated: 2015-04-19 02:41:55

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!