HttpRequestLogin: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{HTTP function}}
{{HTTP function}}
This function makes the user's browser show a 'basic authentication' login box. The result of the login is handled automatically by the server. If the user has not logged in satisfactorily, you should just call the [[httpRequestLogin]] function again.
This function makes the user's browser show a 'basic authentication' login box. The result of the login is handled automatically by the server. If the user has not logged in satisfactorily, you should just call the [[httpRequestLogin]] function again. It is the script's responsibility to judge when the user is logged in satisfactorily - you can use the ''user'' variable can be used to check if the user has logged in with an account you are happy with. If the logged in user doesn't meet whatever criteria you have, you can just call httpRequestLogin again and they will be re-promoted for their password.


This function works by setting a header ('Authentication') and a return code (403 - Authentication required). As such, nothing happens until you finish the page. The content of the page is generally not displayed unless the login fails.
This function works by setting a header ('Authentication') and a return code (403 - Authentication required). As such, nothing happens until you finish the page. The content of the page is generally not displayed unless the login fails.
Line 10: Line 10:


===Returns===
===Returns===
Returns ''true'' if the relevant headers and return codes have been set, ''false'' otherwise.
Returns ''true'' if the relevant headers and return codes have been set, ''false'' otherwise. Essentially, always returns ''true''.


==Example==
==Example==
 
This example shows how you can make a page that only registered users can see.
<syntaxhighlight lang="lua">
<*
if isGuestAccount(user) then
  httpRequestLogin()
else
*>
Welcome to the top secret area for registered users!
<*
end
*>
</syntaxhighlight>


==See Also==
==See Also==
{{HTTP functions}}
{{HTTP functions}}
[[Category:Needs Example]]

Latest revision as of 20:11, 8 September 2009

This function makes the user's browser show a 'basic authentication' login box. The result of the login is handled automatically by the server. If the user has not logged in satisfactorily, you should just call the httpRequestLogin function again. It is the script's responsibility to judge when the user is logged in satisfactorily - you can use the user variable can be used to check if the user has logged in with an account you are happy with. If the logged in user doesn't meet whatever criteria you have, you can just call httpRequestLogin again and they will be re-promoted for their password.

This function works by setting a header ('Authentication') and a return code (403 - Authentication required). As such, nothing happens until you finish the page. The content of the page is generally not displayed unless the login fails.

Syntax

bool httpRequestLogin ( )

Returns

Returns true if the relevant headers and return codes have been set, false otherwise. Essentially, always returns true.

Example

This example shows how you can make a page that only registered users can see.

<*
if isGuestAccount(user) then
   httpRequestLogin()
else
 *>
Welcome to the top secret area for registered users!
<*
end
 *>

See Also

These functions can only be used from within lua blocks in HTML pages hosted by the server