Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getUserData(token) {
return (when(request({
url: UserConstants.USER_DETAIL_URL,
method: 'GET',
type: 'json',
// add Authorization header for api authentication
headers: {
'Authorization': 'Token ' + UserStore.token
}
})).then(function(data) {
console.log(data);
UserActions.loadUserDetail(data);
}));
}
em.on('login', function(username, search) {
$('#failAlert').hide()
$('#successAlert').show();
const url = `${window.location.origin}/authorize${search}&username=${username}`;
when(request({
url: url,
method: 'GET',
crossOrigin: true,
type: 'json',
})
.then(function(code){
var Code = code.code
window.location = `${Code.redirectUri}/?code=${Code.authorizationCode}`
})
.catch( err => {
console.log("no res")
}))
// window.close()
}.bind(this))
}
reset_password(email) {
return (when(request({
url: UserConstants.PASSWORD_RESET_URL,
method: 'POST',
type: 'json',
data: {
email: email
}
})).then(function(data) {
console.log(data);
alert('password reset email sent');
return true;
}));
}
login(username, password) {
return when(request({
url: LOGIN_URL,
method: 'POST',
crossOrigin: true,
type: 'json',
data: {
username: username,
password: password
}
})).then(function(response) {
const status = response.status;
const search = window.location.search
if(status == 'ok'){
em.emit('login', username, search);
return true;
}
});;
signup(email, username, password1, password2) {
console.log(password1, password2);
return this.handleAuth(when(request({
url: UserConstants.SIGNUP_URL,
method: 'POST',
type: 'json',
data: {
email: email,
username: username,
password1: password1,
password2: password2
}
})));
}
export default async function rest(url, payload = null, method = 'POST') {
try {
debug('API call: ' + url);
const response = await when(request({
url: url.startsWith('/') ? url : apiEndpoint + '/' + url,
method: method,
crossOrigin: true,
type: 'json',
contentType: 'application/json',
data: JSON.stringify(payload)
}));
return response;
} catch (response) {
debug('API call failed with status ' + response.status);
if (response.status === 0) {
throw new Error('API endpoint did not respond. Is backend running?');
} else if (response.status === 404) {
throw new Error('API endpoint did not recognize this call (404 Not Found)');
login(username, password) {
return this.handleAuth(when(request({
url: LOGIN_URL,
method: 'POST',
crossOrigin: true,
type: 'json',
data: {
email: username,
password: password
}
})));
}
login(username, password) {
return this.handleAuth(when(request({
url: LOGIN_URL,
method: 'POST',
crossOrigin: true,
type: 'json',
data: {
username, password
}
})));
}
run(state, site) {
const libsPromise = when().then(() => site.getLibraries());
return when.map(libsPromise, libdir => {
site.notifyStart(libdir);
const dir = path.resolve(libdir);
const repo = new FileSystemLibraryRepository(dir, FileSystemNamingStrategy.DIRECT);
return this.processLibrary(repo, '', state, site)
.then(([res, err]) => {
site.notifyEnd(libdir, res, err);
return {libdir, res, err};
});
});
}
run(cmd, state = {}) {
return when()
.then(() => this.begin(state, this))
.then(() => cmd.run(state, this))
.finally(() => this.end(state, this));
}
}