Need help for google Sheet - Data entry

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..

aia file below
fix_username.aia (14.5 KB)

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);
}

The easiest thing to do is to add their age with the other data on registration. So do as you did for the username.

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..

Any reason why they cannot enter their age on registration ? It would save you a lot of work...

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

OK

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.

Here's the part of script i have added

else if ( e.parameter.fn == "score" ) {
var loginData = sh.getDataRange().getValues();
for ( var i = 0; i < loginData.length; i++ ) {
if ( e.parameter.email == loginData[i][0]) {
var rngp = sh.getRange(i+1,4);
rngp.setValue(e.parameter.score);
msg = "score updated";
}
}
}

here's the block I am using, nothing works

Kindly help me in this case

from what I remember, your username column is the third one ?

in which case you want

e.parameter.email == loginData[i][2])

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

thought it looked a bit suspect

:confused:

since i am having the issue to retrieve the usermail after logged in what to do in that case

as u already know our script is designed to retrieve username instead of usermail

Is the email Id different to e.parameter.email - which you already have because you are sending it to the google apps script ?

no its not

but in this script we are retrieving username i[2]

email - pass - uname

What is the problem then ?

Tim, I just solved it :sob: :sob:

the only issue was, after u logged in, u have to initialize the email id as global variable

after that use get global mail

We are done ?

yes :slightly_smiling_face:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.