Fixed bug where unverified account would be marked as verified upon restart

This commit is contained in:
Jeffrey Morgan 2015-05-25 18:10:48 -07:00
parent a0afc9d85c
commit e7979fa97e
3 changed files with 23 additions and 26 deletions

View File

@ -1,29 +1,16 @@
import alt from '../alt'; import alt from '../alt';
import router from '../router';
class AccountServerActions { class AccountServerActions {
constructor () { constructor () {
this.generateActions( this.generateActions(
'signedup',
'loggedin',
'loggedout', 'loggedout',
'prompted', 'prompted',
'errors', 'errors',
'verified' 'verified'
); );
} }
loggedin ({username, verified}) {
if (router.get()) {
router.get().goBack();
}
this.dispatch({username, verified});
}
signedup ({username}) {
if (router.get()) {
router.get().goBack();
}
this.dispatch({username});
}
} }
export default alt.createActions(AccountServerActions); export default alt.createActions(AccountServerActions);

View File

@ -35,7 +35,12 @@ module.exports = React.createClass({
}, },
update: function () { update: function () {
this.setState(accountStore.getState()); let state = accountStore.getState();
this.setState(state);
if (state.username) {
this.goBack();
}
}, },
render: function () { render: function () {

View File

@ -39,7 +39,11 @@ module.exports = {
return jwt; return jwt;
}, },
refresh: function () { post: function (req) {
},
get: function (req) {
// TODO: implement me and wrap all jwt calls // TODO: implement me and wrap all jwt calls
}, },
@ -56,31 +60,32 @@ module.exports = {
}, },
// Places a token under ~/.dockercfg and saves a jwt to localstore // Places a token under ~/.dockercfg and saves a jwt to localstore
login: function (username, password, verifying) { login: function (username, password) {
request.post('https://hub.docker.com/v2/users/login/', {form: {username, password}}, (err, response, body) => { request.post('https://hub.docker.com/v2/users/login/', {form: {username, password}}, (err, response, body) => {
let data = JSON.parse(body); let data = JSON.parse(body);
if (response.statusCode === 200) { if (response.statusCode === 200) {
// TODO: save username to localstorage
// TODO: handle case where token does not exist
if (data.token) { if (data.token) {
localStorage.setItem('auth.jwt', data.token); localStorage.setItem('auth.jwt', data.token);
localStorage.setItem('auth.username', username); localStorage.setItem('auth.username', username);
localStorage.setItem('auth.verified', true); localStorage.setItem('auth.verified', true);
localStorage.setItem('auth.config', new Buffer(username + ':' + password).toString('base64')); localStorage.setItem('auth.config', new Buffer(username + ':' + password).toString('base64'));
}
if (verifying) {
accountServerActions.verified({username});
} else {
accountServerActions.loggedin({username, verified: true}); accountServerActions.loggedin({username, verified: true});
}
regHubUtil.repos(data.token); regHubUtil.repos(data.token);
} else {
accountServerActions.errors({errors: {details: new Error('Did not receive login token.')}});
}
} else if (response.statusCode === 401) { } else if (response.statusCode === 401) {
if (data && data.detail && data.detail.indexOf('Account not active yet') !== -1) { if (data && data.detail && data.detail.indexOf('Account not active yet') !== -1) {
accountServerActions.loggedin({username, verified: false}); accountServerActions.loggedin({username, verified: false});
localStorage.setItem('auth.username', username);
localStorage.setItem('auth.verified', false);
localStorage.setItem('auth.config', new Buffer(username + ':' + password).toString('base64'));
} else { } else {
accountServerActions.errors({errors: data}); accountServerActions.errors({errors: data});
} }
} }
}); });
}, },
@ -92,7 +97,7 @@ module.exports = {
} }
let [username, password] = new Buffer(config, 'base64').toString().split(/:(.+)?/).slice(0, 2); let [username, password] = new Buffer(config, 'base64').toString().split(/:(.+)?/).slice(0, 2);
this.login(username, password, true); this.login(username, password);
}, },
// Signs up and places a token under ~/.dockercfg and saves a jwt to localstore // Signs up and places a token under ~/.dockercfg and saves a jwt to localstore