function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JesipJesip 

sforceClient.Login within an sControl

Is it possible to use sforceClient.Login within an sControl rather than sforce.init?  I would like to allow my sControl to login as an adminstrative user as a security work-around, but I keep getting errors when calling the Login method.
 
Thanks.
DevAngelDevAngel
Absolutely.

You must call init though.  Try this:

Code:
function initPage() {
    sforceClient.registerInitCallback(setup);
    sforceClient.init(null, null, false);
}
function setup() {
    alert(sforceClient.login(username, password));
}    

 

JesipJesip
I tried your suggestion, but I get the message "Object doesn't support this property or method" on the Line:  sforceClient.registerInitCallback(setup);
 
 
JesipJesip

Here is the code for the full control if that helps:

<html>
<head>
<title>Delete Sample Item</title>
<script src="https://www.sforce.com/ajax/beta1/sforceclient.js" type="text/javascript"></script>
<script language="javascript">
<!--
function initPage()
{
sforceClient.useCookies = true;
sforceClient.registerInitCallback(setup);
sforceClient.init(null, null, false);

window.setTimeout(";", 1000);
var Sample = "{!Sample_ID}";
processRun(Sample);

}

function setup() {
alert(sforceClient.login("admin@mydomain.com", "mypassword"));
}

function processRun(Sample) {

sforceClient.Delete("{!Sample_Item_ID}");
redirect(Sample);

}

function redirect(SampleId) {
parent.frames.location.replace("/" + SampleId)
}

//-->
</script>
</head>
<body onload="initPage();" style='background-color:#ffffff;color:#000000;'>
<div id="divMain">
</div>
</body>
</html>

DevAngelDevAngel
Change to beta3.3

https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js
JesipJesip

I have updated to 3.3, but now I get an "Unknown name" error on the login call.  I am using my own username and password to test so I'm sure they are correct.  any more thoughts?

Thank you!

DevAngelDevAngel
Here is a simple sample of doing login.

Code:
function initPage() {
        sforceClient.registerInitCallback(doLogin);
        sforceClient.init(null, null, false);
}
function doLogin() {
 var loginResult = sforceClient.login("username", "password");
    alert(loginResult);
//Here you should do the rest of the page setup
finishPageLoad();
}

 

JesipJesip
Every time I hit the line for the sforceClient.Login I get an error.
 
Line: 905
Char: 3
Error: Unknown name
Code: 0
 
Thank you for your patience; I really need to get this to work.
DevAngelDevAngel

Hmm... what browser and os?

Can you get a simple scontrol that only logs in to work in IE from the file system?

 

chrismclarenchrismclaren

Would I be correct in saying, that using this method, anyone could click on View|Source and looking at the code could then get the username and password?

Is there anyway to do this but also hide/encrypt the username and password?

SteveBowerSteveBower
Correct.

Nothing leaps to mind except obfuscation.  (Like building the username and password byte by byte in hex, backwards, or other laughable approaches.  At the end of the day though, the enterprising thief can work around it and get it.)

Seems like a bad idea. 

It looks like the original goal was to delete some records.  Perhaps instead, the record ID's to be deleted could be stored in a custom object of "Things to be Deleted".  And then once in awhile a "real" admin will come around and execute an s-control which will take the id stored in every record of that table and delete it.  Sure, it's housekeeping, but if you don't want to just grant the users the needed permissions... :-)

Steve Bower.

joe-kizayjoe-kizay

DevAngel,

I am getting this error on some of the machines here as well. Works perfectly on my machine OS=Win2003 Standard,  Browser=IE6 but on on OS=WinXP, Browser=IE6. The line that fails is

Code:

me.XMLHttpRequests[i].req.open('POST', url, async);

 

Which like Jesip stated, errors on line 904 - Unknown Name. Thoughts?

 

ErikGEnErikGEn
Hi
 
I have similar need, I would like execute a Scontrol with a different login, so I follow the previous code, but I have already a error syntax
 
Anyone could look my code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>

 

<script language="javascript">

<!--

window.setTimeout(";", 1000);

sforceClient.init(null, null, false)

var loginResult=sforceClient.login("myLogin", "myPassword")

alert(loginResult);

 

</script>

 

 

</BODY>

</HTML>