Jump to content

Client username


skafy

Recommended Posts

 

in client code "MainForm.ClientEvents.ExtEvents.Show" (for example)

function window.show(sender, eOpts)
{
  var WinNetwork = new ActiveXObject("WScript.Network");
  ajaxRequest(sender, 'UserDetailsEvent', ['UserName='+WinNetwork.UserName]);
}

in server code:

procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TStrings);
begin
  if EventName='UserDetailsEvent' then begin
    UniEdit1.Text:=Params.Values['UserName'];
  end;
end;

It seems like UniFormAjaxEvent doesn't catch/fire UserDetailsEvent. When I debug EventName is equal to cinfo, afterrender and resize.

 

I've put AjaxRequest in window.show.

function window.show(sender, eOpts)
{
  var WinNetwork = new ActiveXObject("WScript.Network");
  ajaxRequest(sender, 'UserDetailsEvent', ['UserName='+WinNetwork.UserName]);
}

and

 

call function UniFormAjaxEvent in main form Main (renamed MainForm)

procedure TMain.UniFormAjaxEvent(Sender: TComponent; EventName: string;
  Params: TStrings);
begin
  if EventName='UserDetailsEvent' then
  begin
    CurrentUser:= Params.Values['UserName'];
    WorkflowDM.SetUp(CurrentUser);
    lblCurrentUser.Caption:= WorkflowDM.GetCurrentUserName;
  end;
end;

What am I doing wrong here.

Link to comment
Share on other sites

I've put this simple line of code in windows.show simple alert code and "Hello ExtJS" doesn't pop up. What could be wrong?

function window.show(sender, eOpts)
{
  alert("Hello ExtJS");
}

Hi,

 

Seems all is correct..

 

call function UniFormAjaxEvent in main form Main (renamed MainForm) ???  - Check please again..

yes. I renamed default named MainForm to Main

Link to comment
Share on other sites

Hi,

 

I'm sorry, maybe in your project somewhere there is a mistake,

but it works for me, also works ajaxRequest:

 

Can you make a simple testcase ?!

 

Best regards.

I think I found the problem. In the ServerModule I have set MainFormDisplayMode to mfPage. Can you confirm?

Link to comment
Share on other sites

  • 11 months later...

When I investigate i couldn't find another option. When I think of it now, I will probably change it so user will have to put its credentials once and I would then save it with cookies(would check whid LDAP). It would cover multiple browser insted of just IE. 

Link to comment
Share on other sites

  • 6 months later...
  • 1 year later...

Ok. This is solved.

 

procedure TMain.UniFormCreate(Sender: TObject);

begin

  UniSession.AddJS('var WinNetwork = new ActiveXObject("WScript.Network");');

  UniSession.AddJS('alert(WinNetwork.UserName);');

end;

 

This pops up domain name of currently logged in user. Now I wonder how to get this WinNetwork.Username in a variable in outside JS. Eny ideas?

 

This is not a best practice since:

 

1) Your user may not be on Internet Explorer.

2) Your user may not be with ActiveX enabled. 

 

The best practice is to get the logged user on your application and save that as a log.

 

BUT if you really want this way you need ajaxRequest.

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  UniSession.AddJS('var WinNetwork = new ActiveXObject("WScript.Network");');
  UniSession.AddJS('ajaxRequest(MainForm.UniLabel1, ''WindowsUser'',[''username=''+WinNetwork.UserName]);');
end;

procedure TMainForm.UniLabel1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
  if EventName='WindowsUser' then
  begin
    UniLabel1.Caption := 'UserName: ' + Params['username'].AsString;
  end;
end;
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...