Registration, Login and Forgot Password using Google Spreadsheet

would you mind modifying blocks from that project,

I am a new user in mit app inventor. don't undersatnd that much

login_register_username.aia (13.2 KB)

You are adding a new parameter username:
image

where are you filling that new parameter? Has it been filled when you are going to use it?

i don't know where to fill this :sob: :sob:

i just caled the text area as username and the parameter username is in the script

someone who has some kind of expertise, kindly help

Restart the app in companion, so that the webviewstring is also cleared / reset.

You could also try adding:

set webviewstring = blank text

at the top here:

image

I've fixed it

We have to re-deploy our script cuz we did some changes. Now its working perfectly fine

tim, as I mentioned earlier, now i dont have any issues related to inserting username data to google sheet

the only problem i am encountering is when u logged in, u will see the email id and the logout button right?

instead i want to showcase only username

but i just see a blank space and the logout data

what to do in that case? Appriciate your guidance

I have not programmed that in the blocks code. one for you to work on....

I am using the same blocks which you have already provided here.

as I said

I’m working on an app using MIT App Inventor using Google AppScript. I’ve set up user registration and login using email and password, and it’s working fine. However, after a successful login, I want to display the username instead of the email address. I’ve tried modifying my AppScript and blocks in App Inventor, but I’m still having trouble. Any advice or guidance would be greatly appreciated. Thanks in advance!

login_register_username.aia (13.2 KB)

here's the script below

function doPost(e) {
var ss = SpreadsheetApp.openById('13FUnFMaNA-8kmLlIg06rlWw3IfXjqLV4a2x6c9wIl2g');
var sh = ss.getSheetByName("Sheet1");
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();
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 = "user logged in as ";
}
}
}
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);
}

function makePasswd() {
var passwd = '';
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!.#*@_';
for (i=1;i<8;i++) {
var c = Math.floor(Math.random()*chars.length + 1);
passwd += chars.charAt(c)
}
return passwd;
}

function makeHash(message,key){
var getHash = Utilities.computeHmacSha256Signature(message,key).reduce(function(str,chr){
chr = (chr < 0 ? chr + 256 : chr).toString(16);
return str + (chr.length==1?'0':'') + chr;
},'');;
return getHash;
}

guys someone please help

Change this part of the script by, for example, this:

This is unnecessary...for the login you only validate the email and password:

And then change this part of the code in GotText:

Hey, I followed the same thing u have suggested.

but once i logged in it says logged in as:
user

it doesn't say the actual user name

just says user :sob:

If it does not find the user/passwd, it returns that string...that's why you are checking that same string in blocks...

I've solved the issue

thank you so much Ramon,

God bless you