summaryrefslogtreecommitdiff
path: root/framework/Web/Security/TMembership.php
blob: e68a0a6a3dda3396863af7493d8cf3991dbddd0b (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
 * TMembership class.
 * Validates user credentials and manages user settings. This class cannot be inherited.
 *
 * @author Jason Ragsdale <jrags@jasrags.net>
 * @version $Id: TMembership.php 1398 2006-09-08 19:31:03Z xue $
 * @package System.Web.Security
 * @since 3.1
 */
final class TMembership
{
	private static $_applicationName;
	private static $_enablePasswordReset=false;
	private static $_enablePasswordRetrieval=false;
	private static $_hashAlgorithmType;
	private static $_isHashAlgorithmFromMembershipConfig=false;
	private static $_maxInvalidPasswordAttempts;
	private static $_minRequiredNonAlphanumericCharacters;
	private static $_minRequiredPasswordLength;
	private static $_passwordAttemptWindow;
	private static $_passwordStrengthReqularExpression;
	private static $_provider;
	private static $_providers;
	private static $_requiresQuestionAndAnswer=false;
	private static $_userIsOnlineTimeWindow=15;
	private static $_punctuations='!@#$%^&*()_-+=[{]};:>./?';
	private static $_hashAlgorithmFromConfig=false;
	private static $_initialized=false;
	private static $_initializeException;

	public static function getApplicationName()
	{
		return self::$_applicationName;
	}
	public static function setApplicationName($value)
	{
		self::$_applicationName = TPropertyValue::ensureString($value);
	}
	public static function getEnablePasswordReset()
	{
		return self::$_enablePasswordReset;
	}
	public static function getEnablePasswordRetrieval()
	{
		return self::$_enablePasswordRetrieval;
	}
	public static function getHashAlgorithmType()
	{
		return self::$_hashAlgorithmType;
	}
	public static function getHashAlgorithmFromMembershipConfig()
	{
		return self::$_isHashAlgorithmFromMembershipConfig;
	}
	public static function getMaxInvalidPasswordAttempts()
	{
		return self::$_maxInvalidPasswordAttempts;
	}
	public static function getMinRequiredNonAlphanumericCharacters()
	{
		return self::$_minRequiredNonAlphanumericCharacters;
	}
	public static function getMinRequiredPasswordLength()
	{
		return self::$_minRequiredPasswordLength;
	}
	public static function getPasswordAttemptWindow()
	{
		return self::$_passwordAttemptWindow;
	}
	public static function getPasswordStrengthReqularExpression()
	{
		return self::$_passwordStrengthReqularExpression;
	}
	public static function getProvider()
	{
		self::initialize();
		return self::$_provider;
	}
	public static function getProviders($providerName)
	{
		self::initialize();
		return self::$_providers[$providerName];
	}
	public static function getUserIsOnlineTimeWindow()
	{
		return self::$_userIsOnlineTimeWindow;
	}
	public static function createUser($username,$password,$email=null,$passwordQuestion=null,$passwordAnswer=null,$isApproved=null,$providerUserKey=null)
	{
		return self::$_provider->createUser($username,$password,$email,$passwordQuestion,$passwordAnswer,$isApproved,$providerUserKey);
	}
	public static function deleteUser($username,$deleteAllRelatedData=true)
	{
		return self::$_provider->deleteUser($username,$deleteAllRelatedData);
	}
	public static function findUsersByEmail($emailToMatch,$pageIndex=null,$pageSize=null)
	{
		if ($pageIndex < 0 && $pageIndex!==null)
		{
			throw new TException('PageIndex_bad',$pageIndex);
		}
		if ($pageSize > 1 && $pageSize!==null)
		{
			throw new TException('PageSize_bad',$pageSize);
		}
		return self::$_provider->findUsersByEmail($emailToMatch,$pageIndex,$pageSize);
	}
	public static function findUsersByName($usernameToMatch,$pageIndex=null,$pageSize=null)
	{
		if ($pageIndex < 0 && $pageIndex!==null)
		{
			throw new TException('PageIndex_bad',$pageIndex);
		}
		if ($pageSize > 1 && $pageSize!==null)
		{
			throw new TException('PageSize_bad',$pageSize);
		}
		return self::$_provider->findUsersByName($usernameToMatch,$pageIndex,$pageSize);
	}
	public static function generatePassword($length,$numberOfNonAlphanumericCharacters)
	{
		if (($length < 1) || ($length > 0x80))
		{
			throw new TException('Membership_password_length_incorrect');
		}
		if (($numberOfNonAlphanumericCharacters > $length) || ($numberOfNonAlphanumericCharacters < 0))
		{
			throw new TException('Membership_min_required_non_alphanumeric_characters_incorrect',$numberOfNonAlphanumericCharacters);
		}
		//need to do the alpha checking in here
		//		$num1=0;
		//		$buffer1=null;
		//		$chArray1;
		//		$num2=0;
		//		for ($num3 = 0;$num3 < $length; $num3++)
		//		{
		//			$num4 = $buffer[$num3];
		//		}
	}
	public static function getAllUsers($pageIndex=null,$pageSize=null)
	{
		if ($pageIndex < 0 && $pageIndex!==null)
		{
			throw new TException('PageIndex_bad',$pageIndex);
		}
		if ($pageSize > 1 && $pageSize!==null)
		{
			throw new TException('PageSize_bad',$pageSize);
		}
		return self::$_provider->getAllUsers($pageIndex,$pageSize);
	}
	private static function getCurrentUserName()
	{
		//how to get the current username?
	}
	public static function getNumberOfUsersOnline()
	{
		return self::$_provider->getNumberOfUsersOnline();
	}
	public static function getUser($username=null,$providerUserKey=null,$userIsOnline=false)
	{
		if ($username===null && $providerUserKey===null)
		{
			return self::$_provider->getUser(self::GetCurrentUserName(),null,true);
		}
		if ($username===null && $providerUserKey!==null)
		{
			return self::$_provider->getUser(null,$providerUserKey,$userIsOnline);
		}
		if ($username!==null && $providerUserKey===null)
		{
			return self::$_provider->getUser($username,null,$userIsOnline);
		}
	}
	public static function getUserNameByEmail($emailToMatch)
	{
		return self::$_provider->getUserNameByEmail($emailToMatch);
	}
	private static function initialize()
	{
		if (self::$_initialized)
		{
			if (self::$_initializeException!==null)
			{
				throw new self::$_initializeException;
			}
		}
		else
		{

		}
	}
	public static function updateUser(TMembershipUser $user)
	{
		if ($user===null)
		{
			throw new TException('Membership_user_can_not_be_null');
		}
		$user->update();
	}
	public static function validateUser($username,$password)
	{
		return self::$_provider->validateUser($username,$password);
	}
}
?>