4 # FILE: SPT--SPTUser.php
6 # Part of the Collection Workflow Integration System (CWIS)
7 # Copyright 2004-2013 Edward Almasy and Internet Scout Research Group
8 # http://scout.wisc.edu/cwis/
12 # ---- PUBLIC INTERFACE --------------------------------------------------
13 # ---- user interface preference mnemonics
14 # color avoidance flags
24 # content display options
29 # content view options
34 # audio description options
39 # caption type options
47 # call parent constructor
48 $this->
User($UserInfo);
50 # if user is logged in
53 # if user already has a UI preferences record in DB
54 $this->DB->Query(
"SELECT * FROM UserUIPreferences"
55 .
" WHERE UserId = '".$this->
Id().
"'");
56 if ($this->DB->NumRowsSelected())
58 # load in UI preferences
59 $this->UserUIPreferencesCache = $this->DB->FetchRow();
63 # add UI preferences record to DB for user
64 $this->DB->Query(
"INSERT INTO UserUIPreferences"
65 .
" (UserId) VALUES (".$this->
Id().
")");
70 # user interface / accessibility preferences
80 {
return $this->
UUPUpdateValue(
"ColorAvoidanceFlags", $NewValue); }
86 {
return $this->
UUPUpdateValue(
"AudioDescriptionLevel", $NewValue); }
88 {
return $this->
UUPUpdateValue(
"AudioDescriptionLanguage", $NewValue); }
90 {
return $this->
UUPUpdateValue(
"VisualDescriptionLanguage", $NewValue); }
92 {
return $this->
UUPUpdateValue(
"ImageDescriptionLanguage", $NewValue); }
94 {
return $this->
UUPUpdateValue(
"UseGraphicAlternatives", $NewValue); }
115 # Clear all keys more than two days old
116 $DB->Query(
"DELETE FROM LoginKeys WHERE NOW() - CreationTime > 172800");
117 $DB->Query(
"DELETE FROM UsedLoginTokens WHERE NOW()-KeyCTime > 172800");
119 # Get the most recently generated key
120 $DB->Query(
"SELECT NOW()-CreationTime as Age,"
121 .
"KeyPair FROM LoginKeys "
122 .
"ORDER BY Age ASC LIMIT 1");
123 $Row =
$DB->FetchRow();
125 # If there is no key in the database, or the key is too old
126 if ( ($Row===FALSE) || ($Row[
"Age"]>=86400) )
128 # Generate a new OpenSSL format keypair
129 $KeyPair = openssl_pkey_new(
131 'private_key_bits' => 512, # Make
this a Sysadmin pref later?
132 'private_key_type' => OPENSSL_KEYTYPE_RSA
135 # Serialize it for storage
136 openssl_pkey_export($KeyPair, $KeyPairDBFormat);
138 # And stick it into the database
139 $DB->Query(
"INSERT INTO LoginKeys "
140 .
"(KeyPair, CreationTime) VALUES ("
141 .
"\"".addslashes($KeyPairDBFormat).
"\","
146 # If we do have a current key in the database,
147 # Convert it to openssl format for usage
148 $KeyPair = openssl_pkey_get_private( $Row[
"KeyPair"] );
162 # Export the keypair as an ASCII signing request (which contains the data we want)
163 openssl_csr_export(openssl_csr_new(array(), $KeyPair), $Export,
false);
169 '/Modulus \([0-9]+ bit\):(.*)Exponent: [0-9]+ \(0x([0-9a-f]+)\)/ms',
170 '/Public-Key: \([0-9]+ bit\).*Modulus:(.*)Exponent: [0-9]+ \(0x([0-9a-f]+)\)/ms',
173 foreach ($Patterns as $Pattern)
175 if (preg_match($Pattern, $Export, $Matches))
177 $Modulus = $Matches[1];
178 $Exponent = $Matches[2];
183 # Clean newlines and whitespace out of the modulus
184 $Modulus = preg_replace(
"/[^0-9a-f]/",
"",$Modulus);
186 # Return key material
187 return array(
"Modulus" => $Modulus,
"Exponent" => $Exponent );
190 # ---- PRIVATE INTERFACE -------------------------------------------------
196 return $this->DB->UpdateValue(
"UserUIPreferences", $FieldName,
197 $NewValue,
"UserId = '".$this->
Id().
"'",
198 $this->UserUIPreferencesCache);
PrefUseGraphicAlternatives($NewValue=DB_NOVALUE)
PrefAudioDescriptionLanguage($NewValue=DB_NOVALUE)
const UIPREF_CONTENTDENSITY_DETAILED
const UIPREF_CONTENTVIEW_NOPREFERENCE
PrefSignLanguage($NewValue=DB_NOVALUE)
const UIPREF_CONTENTDENSITY_OVERVIEW
PrefContentDensity($NewValue=DB_NOVALUE)
SQL database abstraction object with smart query caching.
const UIPREF_AVOID_ORANGE
const UIPREF_CONTENTDENSITY_NOPREFERENCE
const UIPREF_CAPTIONTYPE_REDUCEDREADINGLEVEL
const UIPREF_CAPTIONTYPE_VERBATIM
const UIPREF_CONTENTVIEW_IMAGEINTENSIVE
static ExtractPubKeyParameters($KeyPair)
Extract the modulus and exponent of the public key from an OpenSSL format keypair to send in login fo...
User($UserInfoOne=NULL, $UserInfoTwo=NULL)
PrefFontColor($NewValue=DB_NOVALUE)
const UIPREF_AUDIODESCRIPTION_EXPANDED
const UIPREF_CONTENTVIEW_TEXTINTENSIVE
PrefBackgroundColor($NewValue=DB_NOVALUE)
PrefVisualDescriptionLanguage($NewValue=DB_NOVALUE)
const UIPREF_AUDIODESCRIPTION_NONE
PrefFontSize($NewValue=DB_NOVALUE)
const UIPREF_AVOID_REDBLACK
const UIPREF_AVOID_GREENYELLOW
PrefContentView($NewValue=DB_NOVALUE)
const UIPREF_AVOID_REDGREEN
const UIPREF_AVOID_USEMAXMONOCHR
const UIPREF_AVOID_BLUEYELLOW
static GetCryptKey()
Get/generate a cryptographic keypair for user login.
UUPUpdateValue($FieldName, $NewValue)
const UIPREF_AUDIODESCRIPTION_STANDARD
PrefImageDescriptionLanguage($NewValue=DB_NOVALUE)
const UIPREF_CAPTIONTYPE_NONE
PrefColorAvoidanceFlags($NewValue=DB_NOVALUE)
PrefCaptionType($NewValue=DB_NOVALUE)
PrefCaptionRate($NewValue=DB_NOVALUE)
PrefAudioDescriptionLevel($NewValue=DB_NOVALUE)
PrefFontTypeFace($NewValue=DB_NOVALUE)
CWIS-specific user class.
const UIPREF_AVOID_PURPLEGREY