Skip to content
⌘ NSIS Forum Archive

Problems with function calls

4 posts

pedroac#

Problems with function calls

Hello everybody

I have this sequence of pages in my installer:

!insertmacro MUI_PAGE_WELCOME
Page Custom UserPassPageShow
Page Custom fnAuth
!insertmacro MUI_PAGE_DIRECTORY

The UserPassPageShow is the page which presents the user a dialog to insert login and password, and fnAuth is the function that is called to verify the username and password;
if the username and password is correct, the installer advances to the next page and everything is OK;

The code that is being used is:

StrCmp $R4 "success" +3
MessageBox MB_OK "Authentication failed because the credentials are invalid"
Call UserPassPageShow


The problem is that whenever the user credentials are invalid, the installer starts to act in a strange manner (the user validation doesn't work)

Am I doing something wrong?
Thanks a lot
Afrow UK#
What are you trying to do? You don't call UserPassPageShow yourself.

You must set up a Leave function (Page Custom [ShowFunc] [LeaveFunc]) and validate your form from there. Then call Abort if necessary to go back to the page.

-Stu
pedroac#
OK, following your advice, I've done this:

(...)
!insertmacro MUI_PAGE_LICENSE $(license)
Page Custom UserPassPageShow UserPassPageLeave
!insertmacro MUI_PAGE_DIRECTORY
(...)

The UserPassPageShow function presents the user with the dialog to insert username and password;

The UserPassPageLeave has this code:

Pop $R6
Pop $R7

!define AUTH_URL "(SomeUrl)?username=$R6&password=$R7"

NSISDL::download ${AUTH_URL}
Pop $R4
MessageBox MB_OK "Authentication result: R4=$R4"

StrCmp $R4 "success" +4
StrCmp $R4 "HTTP/1.1 403 Forbidden" +4
MessageBox MB_OK "$(msg_auth_failed)"
Abort
Goto sucess
Goto forbidden

forbidden:
MessageBox MB_OK "$(msg_auth_wrong)"
Abort

sucess:
MessageBox MB_OK "$(msg_auth_ok)"


Basically, it verifies username and password in a remote http server, which returns one of three answers, which I catch in $R4:
"success" - valid user credentials
"HTTP/1.1 403 Forbidden" - invalid user credentials
something else - problem contacting server

if the answer is "sucess", I present a message box telling the success and the installer goes on
else I want the installer to go back to the authentication dialog.


The problem is that using this code, the answer I get (value of $R4) is always "Unable to open" followed by some strange caracters.

What am I doing wrong?
Afrow UK#
You need to give NSISdl the file name to save the download as. You're only giving it the download URL so it doesn't know where to save it.

Also to make the code simpler, change:
StrCmp $R4 "success" +4
StrCmp $R4 "HTTP/1.1 403 Forbidden" +4
to:
StrCmp $R4 "success" success
StrCmp $R4 "HTTP/1.1 403 Forbidden" forbidden

-Stu