Skip to content

Commit

Permalink
Improved and fixed user profile loading and saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Etzold committed Jun 27, 2012
1 parent 031f3be commit 545d38d
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#-SEARCH
#I-SEARCH

Welcome, this is an I-SEARCH (strange apple-like acronym meaning *A unIfied framework for multimodal SEARCH*) repo.
This space is used to build the GUI part of I-SEARCH.
Expand Down
5 changes: 5 additions & 0 deletions client/musebag/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ nav {
/*margin-right: 0;*/
}

.settings-panel #searchHistory p {
color: #fff;
margin: 1em;
}

.settings-panel .setting label {
margin: 0 0.5em 0 0;
padding: 0.3em 0.5em;
Expand Down
2 changes: 1 addition & 1 deletion client/musebag/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ <h3>Personal Data</h3>
</div>
<h3>Search History</h3>
<div id="searchHistory">
Your search history is empty.
<p>Your search history is empty.</p>
</div>
</div>
<button id="logout">Logout</button>
Expand Down
2 changes: 1 addition & 1 deletion client/musebag/js/local/basic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function localConfig(data)
{
data.visOptions.method = 'mst';
data.visOptions.method = 'cubes';
data.fileUploadServer = "http://vision.iti.gr/sotiris/isearch/upload.php"; //"query/item";
data.queryFormulatorUrl = "http://vision.iti.gr/sotiris/isearch/mqf.php?index=uc6"; //"query";
data.userProfileServerUrl = "profile/";
Expand Down
43 changes: 21 additions & 22 deletions client/musebag/js/mylibs/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
define("mylibs/config", ["mylibs/tags", "mylibs/profile", "!js/mylibs/visualization/DefaultThumbRenderer.js", "libs/jquery.select-to-autocomplete"],
function(tags, profile, cofind) {
// define("mylibs/config", ["mylibs/tags", "mylibs/profile", "!js/mylibs/visualization/DefaultThumbRenderer.js", "libs/jquery.select-to-autocomplete"],
// function(tags, profile, cofind) {

//define("mylibs/config",
// [
// "mylibs/tags",
// "mylibs/cofind",
// "mylibs/profile",
// "!js/mylibs/visualization/DefaultThumbRenderer.js",
// "libs/jquery.select-to-autocomplete"
// ],
// function(tags, cofind, profile) {
define("mylibs/config",
[
"mylibs/tags",
"mylibs/cofind",
"mylibs/profile",
"!js/mylibs/visualization/DefaultThumbRenderer.js",
"libs/jquery.select-to-autocomplete"
],
function(tags, cofind, profile) {

var constants = {
//Menu parameters
Expand Down Expand Up @@ -97,9 +97,7 @@

//Get user specific search history
var getUserHistory = function() {

var userId = profile.get('userId');

var userId = profile.get('userId');

if(userId) {
//Ask for user search history
Expand Down Expand Up @@ -313,7 +311,7 @@
};

var handleLogout = function() {
var serverURL = constants.userLoginServerUrl || "login";
var serverURL = constants.userLoginServerUrl || "login";

//Send it to the server
$.ajax({
Expand Down Expand Up @@ -345,13 +343,8 @@

panels.messages = $("#messages");
panels.messages.hide();

//init profile stuff
$('#profile-accordion').accordion({ autoHeight: false });
$('#dateOfBirth').datepicker({ dateFormat: "yy-mm-dd" });
$('#country').selectToAutocomplete();

// initialize settings from local configuration if any
//initialize settings from local configuration if any
if(localConfig) {
if(typeof(localConfig) === "function") {
localConfig(constants);
Expand All @@ -366,6 +359,11 @@
initSettings();
}

//init profile form modification stuff
$('#profile-accordion').accordion({ autoHeight: false });
$('#dateOfBirth').datepicker({ dateFormat: "yy-mm-dd" });
$('#country').selectToAutocomplete();

//init custom checkbox events
$('.checkbox').toggle(function() {
$(this).addClass('checked');
Expand Down Expand Up @@ -400,14 +398,15 @@

window.janrainWidgetOnload = function() {
//Force to format the stupid authentication widget
/*
$('#janrainEngageEmbed .janrainContent').attr('style','min-height: 40px');
$('#janrainEngageEmbed #janrainView').attr('style','');
$('#janrainEngageEmbed #janrainView .janrainHeader').attr('style','display: none;');
$('#janrainEngageEmbed #janrainView #janrain-blank').remove();
$('#janrainEngageEmbed #janrainView #janrainProviderPages').attr('style','margin: 0; padding: 0;');
$('#janrainEngageEmbed #janrainView #attribution_footer').remove();
$('#janrainEngageEmbed .janrainContent > div:last:not(#janrainView)').remove();

*/
$(document).on('DOMNodeInserted','#janrainEngageEmbed .janrainContent',function() {
//sendNotifyMessage($('#janrainEngageEmbed .janrainContent > div:last').text(),'info',false);
$('#janrainEngageEmbed .janrainContent > div:last').remove();
Expand Down
4 changes: 1 addition & 3 deletions client/musebag/js/mylibs/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ define("mylibs/profile", ["libs/modernizr.min"], function(){

var setProfileForm = function() {
$.each(profile, function(index, value) {
if(index === 'dateOfBirth') {
value = value.substring(0,value.indexOf('T'));
}
$('#' + index).val(value);
});

};

var setFromForm = function(callback) {
Expand Down
45 changes: 31 additions & 14 deletions server/musebag/musebag.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,9 @@ exports.login = function(req, res){

restler
.get(checkUrl)
.on('complete', function(data) {
if(data) {
console.log('User data received:');
console.log(data.user);
.on('complete', function(data, response) {

if(data) {
//assign retrieved data to local user profile
var name = data.user.name.split(' ');
user.name = name[0];
Expand All @@ -341,8 +340,15 @@ exports.login = function(req, res){
if(key === 'name') {
continue;
}
//Special treatment for date of birth key
if(key === 'dateOfBirth') {
user[key] = data.user[key].substring(0,data.user[key].indexOf('T'));
continue;
}
user[key] = data.user[key];
}
console.log('User data received:');
console.log(data.user);

} else {
console.log('User does not exist, request additional user information...');
Expand All @@ -368,8 +374,7 @@ exports.login = function(req, res){
})
.on('error', function(data,response) {
console.log("Personalisation component query error: " + data.toString());
});

});
}

//Return user data to client
Expand Down Expand Up @@ -409,7 +414,7 @@ exports.profile = function(req, res) {
var attrib = req.params.attrib;
//Get the right session storage (depending on log in status - guest if not, user if yes)
var sessionStore = getSessionStore(req);

console.dir(sessionStore);
if(sessionStore['userId'] === 'guest') {
res.send(JSON.stringify({error : 'User is not logged in!'}));
return;
Expand Down Expand Up @@ -457,23 +462,23 @@ exports.setProfile = function(req, res) {
settings[key] = newSettings[key];
changed = true;
}
}

}
//ok, the settings object is updated, so transform it back to a JSON string
//and store it in the session
sessionStore[attrib] = JSON.stringify(settings);
req.session.user[attrib] = JSON.stringify(settings);

} catch(e) {
res.send(JSON.stringify({error : 'malformed'}));
return;
}
} else {

if(attrib === 'dateOfBirth') {
data += 'T00:00:00+02:00';
}
//Set the profile attribute to the new value as long as it is a logged in user
if(sessionStore[attrib] !== data && !isGuest(req)) {
sessionStore[attrib] = data;
req.session.user[attrib] = data;
changed = true;
}
}
Expand All @@ -493,8 +498,15 @@ exports.setProfile = function(req, res) {

//if we have a logged in user, we store everything in the profile
var storeURL = apcPath + 'resources/users/setProfileDataFor/' + sessionStore['userId'];
var callData = sessionStore;
callData.name = sessionStore['name']+' '+sessionStore['familyname'],
var callData = {};

for( var key in sessionStore ) {
if(key === 'name') {
callData['name'] = sessionStore['name']+' '+sessionStore['familyname'];
} else {
callData[key] = sessionStore[key];
}
}
console.log(callData);
//save the user data in the user profile
restler
Expand All @@ -503,6 +515,9 @@ exports.setProfile = function(req, res) {
//Check if return data is ok
if (response.statusCode == 201) {
data = {success : attrib};
req.session.user['state'] = 'member';

console.log(sessionStore);
//Notify client about success full save
res.send(JSON.stringify(data));
} else {
Expand Down Expand Up @@ -539,8 +554,10 @@ exports.getProfileHistory = function(req, res) {
.get(getURL)
.on('complete', function(data, response) {
console.log(data);
console.log(response.statusCode);

//Check if result is ok
if (response.statusCode === 200) {
if (response.statusCode == 200) {
//Notify client about successful save
res.send(JSON.stringify(data));
} else {
Expand Down

0 comments on commit 545d38d

Please sign in to comment.