client/general: refactor promises
This commit is contained in:
parent
2af8c9c1a4
commit
8f5890ab67
|
@ -34,7 +34,7 @@ class AuthController {
|
|||
resolve();
|
||||
page('/');
|
||||
events.notify(events.Success, 'Logged in');
|
||||
}).catch(errorMessage => {
|
||||
}, errorMessage => {
|
||||
reject(errorMessage);
|
||||
events.notify(events.Error, errorMessage);
|
||||
});
|
||||
|
@ -63,19 +63,16 @@ class AuthController {
|
|||
api.post('/password-reset/' + name, {token: token})
|
||||
.then(response => {
|
||||
const password = response.password;
|
||||
api.login(name, password, false)
|
||||
.then(() => {
|
||||
return api.login(name, password, false);
|
||||
}, response => {
|
||||
return Promise.reject(response.description);
|
||||
}).then(() => {
|
||||
page('/');
|
||||
events.notify(
|
||||
events.Success, 'New password: ' + password);
|
||||
}).catch(errorMessage => {
|
||||
events.notify(events.Success, 'New password: ' + password);
|
||||
}, errorMessage => {
|
||||
page('/');
|
||||
events.notify(events.Error, errorMessage);
|
||||
});
|
||||
}).catch(response => {
|
||||
page('/');
|
||||
events.notify(events.Error, response.description);
|
||||
});
|
||||
}
|
||||
|
||||
_passwordReset(nameOrEmail) {
|
||||
|
@ -89,7 +86,7 @@ class AuthController {
|
|||
events.Success,
|
||||
'E-mail has been sent. To finish the procedure, ' +
|
||||
'please click the link it contains.');
|
||||
}).catch(response => {
|
||||
}, response => {
|
||||
reject();
|
||||
events.notify(events.Error, response.description);
|
||||
});
|
||||
|
|
|
@ -60,7 +60,7 @@ class UsersController {
|
|||
ctx.save();
|
||||
this.user = response.user;
|
||||
next();
|
||||
}).catch(response => {
|
||||
}, response => {
|
||||
this.emptyView.render();
|
||||
events.notify(events.Error, response.description);
|
||||
});
|
||||
|
@ -88,18 +88,17 @@ class UsersController {
|
|||
return new Promise((resolve, reject) => {
|
||||
api.post('/users/', data).then(() => {
|
||||
api.forget();
|
||||
api.login(name, password, false).then(() => {
|
||||
return api.login(name, password, false);
|
||||
}, response => {
|
||||
return Promise.reject(response.description);
|
||||
}).then(() => {
|
||||
resolve();
|
||||
page('/');
|
||||
events.notify(events.Success, 'Welcome aboard!');
|
||||
}).catch(errorMessage => {
|
||||
}, errorMessage => {
|
||||
reject();
|
||||
events.notify(events.Error, errorMessage);
|
||||
});
|
||||
}).catch(response => {
|
||||
reject();
|
||||
events.notify(events.Error, response.description);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -114,28 +113,22 @@ class UsersController {
|
|||
return new Promise((resolve, reject) => {
|
||||
api.put('/user/' + user.name, data)
|
||||
.then(response => {
|
||||
const next = () => {
|
||||
resolve();
|
||||
page('/user/' + newName + '/edit');
|
||||
events.notify(events.Success, 'Settings updated');
|
||||
};
|
||||
if (isLoggedIn) {
|
||||
return isLoggedIn ?
|
||||
api.login(
|
||||
newName,
|
||||
newPassword || api.userPassword,
|
||||
false)
|
||||
.then(next)
|
||||
.catch(errorMessage => {
|
||||
newName, newPassword || api.userPassword, false) :
|
||||
Promise.fulfill();
|
||||
}, response => {
|
||||
return Promise.reject(response.description);
|
||||
}).then(() => {
|
||||
resolve();
|
||||
if (newName !== user.name) {
|
||||
page('/user/' + newName + '/edit');
|
||||
}
|
||||
events.notify(events.Success, 'Settings updated.');
|
||||
}, errorMessage => {
|
||||
reject();
|
||||
events.notify(events.Error, errorMessage);
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}).catch(response => {
|
||||
reject();
|
||||
events.notify(events.Error, response.description);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -155,7 +148,7 @@ class UsersController {
|
|||
page('/');
|
||||
}
|
||||
events.notify(events.Success, 'Account deleted');
|
||||
}).catch(response => {
|
||||
}, response => {
|
||||
reject();
|
||||
events.notify(events.Error, response.description);
|
||||
});
|
||||
|
|
|
@ -22,7 +22,6 @@ function _messageHandler(target, message, className) {
|
|||
messagesHolder.appendChild(node);
|
||||
}
|
||||
|
||||
|
||||
function listenToMessages(target) {
|
||||
events.unlisten(events.Success);
|
||||
events.unlisten(events.Error);
|
||||
|
|
Loading…
Reference in New Issue