Here you are:
This is the html login page, I gather some extra info like solution, browser and ip address for logging using php, you can omit that:
- Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SintProSystem Login</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="weblogin.jsp">
<label>Username
<input type="text" name="username" id="username" tabindex="1" />
</label>
<p>
<label>Password
<input type="password" name="password" id="password" tabindex="2" />
</label>
</p>
<p>
<label>Language
<select name="language" >
<option value="it" selected="selected">Italiano</option>
<option value="en">English</option>
</select>
</label>
</p>
<p>
<input type="hidden" name="solution" id="solution" value="SintProSystem"/>
<input type="hidden" name="ipaddress" id="ipaddress" value="<?php echo $_SERVER['REMOTE_ADDR']?>"/>
<input type="hidden" name="browser" id="browser" value="<?php echo $_SERVER['HTTP_USER_AGENT']?>"/>
<input type="submit" name="login" id="login" value="Login" tabindex="3" />
</p>
</form>
</body>
</html>
This is the JSP page called by the html form:
- Code: Select all
<%@ page import = "java.util.*" %>
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %>
<%@ page import = "com.servoy.j2db.dataprocessing.IDataSet" %>
<%@ page errorPage="errorpage.jsp" %>
<%
ISessionBean servoy_hc = (ISessionBean)session.getAttribute("servoy");
if (servoy_hc == null)
{
servoy_hc = HeadlessClientFactory.createSessionBean(request,"sintpro_weblogin_mod",null,null);
session.setAttribute("servoy",servoy_hc);
}
boolean ok = servoy_hc.setMainForm("main");
if (!ok)
{
out.print("error cannot work on required form");
return;
}
%>
<%
String user_name = request.getParameter("username");
String passwd = request.getParameter("password");
String language = request.getParameter("language");
String solution = request.getParameter("solution");
String ipaddress = request.getParameter("ipaddress");
String browser = request.getParameter("browser");
String result = "Cannot execute weblogin method!";
result = (String)servoy_hc.executeMethod(null,"webLogin",new Object[]{user_name,passwd,language,solution,ipaddress,browser});
out.println(result);
session.setAttribute("servoy", null);
%>
this is the method called in the webLogin module, if authentication succeeds the solution is loaded and the UUID is passed as argument:
- Code: Select all
function webLogin(_username,_passwd,_language,_solution,_ipaddress,_browser)
{
if(!_username || !_passwd || !_language || !_solution) return 'Missing parameters!';
// Authentication
var fs = databaseManager.getFoundSet('sintpro_mods','sintpro_weblogins')
fs.newRecord()
fs.session_uuid = application.getUUID()
fs.username = _username
fs.language_code = _language
fs.solution_name = _solution
if(_browser) fs.client_info = _browser
if(_ipaddress) fs.ip_address = _ipaddress
var _result = security.authenticate('sintpro_auth_mod', 'authenticate', [_username,utils.stringMD5HashBase64(_passwd)]);
if(_result[0] == false)
{
// Login failed
fs.login_success = 0
databaseManager.saveData(fs)
return _result[1];
}
else
{
// Login succeeded
fs.login_success = 1
databaseManager.saveData(fs)
var url = '/servoy-webclient/ss/s/'+ _solution +'/a/'+ fs.session_uuid
var html = '<HTML> \
<HEAD> \
<META http-equiv="REFRESH" content="0;url='+ url +'"></HEAD> \
<BODY> \
Logging in... \
</BODY> \
</HTML>'
return html;
}
}
and finally this is the onOpen method of the login module that receives the UUID:
- Code: Select all
function onOpen(sessionUUID,args)
{
// Check if a sessionUUID has been provided
if(sessionUUID)
{
// Try to authenticate straight ahead
var _result = security.authenticate('sintpro_auth_mod', 'authenticateBySessionUUID', [sessionUUID]);
if(_result[0] == false)
{
application.output('SessionUUID Login Failed: '+_result[1] +'('+sessionUUID+')',LOGGINGLEVEL.ERROR)
application.exit()
}
else // login successful, proceed to main form...
...
}