summaryrefslogtreecommitdiff
path: root/framework/Web/Security/TMembership.php
blob: 2909eb8b1b3dc57cdc50d189982ee0511c7ad09f (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
<?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()
	{
		return self::$_Provider;
	}
	public static function getProviders()
	{
		return self::$_Providers;
	}
	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::$__s_Initialized)
		{
			if (self::$__s_InitializeException!==null)
			{
				throw new self::$__s_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);
	}
}
?>