source: trunk/Modules/User/Registration.php

Last change on this file was 893, checked in by chronos, 21 months ago
  • Fixed: Class types casting for better type checking.
  • Fixed: XML direct export.
  • Modified: User class instance moved from Core class to ModuleUser class.
File size: 7.0 KB
Line 
1<?php
2
3class PageUserRegistration extends Page
4{
5 function ShowForm()
6 {
7 if (array_key_exists('sc', $_POST)) $Human = true;
8 else $Human = false;
9 if (array_key_exists('user', $_POST)) $UserName = $_POST['user'];
10 else $UserName = '';
11 if (array_key_exists('Email', $_POST)) $Email = $_POST['Email'];
12 else $Email = '';
13 if (array_key_exists('Team', $_POST)) $Team = $_POST['Team'];
14 else $Team = '';
15 if (array_key_exists('Language', $_POST)) $Language = $_POST['Language'];
16 else $Language = 1;
17
18 $Output = '<form action="?" method="post" class="Form">
19 <fieldset><legend>'.T('New user registration').'</legend>
20 <table>
21 <tr><td colspan="2">'.sprintf(T('Please read carefully %s and follow them. Translate with diacritics!'),
22 '<a href="'.$this->System->Link('/info/').'">'.T('translation guidelines').'</a>').
23 '<br/><br/></td></tr>
24 <tr>
25 <th class="Left">'.T('Are you human?').'</th>';
26 if ($Human) $Checked = ' checked="checked"';
27 else $Checked = '';
28 $Output .= '<td><input type="checkbox" name="sc" '.$Checked.'/></td>
29 </tr>
30 <tr>
31 <th class="Left">'.T('Name').':</th>
32 <td><input type="text" name="user" value="'.$UserName.'"/></td>
33 </tr>
34 <tr>
35 <th class="Left">'.T('Password').':</th>
36 <td><input type="password" name="pass" /></td>
37 </tr>
38 <tr>
39 <th class="Left">'.T('Password confirmation').':</th>
40 <td><input type="password" name="pass2" /></td>
41 </tr>
42 <tr>
43 <th class="Left">'.T('E-mail').':</th>
44 <td><input type="text" name="Email" value="'.$Email.'"/></td>
45 </tr>
46 <tr>
47 <th class="Left">'.T('I will translate normally to').':</th>
48 <td>'.WriteLanguages($Language).'</td>
49 </tr>
50 <tr>
51 <th class="Left">'.T('I belong to team').':</th>';
52 if ($Team == '') $Selected = ' selected="selected"';
53 else $Selected = '';
54 $Output .= '<td><select name="Team"><option value="0"'.$Selected.'>'.T('none').'</option>';
55 $DbResult = $this->Database->query('SELECT `Name`, `Id` FROM `Team`');
56 while ($Line = $DbResult->fetch_assoc())
57 {
58 if ($Team == $Line['Id']) $Selected = ' selected="selected"';
59 else $Selected = '';
60 $Output .= '<option value="0'.$Line['Id'].'"'.$Selected.'>'.htmlspecialchars($Line['Name']).'</option>';
61 }
62 $Output .= '</select>';
63 $Output .= '</td></tr>'.
64 '<tr><th class="Left">'.T('Preferred client version').':</th><td>'.ClientVersionSelection('').'</td></tr>';
65
66 $Query = 'SELECT * FROM UserTagType';
67 $DbResult = $this->Database->query($Query);
68 $Output .= '<tr><th class="Left">'.
69 T('Select rules which you will apply during translation').':</th><td>';
70 while ($UserTag = $DbResult->fetch_array())
71 {
72 $checked = false;
73
74 $Output .= CheckBox('Tag'.$UserTag['ID'], $checked, 'CheckBox');
75 $Output .= ''.$UserTag['Text'].'<br />';
76 }
77 $Output .= '</td></tr>';
78
79 $Output .= '<tr>
80 <th colspan="2" class="Center"><input type="submit" value="'.T('Register').'" /></th>
81 </tr>
82 </table></fieldset></form>';
83 return $Output;
84 }
85
86 function CheckRegistration()
87 {
88 $Output = '';
89 $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
90 $ShowForm = true;
91
92 if (array_key_exists('user', $_POST)) $UserName = $_POST['user'];
93 else $UserName = '';
94 if (array_key_exists('pass', $_POST)) $Pass = $_POST['pass'];
95 else $Pass = '';
96 if (array_key_exists('pass2', $_POST)) $Pass2 = $_POST['pass2'];
97 else $Pass2 = '';
98 if (array_key_exists('Email', $_POST)) $Email = $_POST['Email'];
99 else $Email = '';
100 if (array_key_exists('Team', $_POST)) $Team = $_POST['Team'] * 1;
101 else $Team = '';
102 if (array_key_exists('Language', $_POST)) $Language = $_POST['Language'] * 1;
103 else $Language = '';
104 if (array_key_exists('ClientVersion', $_POST) and is_numeric($_POST['ClientVersion']))
105 $PreferredVersion = $_POST['ClientVersion'] * 1;
106 else $PreferredVersion = '';
107 if ($PreferredVersion == '') $PreferredVersion = 'NULL';
108 if (array_key_exists('sc', $_POST)) $SpamCheck = $_POST['sc'];
109 else $SpamCheck = '';
110
111 if ($SpamCheck != '')
112 {
113 if (($UserName != '') and ($Pass != '') and ($Pass2 != ''))
114 {
115 if (!in_array(strtolower($UserName), Core::Cast($this->System)->Config['ForbiddedUserNames']))
116 {
117 if ($Pass == $Pass2)
118 {
119 $DbResult = $this->Database->query('SELECT * FROM `User` WHERE LOWER(`Name`) = LOWER("'.$UserName.'")');
120 $Line = $DbResult->fetch_row();
121 if (!$Line)
122 {
123 if ($Team == 0) $Team = 'NULL';
124 $User->Register($UserName, $Pass, $Email, $Language, $Team, $PreferredVersion);
125 $Output .= ShowMessage(T('Registration was successful'));
126 $Output .= 'Přečtěte si pozorně <a href="'.$this->System->Link('/info/').'">pokyny pro překladání</a> a můžete pak hned začít překládat.';
127 $User->Login($UserName, $Pass);
128 $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel se zaregistroval: '.$UserName, LOG_TYPE_USER);
129 $ShowForm = false;
130
131 // User tags
132 $Query = 'SELECT * FROM `UserTagType`';
133 $DbResult = $this->Database->query($Query);
134 while ($UserTag = $DbResult->fetch_array()) {
135 if (array_key_exists('Tag'.$UserTag['ID'], $_POST)) {
136 $Query = 'SELECT * FROM `UserTag` '.
137 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
138 $DbResult2 = $this->Database->query($Query);
139 if ($DbResult2->num_rows == 0) {
140 $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
141 'VALUES (NULL, '.$UserTag['ID'].' , '.($User->Id * 1).')';
142 $DbResult2 = $this->Database->query($Query);
143 }
144 } else {
145 $Query = 'DELETE FROM `UserTag` '.
146 'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($User->Id * 1);
147 $DbResult2 = $this->Database->query($Query);
148 }
149 }
150 } else $Output = ShowMessage('Uživatel se zadanou přezdívkou již existuje.', MESSAGE_CRITICAL);
151 } else $Output = ShowMessage('Hesla se neshodují.', MESSAGE_CRITICAL);
152 } else $Output = ShowMessage('To jméno uživatele nemůžete použít.', MESSAGE_CRITICAL);
153 } else $Output = ShowMessage('Nelze použít prázdné jméno nebo heslo.', MESSAGE_CRITICAL);
154 } else $Output = ShowMessage('Nejsi člověk. Strojům není dovoleno se registrovat.', MESSAGE_CRITICAL);
155
156 if ($ShowForm) $Output .= $this->ShowForm();
157 return $Output;
158 }
159
160 function Show(): string
161 {
162 $this->Title = T('User registration');
163 $Output = '';
164 if (array_key_exists('user', $_POST))
165 {
166 $Output .= $this->CheckRegistration();
167 } else $Output .= $this->ShowForm();
168 return $Output;
169 }
170}
Note: See TracBrowser for help on using the repository browser.