GithubHelp home page GithubHelp logo

isabella232 / usermanagement-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oauth-io/usermanagement-demo

0.0 0.0 0.0 567 KB

User management on a github page using OAuth.io

JavaScript 86.16% HTML 12.02% CSS 1.82%

usermanagement-demo's Introduction

OAuth.io - User management Demo

Demo

Documentation

Installation

You need to enable the feature in your OAuth.io dashboard in the users tab. For that, you need to get API Key from stormpath and copy paste them in OAuth.io.

Install the OAuth.io javascript SDK

Signup

With email/password

User.signup(data).done(function(user) {
    //todo with `user`
});

data is an object that must contains:

  • email
  • password
  • firstname
  • lastname

You can add other data if you wish (free structure).

exemple:

User.signup({
   email: '[email protected]',
   password: 'St0ngP4ssw0rd',
   firstname: 'John',
   lastname: 'Doe',
   company: 'X Corp',
   age: 47
}).done(function(user) {
   //here, your user is logged in
   console.log(user.data.firstname);
}).fail(function(err) {
   //todo with `err`
});

With social logins

OAuth.popup(provider).then(function(res) {
    return User.signup(res)
}).done(function(user) {
   //here, your user is logged in
   console.log(user.data.firstname);
}).fail(function(err) {
   //todo with `err`
});

provider is the name of a provider on OAuth.io as facebook, twitter, google and 100+ others.

The provider need to have the User API enabled to work properly (you can see it when you add a new provider in your OAuth.io Dashbaord).

Handling errors

Some provider don't give their user's email in their API (it's the case of Twitter for instance). So, you have to ask your user his email manually and setup the email like this:

OAuth.popup('twitter').then(function(twitter) {
    twitter.email = "[email protected]";
    return User.signup(twitter);
}).done(function(user) {
    //todo with `user`
});

Signin

With email/password

User.signin(email, password).done(function(user) {
    console.log(user.data.firstname);
});

With social logins

OAuth.popup(provider).then(function(res) {
    return User.signin(res);
}).done(function(user) {
    console.log(user.data.firstname);
}).fail(function(err) {
    //todo with err
});

Get the connected user

From cache

var user = User.getIdentity();

From the API

User.refreshIdentity().done(function(user) {
    //todo with `user`
})

Know if the user is authenticated

if (User.isLogged()) {
    //todo with authenticated user
}
else {
    //todo with unauthenticated user
}

Update your user data

var user = User.getIdentity()
user.data.firstname = 'Thomas';
user.save().done(function() {
    //todo when saved
}).fail(function(err) {
    //handle `err``
});

Add all custom data you want

var user = User.getIdentity();
user.data.someData = {
    a: 42,
    b: "some string"
}
user.save();

Reset password (or lost password)

User.resetPassword(email).done(function() {
    //email sent to the user containing a key
});

//then...
User.confirmResetPassword(newPassword, key);

Change password

var user = User.getIdentity();
user.changePassword(oldPassword, newPassword);

Attach social identity to an account

var user = User.getIdentity();
OAuth.popup('google').then(function(google) {
   return user.addProvider(google);
}).done(function() {
   //provider attached
   //Your user are now able to signin with Google
});

The list of providers attached to an account

From cache

var user = User.getIdentity();
console.log(user.providers)

From the API

var user = User.getIdentity();
user.getProviders().done(function(providers) {
   console.log(providers);
});

Logout

var user = User.getIdentity();
user.logout().done(function() {
   //todo when logout
});

usermanagement-demo's People

Contributors

thyb avatar

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.