CWIS Developer Documentation

- Home
- Main Page
- Classes
- Files

- File List
- File Members

SPTUser.php
Go to the documentation of this file.
1 <?PHP
2
3 #
4 # FILE: SPT--SPTUser.php
5 #
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/
9 #
10
11 class SPTUser extends CWUser {
12 # ---- PUBLIC INTERFACE --------------------------------------------------
13 # ---- user interface preference mnemonics
14 # color avoidance flags
15 const UIPREF_AVOID_RED = 1;
16 const UIPREF_AVOID_REDGREEN = 2;
17 const UIPREF_AVOID_BLUEYELLOW = 4;
18 const UIPREF_AVOID_GREENYELLOW = 8;
19 const UIPREF_AVOID_ORANGE = 16;
20 const UIPREF_AVOID_REDBLACK = 32;
21 const UIPREF_AVOID_PURPLEGREY = 64;
22 const UIPREF_AVOID_USEMAXMONOCHR = 128;
23
24 # content display options
25 const UIPREF_CONTENTDENSITY_NOPREFERENCE = 0;
26 const UIPREF_CONTENTDENSITY_DETAILED = 1;
27 const UIPREF_CONTENTDENSITY_OVERVIEW = 2;
28
29 # content view options
30 const UIPREF_CONTENTVIEW_NOPREFERENCE = 0;
31 const UIPREF_CONTENTVIEW_TEXTINTENSIVE = 1;
32 const UIPREF_CONTENTVIEW_IMAGEINTENSIVE = 2;
33
34 # audio description options
35 const UIPREF_AUDIODESCRIPTION_NONE = 0;
36 const UIPREF_AUDIODESCRIPTION_STANDARD = 1;
37 const UIPREF_AUDIODESCRIPTION_EXPANDED = 2;
38
39 # caption type options
40 const UIPREF_CAPTIONTYPE_NONE = 0;
41 const UIPREF_CAPTIONTYPE_VERBATIM = 1;
42 const UIPREF_CAPTIONTYPE_REDUCEDREADINGLEVEL = 2;
43
44 # object constructor
45 function SPTUser($UserInfo = NULL)
46 {
47 # call parent constructor
48 $this->User($UserInfo);
49
50 # if user is logged in
51 if ($this->IsLoggedIn())
52 {
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())
57 {
58 # load in UI preferences
59 $this->UserUIPreferencesCache = $this->DB->FetchRow();
60 }
61 else
62 {
63 # add UI preferences record to DB for user
64 $this->DB->Query("INSERT INTO UserUIPreferences"
65 ." (UserId) VALUES (".$this->Id().")");
66 }
67 }
68 }
69
70 # user interface / accessibility preferences
71 function PrefFontSize($NewValue = DB_NOVALUE)
72 { return $this->UUPUpdateValue("FontSize", $NewValue); }
73 function PrefFontTypeFace($NewValue = DB_NOVALUE)
74 { return $this->UUPUpdateValue("FontTypeFace", $NewValue); }
75 function PrefFontColor($NewValue = DB_NOVALUE)
76 { return $this->UUPUpdateValue("FontColor", $NewValue); }
77 function PrefBackgroundColor($NewValue = DB_NOVALUE)
78 { return $this->UUPUpdateValue("BackgroundColor", $NewValue); }
79 function PrefColorAvoidanceFlags($NewValue = DB_NOVALUE)
80 { return $this->UUPUpdateValue("ColorAvoidanceFlags", $NewValue); }
81 function PrefContentDensity($NewValue = DB_NOVALUE)
82 { return $this->UUPUpdateValue("ContentDensity", $NewValue); }
83 function PrefContentView($NewValue = DB_NOVALUE)
84 { return $this->UUPUpdateValue("ContentView", $NewValue); }
85 function PrefAudioDescriptionLevel($NewValue = DB_NOVALUE)
86 { return $this->UUPUpdateValue("AudioDescriptionLevel", $NewValue); }
87 function PrefAudioDescriptionLanguage($NewValue = DB_NOVALUE)
88 { return $this->UUPUpdateValue("AudioDescriptionLanguage", $NewValue); }
89 function PrefVisualDescriptionLanguage($NewValue = DB_NOVALUE)
90 { return $this->UUPUpdateValue("VisualDescriptionLanguage", $NewValue); }
91 function PrefImageDescriptionLanguage($NewValue = DB_NOVALUE)
92 { return $this->UUPUpdateValue("ImageDescriptionLanguage", $NewValue); }
93 function PrefUseGraphicAlternatives($NewValue = DB_NOVALUE)
94 { return $this->UUPUpdateValue("UseGraphicAlternatives", $NewValue); }
95 function PrefSignLanguage($NewValue = DB_NOVALUE)
96 { return $this->UUPUpdateValue("SignLanguage", $NewValue); }
97 function PrefCaptionType($NewValue = DB_NOVALUE)
98 { return $this->UUPUpdateValue("CaptionType", $NewValue); }
99 function PrefCaptionRate($NewValue = DB_NOVALUE)
100 { return $this->UUPUpdateValue("CaptionRate", $NewValue); }
101
111 static function GetCryptKey()
112 {
113 $DB = new Database();
114
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");
118
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();
124
125 # If there is no key in the database, or the key is too old
126 if ( ($Row===FALSE) || ($Row["Age"]>=86400) )
127 {
128 # Generate a new OpenSSL format keypair
129 $KeyPair = openssl_pkey_new(
130 array(
131 'private_key_bits' => 512, # Make this a Sysadmin pref later?
132 'private_key_type' => OPENSSL_KEYTYPE_RSA
133 ));
134
135 # Serialize it for storage
136 openssl_pkey_export($KeyPair, $KeyPairDBFormat);
137
138 # And stick it into the database
139 $DB->Query("INSERT INTO LoginKeys "
140 ."(KeyPair, CreationTime) VALUES ("
141 ."\"".addslashes($KeyPairDBFormat)."\","
142 ."NOW())");
143 }
144 else
145 {
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"] );
149 }
150
151 return $KeyPair;
152 }
153
160 static function ExtractPubKeyParameters($KeyPair)
161 {
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);
164
165 $Modulus = "";
166 $Exponent = "";
167
168 $Patterns = array(
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',
171 );
172
173 foreach ($Patterns as $Pattern)
174 {
175 if (preg_match($Pattern, $Export, $Matches))
176 {
177 $Modulus = $Matches[1];
178 $Exponent = $Matches[2];
179 break;
180 }
181 }
182
183 # Clean newlines and whitespace out of the modulus
184 $Modulus = preg_replace("/[^0-9a-f]/","",$Modulus);
185
186 # Return key material
187 return array( "Modulus" => $Modulus, "Exponent" => $Exponent );
188 }
189
190 # ---- PRIVATE INTERFACE -------------------------------------------------
191
192 var $UserUIPreferencesCache;
193
194 function UUPUpdateValue($FieldName, $NewValue)
195 {
196 return $this->DB->UpdateValue("UserUIPreferences", $FieldName,
197 $NewValue, "UserId = '".$this->Id()."'",
198 $this->UserUIPreferencesCache);
199 }
200 }
201
202 ?>
User\$DB
$DB
Definition: Axis--User.php:961
SPTUser\PrefUseGraphicAlternatives
PrefUseGraphicAlternatives($NewValue=DB_NOVALUE)
Definition: SPTUser.php:93
User\IsLoggedIn
IsLoggedIn()
Definition: Axis--User.php:431
SPTUser\UIPREF_AVOID_RED
const UIPREF_AVOID_RED
Definition: SPTUser.php:15
SPTUser\PrefAudioDescriptionLanguage
PrefAudioDescriptionLanguage($NewValue=DB_NOVALUE)
Definition: SPTUser.php:87
SPTUser\UIPREF_CONTENTDENSITY_DETAILED
const UIPREF_CONTENTDENSITY_DETAILED
Definition: SPTUser.php:26
SPTUser\UIPREF_CONTENTVIEW_NOPREFERENCE
const UIPREF_CONTENTVIEW_NOPREFERENCE
Definition: SPTUser.php:30
SPTUser\PrefSignLanguage
PrefSignLanguage($NewValue=DB_NOVALUE)
Definition: SPTUser.php:95
SPTUser\UIPREF_CONTENTDENSITY_OVERVIEW
const UIPREF_CONTENTDENSITY_OVERVIEW
Definition: SPTUser.php:27
SPTUser\PrefContentDensity
PrefContentDensity($NewValue=DB_NOVALUE)
Definition: SPTUser.php:81
Database
SQL database abstraction object with smart query caching.
Definition: Axis--Database.php:22
DB_NOVALUE
const DB_NOVALUE
Definition: Axis--Database.php:1180
SPTUser\UIPREF_AVOID_ORANGE
const UIPREF_AVOID_ORANGE
Definition: SPTUser.php:19
SPTUser\UIPREF_CONTENTDENSITY_NOPREFERENCE
const UIPREF_CONTENTDENSITY_NOPREFERENCE
Definition: SPTUser.php:25
SPTUser\UIPREF_CAPTIONTYPE_REDUCEDREADINGLEVEL
const UIPREF_CAPTIONTYPE_REDUCEDREADINGLEVEL
Definition: SPTUser.php:42
SPTUser\UIPREF_CAPTIONTYPE_VERBATIM
const UIPREF_CAPTIONTYPE_VERBATIM
Definition: SPTUser.php:41
SPTUser\UIPREF_CONTENTVIEW_IMAGEINTENSIVE
const UIPREF_CONTENTVIEW_IMAGEINTENSIVE
Definition: SPTUser.php:32
SPTUser\ExtractPubKeyParameters
static ExtractPubKeyParameters($KeyPair)
Extract the modulus and exponent of the public key from an OpenSSL format keypair to send in login fo...
Definition: SPTUser.php:160
User\User
User($UserInfoOne=NULL, $UserInfoTwo=NULL)
Definition: Axis--User.php:47
SPTUser\PrefFontColor
PrefFontColor($NewValue=DB_NOVALUE)
Definition: SPTUser.php:75
SPTUser\UIPREF_AUDIODESCRIPTION_EXPANDED
const UIPREF_AUDIODESCRIPTION_EXPANDED
Definition: SPTUser.php:37
SPTUser\UIPREF_CONTENTVIEW_TEXTINTENSIVE
const UIPREF_CONTENTVIEW_TEXTINTENSIVE
Definition: SPTUser.php:31
SPTUser\PrefBackgroundColor
PrefBackgroundColor($NewValue=DB_NOVALUE)
Definition: SPTUser.php:77
PHP
PHP
Definition: OAIClient.php:39
SPTUser\PrefVisualDescriptionLanguage
PrefVisualDescriptionLanguage($NewValue=DB_NOVALUE)
Definition: SPTUser.php:89
SPTUser\UIPREF_AUDIODESCRIPTION_NONE
const UIPREF_AUDIODESCRIPTION_NONE
Definition: SPTUser.php:35
SPTUser
Definition: SPTUser.php:11
SPTUser\PrefFontSize
PrefFontSize($NewValue=DB_NOVALUE)
Definition: SPTUser.php:71
SPTUser\UIPREF_AVOID_REDBLACK
const UIPREF_AVOID_REDBLACK
Definition: SPTUser.php:20
SPTUser\UIPREF_AVOID_GREENYELLOW
const UIPREF_AVOID_GREENYELLOW
Definition: SPTUser.php:18
SPTUser\SPTUser
SPTUser($UserInfo=NULL)
Definition: SPTUser.php:45
SPTUser\PrefContentView
PrefContentView($NewValue=DB_NOVALUE)
Definition: SPTUser.php:83
SPTUser\UIPREF_AVOID_REDGREEN
const UIPREF_AVOID_REDGREEN
Definition: SPTUser.php:16
SPTUser\UIPREF_AVOID_USEMAXMONOCHR
const UIPREF_AVOID_USEMAXMONOCHR
Definition: SPTUser.php:22
SPTUser\UIPREF_AVOID_BLUEYELLOW
const UIPREF_AVOID_BLUEYELLOW
Definition: SPTUser.php:17
SPTUser\GetCryptKey
static GetCryptKey()
Get/generate a cryptographic keypair for user login.
Definition: SPTUser.php:111
User\Id
Id()
Definition: Axis--User.php:189
SPTUser\UUPUpdateValue
UUPUpdateValue($FieldName, $NewValue)
Definition: SPTUser.php:194
SPTUser\UIPREF_AUDIODESCRIPTION_STANDARD
const UIPREF_AUDIODESCRIPTION_STANDARD
Definition: SPTUser.php:36
SPTUser\PrefImageDescriptionLanguage
PrefImageDescriptionLanguage($NewValue=DB_NOVALUE)
Definition: SPTUser.php:91
SPTUser\$UserUIPreferencesCache
$UserUIPreferencesCache
Definition: SPTUser.php:192
SPTUser\UIPREF_CAPTIONTYPE_NONE
const UIPREF_CAPTIONTYPE_NONE
Definition: SPTUser.php:40
SPTUser\PrefColorAvoidanceFlags
PrefColorAvoidanceFlags($NewValue=DB_NOVALUE)
Definition: SPTUser.php:79
SPTUser\PrefCaptionType
PrefCaptionType($NewValue=DB_NOVALUE)
Definition: SPTUser.php:97
SPTUser\PrefCaptionRate
PrefCaptionRate($NewValue=DB_NOVALUE)
Definition: SPTUser.php:99
SPTUser\PrefAudioDescriptionLevel
PrefAudioDescriptionLevel($NewValue=DB_NOVALUE)
Definition: SPTUser.php:85
SPTUser\PrefFontTypeFace
PrefFontTypeFace($NewValue=DB_NOVALUE)
Definition: SPTUser.php:73
CWUser
CWIS-specific user class.
Definition: CWUser.php:13
SPTUser\UIPREF_AVOID_PURPLEGREY
const UIPREF_AVOID_PURPLEGREY
Definition: SPTUser.php:21