@@ -3,25 +3,25 @@ | |||||
"description": "open source password manager", | "description": "open source password manager", | ||||
"author": "Guillaume Vincent <guillaume@oslab.fr>", | "author": "Guillaume Vincent <guillaume@oslab.fr>", | ||||
"scripts": { | "scripts": { | ||||
"start": "NODE_ENV=production node server.js", | |||||
"dev": "webpack-dev-server --inline --hot --host 0.0.0.0", | "dev": "webpack-dev-server --inline --hot --host 0.0.0.0", | ||||
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules", | "build": "cross-env NODE_ENV=production webpack --progress --hide-modules", | ||||
"test": "mocha --ui tdd --require babel-core/register --globals localStorage tests/**/*.js" | "test": "mocha --ui tdd --require babel-core/register --globals localStorage tests/**/*.js" | ||||
}, | }, | ||||
"dependencies": { | "dependencies": { | ||||
"axios": "^0.9.1", | |||||
"bootstrap": "^4.0.0-alpha.2", | "bootstrap": "^4.0.0-alpha.2", | ||||
"clipboard": "^1.5.9", | "clipboard": "^1.5.9", | ||||
"es6-promise": "^3.1.2", | "es6-promise": "^3.1.2", | ||||
"express": "^4.13.4", | "express": "^4.13.4", | ||||
"font-awesome": "^4.5.0", | "font-awesome": "^4.5.0", | ||||
"isomorphic-fetch": "^2.2.1", | |||||
"jquery": "^2.2.2", | "jquery": "^2.2.2", | ||||
"lesspass": "^1.1.1", | "lesspass": "^1.1.1", | ||||
"tether": "^1.2.0", | "tether": "^1.2.0", | ||||
"toastr": "^2.1.2", | "toastr": "^2.1.2", | ||||
"vue": "^1.0.20", | "vue": "^1.0.20", | ||||
"vue-i18n": "^2.4.1", | "vue-i18n": "^2.4.1", | ||||
"vue-router": "^0.7.11", | |||||
"whatwg-fetch": "^0.11.0" | |||||
"vue-router": "^0.7.11" | |||||
}, | }, | ||||
"devDependencies": { | "devDependencies": { | ||||
"babel-core": "^6.7.4", | "babel-core": "^6.7.4", | ||||
@@ -0,0 +1,12 @@ | |||||
var express = require('express'); | |||||
var app = express(); | |||||
app.use('/dist', express.static(__dirname + '/dist')); | |||||
app.get('/', function (req, res) { | |||||
res.sendFile(__dirname + '/index.html'); | |||||
}); | |||||
app.listen(8080, function () { | |||||
console.log('frontend listening on port 8080'); | |||||
}); |
@@ -1,39 +1,17 @@ | |||||
import { polyfill } from 'es6-promise'; | |||||
polyfill(); | |||||
import 'isomorphic-fetch'; | |||||
function checkStatus(response) { | |||||
if (response.status >= 200 && response.status < 300) { | |||||
return response; | |||||
} | |||||
const error = new Error(response.statusText); | |||||
error.response = response; | |||||
throw error; | |||||
} | |||||
function parseJSON(response) { | |||||
return response.json(); | |||||
} | |||||
var Promise = require('es6-promise').Promise; | |||||
import request from 'axios'; | |||||
export default { | export default { | ||||
user: { | user: { | ||||
authenticated: false, | authenticated: false, | ||||
}, | }, | ||||
login(credential) { | |||||
return fetch('/api/sessions/', { | |||||
method: 'post', | |||||
headers: { | |||||
Accept: 'application/json', | |||||
'Content-Type': 'application/json', | |||||
}, | |||||
body: JSON.stringify(credential), | |||||
}).then(checkStatus) | |||||
.then(parseJSON) | |||||
.then((data) => { | |||||
localStorage.setItem('token', data.token); | |||||
login(credentials) { | |||||
return request.post('/api/sessions/', credentials) | |||||
.then((response) => { | |||||
localStorage.setItem('token', response.data.token); | |||||
this.user.authenticated = true; | this.user.authenticated = true; | ||||
return data; | |||||
return response; | |||||
}); | }); | ||||
}, | }, | ||||
@@ -44,7 +22,7 @@ export default { | |||||
this.user.authenticated = false; | this.user.authenticated = false; | ||||
resolve(); | resolve(); | ||||
} catch (e) { | } catch (e) { | ||||
reject('cannot logout'); | |||||
reject(e); | |||||
} | } | ||||
}); | }); | ||||
}, | }, | ||||
@@ -2,13 +2,12 @@ import assert from 'assert'; | |||||
import auth from '../../src/services/auth'; | import auth from '../../src/services/auth'; | ||||
import nock from 'nock'; | import nock from 'nock'; | ||||
suite('Auth', () => { | suite('Auth', () => { | ||||
var credentials = { | var credentials = { | ||||
email: 'test@lesspass.com', | email: 'test@lesspass.com', | ||||
password: 'password' | password: 'password' | ||||
}; | }; | ||||
var token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ'; | |||||
var token = 'eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9'; | |||||
before(() => { | before(() => { | ||||
var LocalStorage = require('node-localstorage').LocalStorage; | var LocalStorage = require('node-localstorage').LocalStorage; | ||||
@@ -16,14 +15,18 @@ suite('Auth', () => { | |||||
}); | }); | ||||
beforeEach(() => { | beforeEach(() => { | ||||
nock('//lesspass.com/').post('/api/sessions/', credentials).reply(201, {token: token}); | |||||
nock('http://localhost/') | |||||
.post('/api/sessions/', credentials) | |||||
.reply(201, {token: token}, {'Content-Type': 'application/json'}); | |||||
}); | }); | ||||
test('should make a post request to create a session', (done) => { | test('should make a post request to create a session', (done) => { | ||||
auth.login(credentials) | auth.login(credentials) | ||||
.then(() => { | .then(() => { | ||||
done(); | done(); | ||||
}); | |||||
}).catch((err) => { | |||||
console.log(err) | |||||
}) | |||||
}); | }); | ||||
test('should throw error if bad request', (done) => { | test('should throw error if bad request', (done) => { | ||||