-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.php
134 lines (115 loc) · 2.65 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
class User
{
// state variables
protected $email;
protected $nonce;
protected $userId;
// constructor
public function __construct($newEmail, $newNonce, $newUserId)
{
try
{
$this->setEmail($newEmail);
$this->setNonce($newNonce);
$this->setUserId($newUserId);
}
catch(Exception $e)
{
throw(new Exception("Users object construct failure.", 0, $e));
}
}
// accessors
/**/
/* accessor for email
* input none
* output string email
* throws none */
public function getEmail()
{
return($this->email);
}
/* accessor for nonce
* input none
* output string nonce, or null if nonce is empty. Registered users will not have a nonce.
* throws none */
public function getNonce()
{
return ($this->nonce);
}
/* accessor for userId
* input none
* output int userId
* throws none */
public function getUserId()
{
return($this->userId);
}
// mutators
/*mutator for email
* input string email
* output none
* throws: empty, nonstring, */
public function setEmail($newEmail)
{
if(!is_string($newEmail) || empty($newEmail))
{
throw new Exception("Invalid username or password.");
}
else
{
$this->email = $newEmail;
}
}
/* mutator for nonce
* input: string nonce hex
* output: none
* throws: nonhex */
public function setNonce($newNonce)
{
// FIXME with actual logic that reflects the qualities of the nonce which are TBA
$this->nonce = $newNonce;
}
/* mutator for userId
* intput: int userId
* output: none
* throws: nonint, <= 0 */
public function setUserId($newUserId)
{
if(!is_int($newUserId) || $newUserId <= 0)
{
throw new Exception ("Invalid username or password.");
}
else
{
$this->userId = $newUserId;
}
}
// nonce handling
/* this method must recieve an input from the confirmation process which will create a
* users object and fire a verify-nonce method. The nonce is sent through $_POST data and matched
* in this method, if it matches the nonce which is obtained from the data-row the user's data-row
* is updated with the nonce being null.
* intput: string nonce from registration link
* output: none
* throws: $registrationNonce not a string, hex, and of the appropriate length (regex), failed to match */
/*public function matchNonce($registrationNonce)
{
$p = "/^[0-9a-fA-F]{64}$/";
if(preg_match($registrationNonce, $p) !== 1)
{
throw new Exception("Invalid registration type.");
}
elseif($this->getNonce() !== $registrationNonce)
{
throw new Exception("Invalid registration details.");
}
else
{
// update user row with a null nonce
}
}
*/
// string
}
?>