webint_procs.dm - webint_start_singlesignon()

Proc for creating a unique signin token for the website and shoving it into the database.
This commit is contained in:
skull132
2016-03-21 23:04:10 +02:00
parent 6bb74a7a87
commit 997665bca7

View File

@@ -32,4 +32,65 @@
if (!(attribute in required_attributes))
return 0
if (attributes_list[attribute] && required_attributes[attribute])
if (istype(required_attributes, /list))
if (!(attributes_list[attribute] in required_attributes[attribute]))
return 0
else
if (attributes_list[attribute] != required_attributes[attribute])
return 0
return 1
/*
* /proc/webint_start_singlesignon()
* Used to insert a token into the web_sso database and to enable a user to navigate to a page on the website and be automatically logged in. Hashes the user's save file for a unique token. Additional security managed on the website's end.
*
* Arguments:
* - var/user - Must be a mob or a client. The player object that's going to be using the request.
* - var/list/attributes - The attributes to which we route the URL as we call user.process_webint_link().
* Validated here with webint_validate_attributes().
* Must contain the 'location' key.
*
* Returns:
* 0 - if one of the checks is failed and the operation cancelled.
* string - if everything works, it will return the attributes with the added token and ckey value.
*/
/proc/webint_start_singlesignon(var/client/user, var/attributes)
if (!istype(user))
return 0
var/list/permitted_locations = list("user_dashboard", "contract_overview", "contract_details")
if (!webint_validate_attributes(list("location" = permitted_locations, "contract"), attributes_text = attributes))
return 0
var/token = ""
var/list/alphabet = alphabet_uppercase
alphabet.Add(list("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"))
alphabet.Add(list("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"))
for (var/i = 0, i <= 24, i++)
token += alphabet[rand(1, alphabet.len)]
attributes += "&"
attributes += list2params(list("ckey" = user.ckey, "token" = token))
establish_db_connection(dbcon)
if (!dbcon.IsConnected())
alert("An error occured while attempting to connect to the database!")
return 0
var/DBQuery/insert_query = dbcon.NewQuery("INSERT INTO ss13_web_sso (ckey, token, ip, created_at) VALUES (:ckey, :token, :ip, NOW())")
insert_query.Execute(list(":ckey" = user.ckey, ":token" = token, ":ip" = user.address))
if (insert_query.ErrorMsg())
alert("An error occured while trying to upload the session data!")
return 0
if (alert("This will take you to the webpage and log you in. Do you wish to proceed?",,"Yes","No") == "No")
return 0
return attributes