Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for bad gateway error due to missing details on drupal - displays an error message #577

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 72 additions & 68 deletions libs/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,82 +65,86 @@ var drupal_login = function (email, password, done) {
drupal_login_request(email, password).then(function (drupal_user) {
if (drupal_user != null) {
// Drupal update information.
var drupal_user_id = drupal_user.user.uid;
var tickets = drupal_user.user.data.tickets.tickets;
var current_event_tickets_count = 0;
var tickets_array = [];
var drupal_user_id = _.get(drupal_user, 'user.uid');
if (!drupal_user_id) {
done(false, i18next.t('invalid_user_id'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change right, all the rest is indentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly yes, you can see only the changes without whitespace changes by adding ?w=1 to the url - https://github.com/Midburn/spark/pull/577/files?w=1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! it's useful.

} else {
var tickets = drupal_user.user.data.tickets.tickets;
var current_event_tickets_count = 0;
var tickets_array = [];

_.each(tickets, (ticket, ticket_id) => {
if (ticket.trid) {
var _ticket = {
trid: ticket.trid,
user_uid: ticket.user_uid,
bundle: ticket.bundle,
barcode: _.get(ticket, 'field_ticket_barcode.und.0.value', ''),
serial_id: _.get(ticket, 'field_ticket_serial_id.und.0.value', '')
};
_ticket.is_mine = (_ticket.user_uid === drupal_user_id);
if (constants.events[constants.DEFAULT_EVENT_ID].bundles.indexOf(_ticket.bundle) > -1) {
_ticket.event_id = constants.DEFAULT_EVENT_ID;
if (_ticket.is_mine) {
current_event_tickets_count++;
_.each(tickets, (ticket, ticket_id) => {
if (ticket.trid) {
var _ticket = {
trid: ticket.trid,
user_uid: ticket.user_uid,
bundle: ticket.bundle,
barcode: _.get(ticket, 'field_ticket_barcode.und.0.value', ''),
serial_id: _.get(ticket, 'field_ticket_serial_id.und.0.value', '')
};
_ticket.is_mine = (_ticket.user_uid === drupal_user_id);
if (constants.events[constants.DEFAULT_EVENT_ID].bundles.indexOf(_ticket.bundle) > -1) {
_ticket.event_id = constants.DEFAULT_EVENT_ID;
if (_ticket.is_mine) {
current_event_tickets_count++;
}
}
tickets_array.push(_ticket);
}
tickets_array.push(_ticket);
}
});
});

var drupal_details = {
created_at: (new Date(parseInt(_.get(drupal_user, 'user.created', 0)) * 1000)).toISOString().substring(0, 19).replace('T', ' '),
updated_at: (new Date()).toISOString().substring(0, 19).replace('T', ' '),
first_name: _.get(drupal_user, 'user.field_profile_first.und.0.value', ''),
last_name: _.get(drupal_user, 'user.field_profile_last.und.0.value', ''),
cell_phone: _.get(drupal_user, 'user.field_profile_phone.und.0.value', ''),
address: _.get(drupal_user, 'user.field_profile_address.und.0.thoroughfare', '') + ' ' + _.get(drupal_user, 'user.field_profile_address.und.0.locality', '') + ' ' + _.get(drupal_user, 'user.field_profile_address.und.0.country', ''),
israeli_id: _.get(drupal_user, 'user.field_field_profile_document_id.und.0.value', ''),
date_of_birth: _.get(drupal_user, 'user.field_profile_birth_date.und.0.value', ''),
gender: _.get(drupal_user, 'user.field_sex.und.0.value', constants.USER_GENDERS_DEFAULT).toLowerCase(),
current_event_id_ticket_count: current_event_tickets_count,
validated: true
};
var drupal_details = {
created_at: (new Date(parseInt(_.get(drupal_user, 'user.created', 0)) * 1000)).toISOString().substring(0, 19).replace('T', ' '),
updated_at: (new Date()).toISOString().substring(0, 19).replace('T', ' '),
first_name: _.get(drupal_user, 'user.field_profile_first.und.0.value', ''),
last_name: _.get(drupal_user, 'user.field_profile_last.und.0.value', ''),
cell_phone: _.get(drupal_user, 'user.field_profile_phone.und.0.value', ''),
address: _.get(drupal_user, 'user.field_profile_address.und.0.thoroughfare', '') + ' ' + _.get(drupal_user, 'user.field_profile_address.und.0.locality', '') + ' ' + _.get(drupal_user, 'user.field_profile_address.und.0.country', ''),
israeli_id: _.get(drupal_user, 'user.field_field_profile_document_id.und.0.value', ''),
date_of_birth: _.get(drupal_user, 'user.field_profile_birth_date.und.0.value', ''),
gender: _.get(drupal_user, 'user.field_sex.und.0.value', constants.USER_GENDERS_DEFAULT).toLowerCase(),
current_event_id_ticket_count: current_event_tickets_count,
validated: true
};

var details_json_data = {
address: {
first_name: _.get(drupal_user, 'user.field_profile_address.und.0.first_name', ''),
last_name: _.get(drupal_user, 'user.field_profile_address.und.0.last_name', ''),
street: _.get(drupal_user, 'user.field_profile_address.und.0.thoroughfare', ''),
city: _.get(drupal_user, 'user.field_profile_address.und.0.locality', ''),
country: _.get(drupal_user, 'user.field_profile_address.und.0.country', '')
},
foreign_passport: _.get(drupal_user, 'user.field_profile_address.und.0.country', '')
};
var details_json_data = {
address: {
first_name: _.get(drupal_user, 'user.field_profile_address.und.0.first_name', ''),
last_name: _.get(drupal_user, 'user.field_profile_address.und.0.last_name', ''),
street: _.get(drupal_user, 'user.field_profile_address.und.0.thoroughfare', ''),
city: _.get(drupal_user, 'user.field_profile_address.und.0.locality', ''),
country: _.get(drupal_user, 'user.field_profile_address.und.0.country', '')
},
foreign_passport: _.get(drupal_user, 'user.field_profile_address.und.0.country', '')
};

var addinfo_json = {};
if (user && typeof user.attributes.addinfo_json === 'string') {
addinfo_json = JSON.parse(user.attributes.addinfo_json);
}
addinfo_json.drupal_data = details_json_data;
addinfo_json.tickets = tickets_array;
drupal_details.addinfo_json = JSON.stringify(addinfo_json);
var addinfo_json = {};
if (user && typeof user.attributes.addinfo_json === 'string') {
addinfo_json = JSON.parse(user.attributes.addinfo_json);
}
addinfo_json.drupal_data = details_json_data;
addinfo_json.tickets = tickets_array;
drupal_details.addinfo_json = JSON.stringify(addinfo_json);

if (user === null) {
signup(email, password, drupal_details, function (newUser, error) {
if (newUser) {
done(newUser);
} else {
done(false, error);
}
})
}
else {
// we are now updating user data every login
// to fetch latest user information. very important is to know
// that once spark will be the main system, this all should be removed!
user.save(drupal_details).then((user) => {
done(user);
});
if (user === null) {
signup(email, password, drupal_details, function (newUser, error) {
if (newUser) {
done(newUser);
} else {
done(false, error);
}
})
}
else {
// we are now updating user data every login
// to fetch latest user information. very important is to know
// that once spark will be the main system, this all should be removed!
user.save(drupal_details).then((user) => {
done(user);
});

console.log('User', email, 'authenticated successfully in Drupal and synchronized to Spark.');
console.log('User', email, 'authenticated successfully in Drupal and synchronized to Spark.');
}
}
}
else {
Expand Down
1 change: 1 addition & 0 deletions locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"hello": "Hello",
"home": "Home",
"invalid_user_password": "Invalid username or password",
"invalid_user_id": "Please login to your midburn profile, sorry for the inconvenience - https://profile.midburn.org/",
"login": "Login",
"logout": "Logout",
"male": "Male",
Expand Down
1 change: 1 addition & 0 deletions locales/he/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"hello": "שלום",
"home": "בית",
"invalid_user_password": "דואר אלקטרוני או סיסמה אינם תקינים",
"invalid_user_id": "היכנסו בבקשה לפרופיל המידברן שלכם - https://profile.midburn.org",
"last_name": "שם משפחה",
"login": "כניסה למערכת",
"logout": "התנתקות",
Expand Down