Commit 2f511134 authored by Michael Ott's avatar Michael Ott
Browse files

add encode and decode functions

parent 7f71f6b7
......@@ -458,10 +458,11 @@ function WebBackend.create_user(WebBackend me)
JSON_OBJECT data;
data =@ JSON_OBJECT.new(.false, me.encoding);
data.members.addmember(KEY_ID, JSON_NUMBER.new(id));
data.members.addmember(KEY_ID, JSON_STRING.new(simpolstringtojsonblob(me.encode(id), me.encoding)));
data.members.addmember(KEY_LOGIN, JSON_STRING.new(simpolstringtojsonblob(login, me.encoding)));
data.members.addmember(KEY_NAME, JSON_STRING.new(simpolstringtojsonblob(name, me.encoding)));
data.members.addmember(KEY_MAIL_ADDRESS, JSON_STRING.new(simpolstringtojsonblob(mail_address, me.encoding)));
data.members.addmember(KEY_MAIL_ADDRESS, \
JSON_STRING.new(simpolstringtojsonblob(mail_address, me.encoding)));
me.create_json_response(ERROR_OK, "Successfully created an account, please login!", data);
me.log_handler.info_message("Created new account: " + login + ", email: " + mail_address);
if new_user_mail == .true
......@@ -470,7 +471,7 @@ function WebBackend.create_user(WebBackend me)
result = .true;
else
me.create_json_response(ERROR_INTERNAL, \
"ERROR during registration, please try again, or contact support");
"ERROR during registration, please try again, or contact support");
me.log_handler.error_message("Error: " + .tostr(errno, 10) + " whilst saving during register function");
end if
else
......@@ -515,20 +516,10 @@ function WebBackend.get_user_list(WebBackend me)
while record !@= .nul
if record!project == me.project
JSON_OBJECT item;
string id;
integer len;
id = base64encode(.tostr(record!CustomerNumber, 10));
id = .substr(id, 0, .instr(id, CRLF) - 1);
len = .instr(id, "=");
if (len > 0)
id = .substr(id, 0, len - 1);
end if
string test;
test = base64decode(id);
item =@ JSON_OBJECT.new(.false, me.encoding);
item.members.addmember(KEY_ID, JSON_STRING.new(simpolstringtojsonblob(id, me.encoding)));
item.members.addmember(KEY_ID, \
JSON_STRING.new(simpolstringtojsonblob(me.encode(record!CustomerNumber), me.encoding)));
item.members.addmember(KEY_LOGIN, JSON_STRING.new(simpolstringtojsonblob(record!LoginName, me.encoding)));
item.members.addmember(KEY_NAME, JSON_STRING.new(simpolstringtojsonblob(record!Nameline, me.encoding)));
item.members.addmember(KEY_MAIL_ADDRESS, \
......@@ -575,4 +566,4 @@ function WebBackend.find_user(WebBackend me, integer user_id)
me.create_json_response(ERROR_AUTH, "Cannot find user");
me.log_handler.info_message("Cannot find user with id " + .tostr(user_id, 10));
end if
end function record
\ No newline at end of file
end function record
......@@ -59,15 +59,18 @@ type WebBackend export
function new readonly;
function init readonly;
function is_auth readonly;
function create_session readonly;
function register readonly;
function get_json_object readonly;
function create_json_response readonly;
function open_table readonly;
function create_response readonly;
function open_table readonly;
function encode readonly;
function decode readonly;
function open_session_file readonly;
function open_user_data readonly;
function login readonly;
function create_session readonly;
function reset_password readonly;
function update_password readonly;
function users readonly;
......@@ -434,6 +437,57 @@ function WebBackend.open_table(WebBackend me, string table)
end if
end function file
//////////////////////////////////////////////////////////////////////////
// encode
//
// Parameters
// ==========
// WebBackend backend: Pointer to WebBackend object
// integer i: integer to encode
//
// Description
// ===========
// Encode an integer
//
// Return Value
// ============
// Encoded string
//////////////////////////////////////////////////////////////////////////
function WebBackend.encode(WebBackend me, integer i)
string result;
integer len;
result = base64encode(.tostr(i, 10));
result = .substr(result, 0, .instr(result, CRLF) - 1);
len = .instr(result, "=");
if (len > 0)
result = .substr(result, 0, len - 1);
end if
end function result;
//////////////////////////////////////////////////////////////////////////
// decode
//
// Parameters
// ==========
// WebBackend backend: Pointer to WebBackend object
// string str: string to decode
//
// Description
// ===========
// Decode a string
//
// Return Value
// ============
// Decoded integer
//////////////////////////////////////////////////////////////////////////
function WebBackend.decode(WebBackend me, string str)
integer result;
str = base64decode(str);
result = .toval(str, nondigits(str), 10);
end function result;
//////////////////////////////////////////////////////////////////////////
// open_session_file
//
......@@ -455,10 +509,10 @@ function WebBackend.open_session_file(WebBackend me)
me.sessions_file =@ SessionsFile.new();
if me.sessions_file.open(me.ppcs, me.ppsc_ip_address, me.session_file_table) != 0
me.create_json_response(ERROR_INTERNAL, \
"Error opening the session table, please contact the " + me.webmaster + ", IP address=" + me.ppsc_ip_address + \
", inifile=" + CGI_INI_FILE);
"Error opening the session table, please contact the " + me.webmaster + ", IP address=" + me.ppsc_ip_address + \
", inifile=" + CGI_INI_FILE);
me.log_handler.info_message("Error opening the session file, please contact the " + me.webmaster + \
", IP address=" + me.ppsc_ip_address + ", inifile=" + CGI_INI_FILE);
", IP address=" + me.ppsc_ip_address + ", inifile=" + CGI_INI_FILE);
result = .false;
else
result = .true;
......@@ -486,10 +540,10 @@ function WebBackend.open_user_data(WebBackend me)
me.user_data =@ UserData.new();
if me.user_data.open(me.user_data_table, me.ppcs, me.ppsc_ip_address) != 0
me.create_json_response(ERROR_INTERNAL, \
"Error opening the address file, please contact the " + me.webmaster + ", IP address=" + me.ppsc_ip_address + \
", inifile=" + CGI_INI_FILE);
"Error opening the address file, please contact the " + me.webmaster + ", IP address=" + me.ppsc_ip_address + \
", inifile=" + CGI_INI_FILE);
me.log_handler.info_message("Error opening the address file, please contact the " + me.webmaster + \
", IP address=" + me.ppsc_ip_address + ", inifile=" + CGI_INI_FILE);
", IP address=" + me.ppsc_ip_address + ", inifile=" + CGI_INI_FILE);
result = .false;
else
result = .true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment