Partner in Log Web app:
A login page is designed using HTML and the back end functionality is achieved using suitelet script. Credentials used for login are email and password. The suitelet script checks in Netsuite if the user credentials are valid or not.
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/search', 'N/record'],
function(search, record) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
log.debug({ title: "test" });
//log.debug({details:context.request.method});
var emailusr = context.request.parameters.email;
var passusr = unescape(context.request.parameters.password);
log.debug({ title: "passwordcomming", details: passusr });
var UsrCallback = context.request.parameters.callback;
log.debug({ title: "login by:", details: emailusr });
try {
filter = ['custrecord_jj_partnerinlog_email', 'is', emailusr];
var mySearch = search.create({
type: 'customrecord_jj_partnerinlog_partners',
title: 'My Search',
columns: ['id', 'custrecord_jj_partnerinlog_password'],
filters: filter
});
var search_run = mySearch.run().getRange({
start: 0,
end: 1
});
if (search_run.length > 0) {
var usrid = search_run[0].getValue({
name: 'id',
});
var pass = search_run[0].getValue({
name: 'custrecord_jj_partnerinlog_password',
});
if (passusr == pass) {
log.debug({ title: "status:", details: "LOGGED IN" });
//password is correct
var result = "SUCCESS" + usrid;
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
context.response.write(strJson);
} else {
log.debug({ title: "status:", details: "PASSWORD fAIL" });
//invalid password
log.debug({ details: 'Password incorrect' });
var result = "failure";
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
context.response.write(strJson);
}
} else {
var result = "failure";
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
context.response.write(strJson);
}
} catch (err) {
log.debug({ title: "error", details: err });
}
}
return {
onRequest: onRequest
};
});