Giter Club home page Giter Club logo

ember-mu-login's Introduction

Ember-mu-login

This addon provides a mu-login and mu-logout component for the mu-login microservice. The addon is based on ember-simple-auth.

Installation

ember install ember-mu-login

Basic usage

Just include the {{mu-login}} or {{mu-logout}} component in your template.

Advanced usage

Overwriting the component templates

To overwrite the template of the components, create a custom mu-login.hbs or mu-logout.hbs file. Make sure you use the correct bindings and actions. You can have a look at the default templates in addon/templates/components.

For mu-login

  • call the login action
  • use nickname and password as value bindings for the input fields

For mu-logout

  • call the logout action

Customizing the components

To customize the components, generate your own new components and include the mu-login (ember-mu-login/mixins/mu-login) and mu-logout (ember-mu-login/mixins/mu-logout) mixins to handle the login and logout actions.

Ember Simple Auth in a nutshell

The ember-mu-login addon is based on ember-simple-auth. The following paragraphs highlight the features you will probably need in combination with ember-mu-login. A complete usage and configuration guide can be found in the ember-simple-auth documentation.

Session state

You can use ember-simple-auth's isAuthenticated property to check the current session's state. The session service needs to be injected.

// app/controllers/application.js
import Ember from 'ember';

export default Ember.Controller.extend({
  session: Ember.inject.service('session')

  
});
{{!-- app/templates/application.hbs --}}
{{#if session.isAuthenticated}}
  {{mu-logout}}
{{else}}
  {{mu-login}}
{{/if}}

Authentication events

Mix the ApplicationRouteMixin into the application route to have the authenticationSucceeded and invalidationSucceeded events handled automatically:

// app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin);

Protecting routes

To make a route in the application accessible only when the session is authenticated, mix the AuthenticatedRouteMixin into the respective route:

// app/routes/protected.js
import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin);

This will make the route (and all of its subroutes) transition to the login route if the session is not authenticated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.