Fixed typos
Renamed class CMS_SESSION_CONSTANT to CMS_SESSION_CONSTANTS Removed unneeded classes and files. Update SQL implementation.
This commit is contained in:
@@ -99,7 +99,7 @@ feature {CMS_API} -- Module management
|
||||
l_sql_storage.sql_execute_file_script (api.module_resource_location (Current, (create {PATH}.make_from_string ("scripts")).extended ("oauth2_consumers.sql")), Void)
|
||||
|
||||
if l_sql_storage.has_error then
|
||||
api.logger.put_error ("Could not initialize database for blog module", generating_type)
|
||||
api.logger.put_error ("Could not initialize database for oauth_20 module", generating_type)
|
||||
end
|
||||
-- TODO workaround.
|
||||
l_sql_storage.sql_execute_file_script (api.module_resource_location (Current, (create {PATH}.make_from_string ("scripts")).extended ("oauth2_consumers_initialize.sql")), Void)
|
||||
@@ -108,7 +108,7 @@ feature {CMS_API} -- Module management
|
||||
-- TODO workaround, until we have an admin module
|
||||
l_sql_storage.sql_query ("SELECT name FROM oauth2_consumers;", Void)
|
||||
if l_sql_storage.has_error then
|
||||
api.logger.put_error ("Could not initialize database for differnent consumerns", generating_type)
|
||||
api.logger.put_error ("Could not initialize database for differnent consumers", generating_type)
|
||||
else
|
||||
from
|
||||
l_sql_storage.sql_start
|
||||
@@ -227,7 +227,10 @@ feature -- Hooks
|
||||
until
|
||||
lnk2 /= Void
|
||||
loop
|
||||
if ic.item.location.same_string ("account/roc-logout") or else ic.item.location.same_string ("basic_auth_logoff") then
|
||||
if
|
||||
ic.item.location.same_string ("account/roc-logout") or else
|
||||
ic.item.location.same_string ("basic_auth_logoff")
|
||||
then
|
||||
lnk2 := ic.item
|
||||
end
|
||||
end
|
||||
|
||||
@@ -203,7 +203,10 @@ feature -- Hooks
|
||||
until
|
||||
lnk2 /= Void
|
||||
loop
|
||||
if ic.item.location.same_string ("account/roc-logout") or else ic.item.location.same_string ("basic_auth_logoff") then
|
||||
if
|
||||
ic.item.location.same_string ("account/roc-logout") or else
|
||||
ic.item.location.same_string ("basic_auth_logoff")
|
||||
then
|
||||
lnk2 := ic.item
|
||||
end
|
||||
end
|
||||
|
||||
@@ -91,7 +91,7 @@ feature {CMS_API} -- Module management
|
||||
l_sql_storage.sql_execute_file_script (api.module_resource_location (Current, (create {PATH}.make_from_string ("scripts")).extended ("session_auth_table.sql")), Void)
|
||||
|
||||
if l_sql_storage.has_error then
|
||||
api.logger.put_error ("Could not initialize database for blog module", generating_type)
|
||||
api.logger.put_error ("Could not initialize database for session auth module", generating_type)
|
||||
end
|
||||
end
|
||||
l_sql_storage.sql_finalize
|
||||
@@ -141,11 +141,11 @@ feature {NONE} -- Implementation: routes
|
||||
l_cookie: WSF_COOKIE
|
||||
do
|
||||
if
|
||||
attached {WSF_STRING} req.cookie ({CMS_SESSION_CONSTANT}.session_auth_token) as l_cookie_token and then
|
||||
attached {WSF_STRING} req.cookie ({CMS_SESSION_CONSTANTS}.session_auth_token) as l_cookie_token and then
|
||||
attached {CMS_USER} current_user (req) as l_user
|
||||
then
|
||||
-- Logout Session
|
||||
create l_cookie.make ({CMS_SESSION_CONSTANT}.session_auth_token, l_cookie_token.value)
|
||||
create l_cookie.make ({CMS_SESSION_CONSTANTS}.session_auth_token, l_cookie_token.value)
|
||||
l_cookie.set_path ("/")
|
||||
l_cookie.set_max_age (-1)
|
||||
res.add_cookie (l_cookie)
|
||||
@@ -181,8 +181,8 @@ feature {NONE} -- Implementation: routes
|
||||
else
|
||||
l_session_api.new_user_session_auth (l_token, l_user)
|
||||
end
|
||||
create l_cookie.make ({CMS_SESSION_CONSTANT}.session_auth_token, l_token)
|
||||
l_cookie.set_max_age (60*60*24*360)
|
||||
create l_cookie.make ({CMS_SESSION_CONSTANTS}.session_auth_token, l_token)
|
||||
l_cookie.set_max_age ({CMS_SESSION_CONSTANTS}.session_max_age)
|
||||
l_cookie.set_path ("/")
|
||||
res.add_cookie (l_cookie)
|
||||
set_current_user (req, l_user)
|
||||
@@ -219,7 +219,7 @@ feature -- Hooks
|
||||
do
|
||||
if
|
||||
attached a_response.user as u and then
|
||||
attached {WSF_STRING} a_response.request.cookie ({CMS_SESSION_CONSTANT}.session_auth_token)
|
||||
attached {WSF_STRING} a_response.request.cookie ({CMS_SESSION_CONSTANTS}.session_auth_token)
|
||||
then
|
||||
a_value.force ("account/roc-session-logout", "auth_login_strategy")
|
||||
end
|
||||
@@ -235,7 +235,7 @@ feature -- Hooks
|
||||
do
|
||||
if
|
||||
attached a_response.user as u and then
|
||||
attached {WSF_STRING} a_response.request.cookie ({CMS_SESSION_CONSTANT}.session_auth_token)
|
||||
attached {WSF_STRING} a_response.request.cookie ({CMS_SESSION_CONSTANTS}.session_auth_token)
|
||||
then
|
||||
across
|
||||
a_menu_system.primary_menu.items as ic
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {CMS_SESSION_CONSTANT}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_SESSION_CONSTANT
|
||||
|
||||
|
||||
feature
|
||||
session_auth_token: STRING = "EWF_ROC_SESSION_AUTH_TOKEN_"
|
||||
-- Name of Cookie used to keep the session info.
|
||||
end
|
||||
19
modules/session_auth/cms_session_constants.e
Normal file
19
modules/session_auth/cms_session_constants.e
Normal file
@@ -0,0 +1,19 @@
|
||||
note
|
||||
description: "Summary description for {CMS_SESSION_CONSTANTS}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_SESSION_CONSTANTS
|
||||
|
||||
|
||||
feature
|
||||
session_auth_token: STRING = "EWF_ROC_SESSION_AUTH_TOKEN_"
|
||||
-- Name of Cookie used to keep the session info.
|
||||
-- TODO add a config file to be able to customize this value via coniguration file.
|
||||
|
||||
session_max_age: INTEGER = 86400
|
||||
-- Value of the Max-Age, before the cookie expires.
|
||||
-- TODO add a config file to be able to customize this value via coniguration file.
|
||||
|
||||
end
|
||||
@@ -39,7 +39,7 @@ feature -- Basic operations
|
||||
api.logger.put_debug (generator + ".execute ", Void)
|
||||
-- A valid user
|
||||
if
|
||||
attached {WSF_STRING} req.cookie ({CMS_SESSION_CONSTANT}.session_auth_token) as l_roc_auth_session_token
|
||||
attached {WSF_STRING} req.cookie ({CMS_SESSION_CONSTANTS}.session_auth_token) as l_roc_auth_session_token
|
||||
then
|
||||
if attached session_oauth_api.user_by_session_token (l_roc_auth_session_token.value) as l_user then
|
||||
set_current_user (req, l_user)
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {CMS_SESSION_AUTH_LOGOFF_HANDLER}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_SESSION_AUTH_LOGOFF_HANDLER
|
||||
|
||||
inherit
|
||||
CMS_HANDLER
|
||||
|
||||
WSF_URI_HANDLER
|
||||
rename
|
||||
execute as uri_execute,
|
||||
new_mapping as new_uri_mapping
|
||||
end
|
||||
|
||||
WSF_RESOURCE_HANDLER_HELPER
|
||||
redefine
|
||||
do_get
|
||||
end
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- execute
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute request handler.
|
||||
do
|
||||
execute_methods (req, res)
|
||||
end
|
||||
|
||||
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute request handler.
|
||||
do
|
||||
execute_methods (req, res)
|
||||
end
|
||||
|
||||
feature -- HTTP Methods
|
||||
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_page: CMS_RESPONSE
|
||||
l_url: STRING
|
||||
i: INTEGER
|
||||
l_message: STRING
|
||||
do
|
||||
api.logger.put_information (generator + ".do_get Processing basic auth logoff", Void)
|
||||
if attached req.query_parameter ("prompt") as l_prompt then
|
||||
unset_current_user (req)
|
||||
send_access_denied_message (res)
|
||||
else
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
unset_current_user (req)
|
||||
l_page.set_status_code ({HTTP_STATUS_CODE}.unauthorized) -- Note: can not use {HTTP_STATUS_CODE}.unauthorized for redirection
|
||||
l_url := req.absolute_script_url ("")
|
||||
i := l_url.substring_index ("://", 1)
|
||||
if i > 0 then
|
||||
-- Note: this is a hack to have the logout effective on various browser
|
||||
-- (firefox requires this).
|
||||
l_url.replace_substring ("://_logout_basic_auth_@", i, i + 2)
|
||||
end
|
||||
if
|
||||
attached req.http_user_agent as l_user_agent and then
|
||||
browser_name (l_user_agent).is_case_insensitive_equal_general ("Firefox")
|
||||
then
|
||||
-- Set status to refirect
|
||||
-- and redirect to the host page.
|
||||
l_page.set_status_code ({HTTP_STATUS_CODE}.found)
|
||||
l_page.set_redirection (l_url)
|
||||
end
|
||||
create l_message.make_from_string (logout_message)
|
||||
l_message.replace_substring_all ("$site_login", req.absolute_script_url ("/account/roc-login"))
|
||||
l_message.replace_substring_all ("$site_home", req.absolute_script_url (""))
|
||||
l_page.set_main_content (l_message)
|
||||
l_page.execute
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
browser_name (a_user_agent: READABLE_STRING_8): READABLE_STRING_32
|
||||
-- Browser name.
|
||||
-- Must contain Must not contain
|
||||
-- Firefox Firefox/xyz Seamonkey/xyz
|
||||
-- Seamonkey Seamonkey/xyz
|
||||
-- Chrome Chrome/xyz Chromium/xyz
|
||||
-- Chromium Chromium/xyz
|
||||
-- Safari Safari/xyz Chrome/xyz
|
||||
-- Chromium/xyz
|
||||
-- Opera OPR/xyz [1]
|
||||
-- Opera/xyz [2]
|
||||
-- Internet Explorer ;MSIE xyz; Internet Explorer doesn't put its name in the BrowserName/VersionNumber format
|
||||
|
||||
do
|
||||
if
|
||||
a_user_agent.has_substring ("Firefox") and then
|
||||
not a_user_agent.has_substring ("Seamonkey")
|
||||
then
|
||||
Result := "Firefox"
|
||||
elseif a_user_agent.has_substring ("Seamonkey") then
|
||||
Result := "Seamonkey"
|
||||
elseif a_user_agent.has_substring ("Chrome") and then not a_user_agent.has_substring ("Chromium")then
|
||||
Result := "Chrome"
|
||||
elseif a_user_agent.has_substring ("Chromium") then
|
||||
Result := "Chromiun"
|
||||
elseif a_user_agent.has_substring ("Safari") and then not (a_user_agent.has_substring ("Chrome") or else a_user_agent.has_substring ("Chromium")) then
|
||||
Result := "Safari"
|
||||
elseif a_user_agent.has_substring ("OPR") or else a_user_agent.has_substring ("Opera") then
|
||||
Result := "Opera"
|
||||
elseif a_user_agent.has_substring ("MSIE") or else a_user_agent.has_substring ("Trident")then
|
||||
Result := "Internet Explorer"
|
||||
else
|
||||
Result := "Unknown"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature {NONE}-- Lougout Message
|
||||
|
||||
logout_message: STRING = "[
|
||||
<div class="cms-logout-message">
|
||||
<h2>You are now signed out</h2>
|
||||
<p>You can <a href="$site_login">log</a> in again, or go to the <a href="$site_home">front page</a>.</p>
|
||||
</div>
|
||||
]"
|
||||
|
||||
|
||||
end
|
||||
@@ -7,6 +7,7 @@ class
|
||||
CMS_SESSION_AUTH_STORAGE_SQL
|
||||
|
||||
inherit
|
||||
|
||||
CMS_SESSION_AUTH_STORAGE_I
|
||||
|
||||
CMS_PROXY_STORAGE_SQL
|
||||
@@ -26,36 +27,35 @@ feature -- Access User
|
||||
-- Retrieve user by token `a_token', if any.
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_string: STRING
|
||||
do
|
||||
error_handler.reset
|
||||
write_information_log (generator + ".user_by_session_token")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_token, "token")
|
||||
sql_insert (Select_user_by_token, l_parameters)
|
||||
sql_query (Select_user_by_token, l_parameters)
|
||||
if not has_error and not sql_after then
|
||||
Result := fetch_user
|
||||
sql_forth
|
||||
if not sql_after then
|
||||
check no_more_than_one: False end
|
||||
check
|
||||
no_more_than_one: False
|
||||
end
|
||||
Result := Void
|
||||
end
|
||||
end
|
||||
sql_finalize
|
||||
end
|
||||
|
||||
|
||||
has_user_token (a_user: CMS_USER): BOOLEAN
|
||||
-- Has the user `a_user' and associated session token?
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_string: STRING
|
||||
do
|
||||
error_handler.reset
|
||||
write_information_log (generator + ".has_user_token")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_user.id, "uid")
|
||||
sql_insert (Select_user_token, l_parameters)
|
||||
sql_query (Select_user_token, l_parameters)
|
||||
if not has_error and not sql_after then
|
||||
if sql_read_integer_64 (1) = 1 then
|
||||
Result := True
|
||||
@@ -66,26 +66,20 @@ feature -- Access User
|
||||
sql_finalize
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Change User token
|
||||
|
||||
new_user_session_auth (a_token: READABLE_STRING_GENERAL; a_user: CMS_USER;)
|
||||
-- Add a new user with oauth2 authentication.
|
||||
-- <Precursor>.
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_string: STRING
|
||||
do
|
||||
error_handler.reset
|
||||
sql_begin_transaction
|
||||
|
||||
write_information_log (generator + ".new_user_session")
|
||||
create l_parameters.make (3)
|
||||
l_parameters.put (a_user.id, "uid")
|
||||
l_parameters.put (a_token, "token")
|
||||
l_parameters.put (create {DATE_TIME}.make_now_utc, "utc_date")
|
||||
|
||||
sql_begin_transaction
|
||||
sql_insert (sql_insert_session_auth, l_parameters)
|
||||
sql_commit_transaction
|
||||
sql_finalize
|
||||
@@ -95,24 +89,19 @@ feature -- Change User token
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_string: STRING
|
||||
do
|
||||
error_handler.reset
|
||||
sql_begin_transaction
|
||||
|
||||
write_information_log (generator + ".update_user_session_auth")
|
||||
create l_parameters.make (3)
|
||||
l_parameters.put (a_user.id, "uid")
|
||||
l_parameters.put (a_token, "token")
|
||||
l_parameters.put (create {DATE_TIME}.make_now_utc, "utc_date")
|
||||
|
||||
|
||||
sql_begin_transaction
|
||||
sql_modify (sql_update_session_auth, l_parameters)
|
||||
sql_commit_transaction
|
||||
sql_finalize
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
fetch_user: detachable CMS_USER
|
||||
@@ -126,7 +115,6 @@ fetch_user: detachable CMS_USER
|
||||
if attached sql_read_string_32 (2) as s and then not s.is_whitespace then
|
||||
l_name := s
|
||||
end
|
||||
|
||||
if l_name /= Void then
|
||||
create Result.make (l_name)
|
||||
if l_id > 0 then
|
||||
@@ -135,7 +123,6 @@ fetch_user: detachable CMS_USER
|
||||
elseif l_id > 0 then
|
||||
create Result.make_with_id (l_id)
|
||||
end
|
||||
|
||||
if Result /= Void then
|
||||
if attached sql_read_string (3) as l_password then
|
||||
-- FIXME: should we return the password here ???
|
||||
@@ -148,10 +135,11 @@ fetch_user: detachable CMS_USER
|
||||
Result.set_status (l_status)
|
||||
end
|
||||
else
|
||||
check expected_valid_user: False end
|
||||
check
|
||||
expected_valid_user: False
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- SQL statements
|
||||
|
||||
@@ -160,10 +148,8 @@ feature {NONE} -- SQL statements
|
||||
|
||||
Sql_insert_session_auth: STRING = "INSERT INTO session_auth (uid, access_token, created) VALUES (:uid, :token, :utc_date);"
|
||||
|
||||
|
||||
Sql_update_session_auth: STRING = "UPDATE session_auth SET access_token = :token, created = :utc_date WHERE uid =:uid;"
|
||||
|
||||
|
||||
Select_user_token: STRING = "SELECT COUNT(*) FROM session_auth where uid = :uid;"
|
||||
|
||||
end
|
||||
|
||||
@@ -1,325 +0,0 @@
|
||||
var ROC_AUTH = ROC_AUTH || { };
|
||||
|
||||
var loginURL = "/basic_auth_login";
|
||||
var logoutURL = "/basic_auth_logoff";
|
||||
|
||||
var userAgent = navigator.userAgent.toLowerCase();
|
||||
var firstLogIn = true;
|
||||
|
||||
ROC_AUTH.login = function() {
|
||||
var form = document.forms['cms_basic_auth'];
|
||||
var username = form.username.value;
|
||||
var password = form.password.value;
|
||||
//var host = form.host.value;
|
||||
var origin = window.location.origin + window.location.pathname;
|
||||
var _login = function(){
|
||||
|
||||
|
||||
if (document.getElementById('myModalFormId') !== null ) {
|
||||
ROC_AUTH.remove ('myModalFormId');
|
||||
}
|
||||
|
||||
|
||||
if (username === "" || password === "") {
|
||||
if (document.getElementById('myModalFormId') === null ) {
|
||||
var newdiv = document.createElement('div');
|
||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||
newdiv.id = 'myModalFormId';
|
||||
$(".primary-tabs").append(newdiv);
|
||||
}
|
||||
}else{
|
||||
|
||||
//Instantiate HTTP Request
|
||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||
request.open("GET", loginURL, true, username, password);
|
||||
request.send(null);
|
||||
|
||||
//Process Response
|
||||
request.onreadystatechange = function(){
|
||||
if (request.readyState == 4) {
|
||||
if (request.status==200) {
|
||||
delete form;
|
||||
window.location=window.location.origin;
|
||||
}
|
||||
else{
|
||||
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
||||
}
|
||||
|
||||
if (document.getElementById('myModalFormId') === null ) {
|
||||
var newdiv = document.createElement('div');
|
||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||
newdiv.id = 'myModalFormId';
|
||||
$(".primary-tabs").append(newdiv);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var userAgent = navigator.userAgent.toLowerCase();
|
||||
if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
||||
if (firstLogIn) _login();
|
||||
else logoff(_login);
|
||||
}
|
||||
else{
|
||||
_login();
|
||||
}
|
||||
|
||||
if (firstLogIn) firstLogIn = false;
|
||||
};
|
||||
|
||||
|
||||
ROC_AUTH.login_with_redirect = function() {
|
||||
var form = document.forms[2];
|
||||
var username = form.username.value;
|
||||
var password = form.password.value;
|
||||
var host = form.host.value;
|
||||
var _login = function(){
|
||||
|
||||
var redirectURL = form.redirect && form.redirect.value || "";
|
||||
|
||||
|
||||
$("#imgProgressRedirect").show();
|
||||
|
||||
if (document.getElementById('myModalFormId') !== null ) {
|
||||
ROC_AUTH.remove ('myModalFormId');
|
||||
}
|
||||
|
||||
|
||||
if (username === "" || password === "") {
|
||||
if (document.getElementById('myModalFormId') === null ) {
|
||||
var newdiv = document.createElement('div');
|
||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||
newdiv.id = 'myModalFormId';
|
||||
$(".primary-tabs").append(newdiv);
|
||||
$("#imgProgressRedirect").hide();
|
||||
}
|
||||
}else{
|
||||
|
||||
//Instantiate HTTP Request
|
||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||
request.open("GET", host.concat(loginURL), true, username, password);
|
||||
request.send(null);
|
||||
|
||||
//Process Response
|
||||
request.onreadystatechange = function(){
|
||||
if (request.readyState == 4) {
|
||||
if (request.status==200) {
|
||||
if (redirectURL === "") {
|
||||
window.location=host.concat("/");
|
||||
} else {
|
||||
window.location=host.concat(redirectURL);
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
||||
}
|
||||
|
||||
if (document.getElementById('myModalFormId') === null ) {
|
||||
var newdiv = document.createElement('div');
|
||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||
newdiv.id = 'myModalFormId';
|
||||
$(".primary-tabs").append(newdiv);
|
||||
$("#imgProgressRedirect").hide();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var userAgent = navigator.userAgent.toLowerCase();
|
||||
if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
||||
if (firstLogIn) _login();
|
||||
else logoff(_login);
|
||||
}
|
||||
else{
|
||||
_login();
|
||||
}
|
||||
|
||||
if (firstLogIn) firstLogIn = false;
|
||||
};
|
||||
|
||||
|
||||
ROC_AUTH.getQueryParameterByName = function (name) {
|
||||
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
||||
results = regex.exec(location.search);
|
||||
return results === null ? " " : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||
}
|
||||
|
||||
ROC_AUTH.logoff = function(callback){
|
||||
var form = document.forms[0];
|
||||
var host = form.host.value;
|
||||
|
||||
if (userAgent.indexOf("msie") != -1) {
|
||||
document.execCommand("ClearAuthenticationCache");
|
||||
}
|
||||
else if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
||||
|
||||
var request1 = new XMLHttpRequest();
|
||||
var request2 = new XMLHttpRequest();
|
||||
|
||||
//Logout. Tell the server not to return the "WWW-Authenticate" header
|
||||
request1.open("GET", host.concat(logoutURL) + "?prompt=false", true);
|
||||
request1.send("");
|
||||
request1.onreadystatechange = function(){
|
||||
if (request1.readyState == 4) {
|
||||
|
||||
//Sign in with dummy credentials to clear the auth cache
|
||||
request2.open("GET", host.concat(logoutURL), true, "logout", "logout");
|
||||
request2.send("");
|
||||
|
||||
request2.onreadystatechange = function(){
|
||||
if (request2.readyState == 4) {
|
||||
if (callback!=null) { callback.call(); } else { window.location=host.concat(logoutURL);}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||
request.open("GET", host.concat(logoutURL), true, "logout", "logout");
|
||||
request.send("");
|
||||
request.onreadystatechange = function(){
|
||||
if (request.status==401 || request.status==403 ) { window.location=host.concat(logoutURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ROC_AUTH.remove = function (id)
|
||||
{
|
||||
var element = document.getElementById(id);
|
||||
element.outerHTML = "";
|
||||
delete element;
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
if (typeof String.prototype.contains != 'function') {
|
||||
String.prototype.contains = function (str){
|
||||
return this.indexOf(str) != -1;
|
||||
};
|
||||
}
|
||||
ROC_AUTH.progressive_loging();
|
||||
|
||||
});
|
||||
|
||||
|
||||
ROC_AUTH.progressive_loging = function () {
|
||||
|
||||
ROC_AUTH.login_href();
|
||||
};
|
||||
|
||||
|
||||
$(document).keypress(function(e) {
|
||||
if ((e.which === 13) && (e.target.localName === 'input' && e.target.id === 'password')) {
|
||||
ROC_AUTH.login();
|
||||
}
|
||||
});
|
||||
|
||||
ROC_AUTH.OnOneClick = function(event) {
|
||||
event.preventDefault();
|
||||
if ( document.forms[0] === undefined ) {
|
||||
ROC_AUTH.create_form();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
ROC_AUTH.login_href = function() {
|
||||
var els = document.getElementsByTagName("a");
|
||||
for (var i = 0, l = els.length; i < l; i++) {
|
||||
var el = els[i];
|
||||
if (el.href.contains("/basic_auth_login?destination")) {
|
||||
loginURL = el.href;
|
||||
var OneClick = el;
|
||||
OneClick.addEventListener('click', ROC_AUTH.OnOneClick, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ROC_AUTH.create_form = function() {
|
||||
|
||||
// Fetching HTML Elements in Variables by ID.
|
||||
var createform = document.createElement('form'); // Create New Element Form
|
||||
createform.setAttribute("action", ""); // Setting Action Attribute on Form
|
||||
createform.setAttribute("method", "post"); // Setting Method Attribute on Form
|
||||
$("body").append(createform);
|
||||
|
||||
var heading = document.createElement('h2'); // Heading of Form
|
||||
heading.innerHTML = "Login Form ";
|
||||
createform.appendChild(heading);
|
||||
|
||||
var line = document.createElement('hr'); // Giving Horizontal Row After Heading
|
||||
createform.appendChild(line);
|
||||
|
||||
var linebreak = document.createElement('br');
|
||||
createform.appendChild(linebreak);
|
||||
|
||||
var namelabel = document.createElement('label'); // Create Label for Name Field
|
||||
namelabel.innerHTML = "Username : "; // Set Field Labels
|
||||
createform.appendChild(namelabel);
|
||||
|
||||
var inputelement = document.createElement('input'); // Create Input Field for UserName
|
||||
inputelement.setAttribute("type", "text");
|
||||
inputelement.setAttribute("name", "username");
|
||||
inputelement.setAttribute("required","required");
|
||||
createform.appendChild(inputelement);
|
||||
|
||||
var linebreak = document.createElement('br');
|
||||
createform.appendChild(linebreak);
|
||||
|
||||
var passwordlabel = document.createElement('label'); // Create Label for Password Field
|
||||
passwordlabel.innerHTML = "Password : ";
|
||||
createform.appendChild(passwordlabel);
|
||||
|
||||
var passwordelement = document.createElement('input'); // Create Input Field for Password.
|
||||
passwordelement.setAttribute("type", "password");
|
||||
passwordelement.setAttribute("name", "password");
|
||||
passwordelement.setAttribute("id", "password");
|
||||
passwordelement.setAttribute("required","required");
|
||||
createform.appendChild(passwordelement);
|
||||
|
||||
|
||||
var passwordbreak = document.createElement('br');
|
||||
createform.appendChild(passwordbreak);
|
||||
|
||||
|
||||
var submitelement = document.createElement('button'); // Append Submit Button
|
||||
submitelement.setAttribute("type", "button");
|
||||
submitelement.setAttribute("onclick", "ROC_AUTH.login();");
|
||||
submitelement.innerHTML = "Sign In ";
|
||||
createform.appendChild(submitelement);
|
||||
|
||||
};
|
||||
|
||||
|
||||
var password = document.getElementById("password");
|
||||
var confirm_password = document.getElementById("confirm_password");
|
||||
|
||||
ROC_AUTH.validatePassword =function(){
|
||||
if ((password != null) && (confirm_password != null)) {
|
||||
if(password.value != confirm_password.value) {
|
||||
confirm_password.setCustomValidity("Passwords Don't Match");
|
||||
} else {
|
||||
confirm_password.setCustomValidity('');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((password != null) && (confirm_password != null)) {
|
||||
password.onchange = ROC_AUTH.validatePassword();
|
||||
confirm_password.onkeyup = ROC_AUTH.validatePassword;
|
||||
}
|
||||
Reference in New Issue
Block a user