{= # # # authentication.cfv # # authentication.cfv is called from the C++ or from the client upon login or when validating a new license # with volatile.authentication_state = not_authenticated | session_timed_out | invalid_license | no_root_admin_password # # # include "templates.util.authentication_util"; debug_message("\n\n#### authentication.cfv \n"); # DEBUG_BEGIN # if (?("v.fp")) then ( # debug_message("\n\n" . node_as_string("v.fp") . "\n\n"); # ) # else ( # debug_message("\n\n#### The node \"v.fp\" does not exist. \n\n"); # ); # # if (?("command_line")) then ( # debug_message("\n" . node_as_string("command_line") . "\n"); # ) # else ( # debug_message("#### authentication.cfv - command_line DOES NOT EXIST \n"); # ); # DEBUG_END # # # # Check the authentication task # # # string authentication_state = "unknown"; bool is_session_timed_out = false; if (?("volatile.authentication_state")) then ( authentication_state = volatile.authentication_state; is_session_timed_out = (authentication_state eq "session_timed_out"); ); bool is_server_backround_call = (?("volatile.is_server_background_call")); bool is_login_form_processing = false; bool is_new_password_form_processing = false; bool is_forgot_password_form_processing = false; bool is_password_reset_form_processing = false; bool is_license_validation = false; bool is_auto_login = false; string username; string password; string new_password; string base_url; string access_code; if (is_server_backround_call) then ( if (?("v.fp.is_login_form_processing")) then ( is_login_form_processing = true; ) else if (?("v.fp.is_new_password_form_processing")) then ( is_new_password_form_processing = true; ) else if (?("v.fp.is_forgot_password_form_processing")) then ( is_forgot_password_form_processing = true; ) else if (?("v.fp.is_password_reset_form_processing")) then ( is_password_reset_form_processing = true; ) else if (?("v.fp.license_key")) then ( is_license_validation = true; ); ) else if (authentication_state eq "not_authenticated") then ( # # Check if this is auto login (username and password is provided in URL) # if (?("command_line.login_username") and @("command_line.login_username") ne "") then ( username = @("command_line.login_username"); ) else if (?("webvars.username")) then ( # We support the deprecated webvars.username for backward compatibility username = @("webvars.username"); ); if (?("command_line.login_password") and @("command_line.login_password") ne "") then ( password = @("command_line.login_password"); ) else if (?("webvars.password")) then ( # We support the deprecated webvars.password for backward compatibility password = @("webvars.password"); ); is_auto_login = (username ne "" or password ne ""); # Check if this is a session time out caused by a previous server background call # but which is not reported by volatile.authentication_state as "session_timed_out" # because this is already the second call of this page initated by javascript. # However, if there was a session_timed_out background call then javascript will # add command_line.session_timed_out to the reloaded URL. # volatile.session_timed_out is set by javacsript in URL if (!is_auto_login and ?("volatile.session_timed_out")) then ( is_session_timed_out = true; ); ); debug_message("#### authentication_state: " . authentication_state . "\n"); debug_message("#### is_server_backround_call: " . is_server_backround_call . "\n"); debug_message("#### is_login_form_processing: " . is_login_form_processing . "\n"); debug_message("#### is_new_password_form_processing: " . is_new_password_form_processing . "\n"); debug_message("#### is_forgot_password_form_processing: " . is_forgot_password_form_processing . "\n"); debug_message("#### is_license_validation: " . is_license_validation . "\n"); debug_message("#### is_auto_login: " . is_auto_login . "\n"); debug_message("#### username: " . username . "\n"); debug_message("#### password: " . password . "\n"); # # # # Handle authentication # # # if (is_login_form_processing) then ( username = v.fp.username; password = v.fp.password; debug_message("#### username: " . username . "\n"); debug_message("#### password: " . password . "\n"); validate_login_form_processing(username, password); ) else if (is_new_password_form_processing) then ( # New password form processing (the existing password expired) username = v.fp.username; password = v.fp.password; new_password = v.fp.new_password; debug_message("#### new_password: " . new_password . "\n"); validate_login_with_new_password_form_processing(username, password, new_password); ) else if (is_forgot_password_form_processing) then ( username = v.fp.username; base_url = v.fp.base_url; validate_forgot_password_form_processing(username, base_url); ) else if (is_password_reset_form_processing) then ( access_code = v.fp.access_code; new_password = v.fp.new_password; validate_password_reset_form_processing(access_code, new_password); ) else if (is_license_validation) then ( # Validate license key (Note, this is a server background call from authentication.cfv!) string license_key = v.fp.license_key; # debug_message("#### license_key: " . license_key . "\n"); authentication_handle_license_submission(license_key); ) else ( if (authentication_state eq "not_authenticated" or is_session_timed_out) then ( handle_not_authenticated_or_session_timed_out( authentication_state, is_session_timed_out, is_auto_login, username, password, is_server_backround_call ); ) else if (authentication_state eq "invalid_license") then ( authentication_handle_invalid_license(); ) else if (authentication_state eq "no_root_admin_password") then ( # KHP-RC no_root_admin_password state error("volatile.authentication_state = \"no_root_admin_password\""); ) else ( error("Unknown authentication_state \"" . authentication_state . "\" in volatile.authentication_state"); ); ); debug_message("#### authentication.cfv END \n\n"); =}