Created
June 9, 2015 14:02
-
-
Save alihammad-gist/1de4afc6189bec1f13e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Login {} | |
export class Logout {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../../typings/_.d.ts" /> | |
import jwt_decode = require('jwt-decode') | |
import cookie_getter = require('cookie-getter') | |
import flux = require('flux') | |
import action = require('./action') | |
export interface User { | |
Id: number | |
Name: string | |
Dp: string | |
Email: string | |
} | |
export var Auth | |
export function Init(d: flux.Dispatcher) { | |
Auth = new Authenticator(d) | |
} | |
function login() { | |
// getting cookie | |
var token = cookie_getter<string>(Authenticator.cookieName) | |
if (token === null || token === '') { | |
return | |
} | |
var user = jwt_decode<User>(token) | |
if (user !== null) { | |
Authenticator.user = user | |
} | |
} | |
class Authenticator { | |
static cookieName = "jwt" | |
static user: User; | |
static dispatcher: flux.Dispatcher; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment