I've developed an app which includes user registration and login features using email and password. After login on the welcome screen, we display the username that was entered into a Google Sheet during the registration process.
Now, we would like a specific user who has logged in to be able to enter their age into the Google Sheet from the welcome screen. The age data should be saved in the corresponding column (i[0] email - i[1] pass - i[2] uname - i[3] age) for that specific user, based on their login ID. And we want to retrieve the age data depending on specific user account.
I believe it's a high level approach and I need your help guys..
Here's the script below
function doPost(e) {
var ss = SpreadsheetApp.openById('l2g');
var sh = ss.getSheetByName("She");
var msg;
if (e.parameter.fn == "getusers" ) {
var loginData = sh.getDataRange().getValues();
var users = ;
for ( var i = 1; i < loginData.length; i++ ) {
users.push(loginData[i][0]);
}
msg = JSON.stringify(users);
}
else if ( e.parameter.fn == "register" ) {
sh.appendRow([e.parameter.email, e.parameter.pass, e.parameter.uname]); // Add username to the row
msg = "user registered";
}
else if ( e.parameter.fn == "login" ) {
var loginData = sh.getDataRange().getValues();
msg = "user not found";
for ( var i = 0; i < loginData.length; i++ ) {
if ( e.parameter.email == loginData[i][0] && e.parameter.pass == loginData[i][1]) { // Check email and password
msg = JSON.stringify(loginData[i][2]);
}
}
}
else if ( e.parameter.fn == "reset" ) {
var newpass = makePasswd();
var newHash = makeHash(newpass,e.parameter.key);
var loginData = sh.getDataRange().getValues();
for ( var i = 0; i < loginData.length; i++ ) {
if ( e.parameter.email == loginData[i][1]) {
var rngp = sh.getRange(i+1,3);
rngp.setValue(newHash);
msg = "password reset";
}
}
GmailApp.sendEmail(e.parameter.email,"From AI2 App","Your new password is: " + newpass + "\n\n Use this new password to login.\n\n Thank you.");
}
return ContentService.createTextOutput(msg);
}
Tim, username part is connected with the registration, here i am talking about the welcome screen where u will put the age data based on the specific user logged in.
Based on the requirement, appscript also gonna change
I'd be more than greatful if u could provide a practical solution..
If we consider the scenario where different features need to be used for different purposes, let's take the example of creating a game where users have to store specific information only during that time.
To understand better how these kinds of data entry works, I just gave that age example, it can be any types of data
Your first step would be to add the "Age" column to your spreadsheet.
Then I suggest you have a good look at this guide, you will need to use the update section. You will need a unique item in each row to ensure you get the correct row to add the age.
Tim, its in the first collumn
anyway, in the block that i have shared recently, instead of tbRegUsername.text i have added an email id which is already in the google sheet
it works!
now the fact is i am only having the issue to retreive the email id after logged in