Changeset 756:673a9809df08 for src
- Timestamp:
- 01/11/16 15:56:23 (9 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/flight.py
r754 r756 1127 1127 self._updateButtons() 1128 1128 1129 @property 1130 def name(self): 1131 """Get the name entered.""" 1132 return self._name.get_text() 1133 1134 @property 1135 def yearOfBirth(self): 1136 """Get the year of birth.""" 1137 yearOfBirthText = self._yearOfBirth.get_text() 1138 return int(yearOfBirthText) if yearOfBirthText else 0 1139 1140 @property 1141 def emailAddress(self): 1142 """Get the e-mail address.""" 1143 return self._emailAddress.get_text() 1144 1145 @property 1146 def emailAddressPublic(self): 1147 """Get the whether the e-mail address is public.""" 1148 return self._emailAddressPublic.get_active() 1149 1150 @property 1151 def vatsimID(self): 1152 """Get the VATSIM ID.""" 1153 return self._vatsimID.get_int() 1154 1155 @property 1156 def ivaoID(self): 1157 """Get the IVAO ID.""" 1158 return self._ivaoID.get_int() 1159 1160 @property 1161 def phoneNumber(self): 1162 """Get the phone number.""" 1163 return self._phoneNumber.get_text() 1164 1165 @property 1166 def nationality(self): 1167 """Get the nationality.""" 1168 return self._nationality.get_text() 1169 1170 @property 1171 def password(self): 1172 """Get the password.""" 1173 return self._password.get_text() 1174 1175 @property 1176 def rememberPassword(self): 1177 """Get whether the password should be remembered.""" 1178 return self._rememberButton.get_active() 1179 1129 1180 def activate(self): 1130 1181 """Setup the route from the booked flight.""" … … 1135 1186 def _updateButtons(self, widget = None): 1136 1187 """Update the sensitive state of the buttons""" 1137 name = self. _name.get_text()1188 name = self.name 1138 1189 nameLength = len(name) 1139 1190 nameSpacePosition = name.find(" ") 1140 1191 1141 yearOfBirthText = self._yearOfBirth.get_text() 1142 yearOfBirth = int(yearOfBirthText) if yearOfBirthText else 0 1143 1144 emailAddressText = self._emailAddress.get_text() 1145 emailAddressMatch = RegisterPage._emailAddressRE.match(emailAddressText) 1146 1147 vatsimID = self._vatsimID.get_int() 1148 ivaoID = self._ivaoID.get_int() 1149 1150 password = self._password.get_text() 1192 yearOfBirth = self.yearOfBirth 1193 1194 emailAddress = self.emailAddress 1195 emailAddressMatch = RegisterPage._emailAddressRE.match(emailAddress) 1196 1197 vatsimID = self.vatsimID 1198 ivaoID = self.ivaoID 1199 1200 password = self.password 1151 1201 password2 = self._password2.get_text() 1152 1202 if not password: … … 1183 1233 def _registerClicked(self, button): 1184 1234 """Called when the Register button is clicked.""" 1235 registrationData = web.Registration(self.name, self.yearOfBirth, 1236 self.emailAddress, 1237 self.emailAddressPublic, 1238 self.vatsimID, self.ivaoID, 1239 self.phoneNumber, self.nationality, 1240 self.password) 1241 print "Registering with data:" 1242 print " name:", self.name, registrationData.name 1243 print " yearOfBirth:", self.yearOfBirth, registrationData.yearOfBirth 1244 print " emailAddress:", self.emailAddress, registrationData.emailAddress 1245 print " emailAddressPublic:", self.emailAddressPublic, registrationData.emailAddressPublic 1246 print " vatsimID:", self.vatsimID, registrationData.vatsimID 1247 print " ivaoID:", self.ivaoID, registrationData.ivaoID 1248 print " phoneNumber:", self.phoneNumber, registrationData.phoneNumber 1249 print " nationality:", self.nationality, registrationData.nationality 1250 1251 gui = self._wizard.gui 1252 gui.beginBusy(xstr("register_busy")) 1253 gui.webHandler.register(self._registerResultCallback, registrationData) 1254 1255 def _registerResultCallback(self, returned, result): 1256 """Called when the registration result is available.""" 1257 gobject.idle_add(self._handleRegisterResult, returned, result) 1258 1259 def _handleRegisterResult(self, returned, result): 1260 """Handle the registration result.""" 1261 gui = self._wizard.gui 1262 1263 gui.endBusy() 1264 1265 print "Registration result:" 1266 print " returned:", returned 1267 if returned: 1268 print " registered:", result.registered 1269 if result.registered: 1270 print " pilotID", result.pilotID 1271 print " loggedIn", result.loggedIn 1272 print " emailAlreadyRegistered:", result.emailAlreadyRegistered 1273 print " invalidData:", result.invalidData 1274 1275 registrationOK = returned and result.registered 1276 1277 message = xstr("register_ok") if registrationOK \ 1278 else xstr("register_failed") 1279 secondaryMessage = None 1280 if registrationOK: 1281 if result.loggedIn: 1282 secondaryMessage = xstr("register_info") % (result.pilotID,) 1283 else: 1284 secondaryMessage = xstr("register_nologin") % (result.pilotID,) 1285 messageType = MESSAGETYPE_INFO 1286 1287 config = gui.config 1288 config.pilotID = result.pilotID 1289 config.rememberPassword = self.rememberPassword 1290 if config.rememberPassword: 1291 config.password = self.password 1292 else: 1293 config.password = "" 1294 1295 config.save() 1296 elif returned and result.emailAlreadyRegistered: 1297 secondaryMessage = xstr("register_email_already") 1298 messageType = MESSAGETYPE_ERROR 1299 elif returned and result.invalidData: 1300 secondaryMessage = xstr("register_invalid_data") 1301 messageType = MESSAGETYPE_ERROR 1302 else: 1303 secondaryMessage = xstr("register_error") 1304 messageType = MESSAGETYPE_ERROR 1305 1306 dialog = gtk.MessageDialog(parent = gui.mainWindow, 1307 type = messageType, 1308 message_format = message) 1309 dialog.set_title(WINDOW_TITLE_BASE + " - " + 1310 xstr("register_result_title")) 1311 dialog.format_secondary_markup(secondaryMessage) 1312 1313 dialog.add_button(xstr("button_ok"), 0) 1314 1315 dialog.run() 1316 dialog.hide() 1317 1318 if registrationOK: 1319 if result.loggedIn: 1320 self._wizard.nextPage() 1321 else: 1322 self._wizard.jumpPage("login") 1185 1323 1186 1324 #----------------------------------------------------------------------------- -
src/mlx/rpc.py
r745 r756 125 125 #--------------------------------------------------------------------------------------- 126 126 127 class Registration(object): 128 """Data for registration.""" 129 def __init__(self, name, yearOfBirth, emailAddress, emailAddressPublic, 130 vatsimID, ivaoID, phoneNumber, nationality, password): 131 """Construct the registration data.""" 132 self.name = name 133 self.yearOfBirth = yearOfBirth 134 self.emailAddress = emailAddress 135 self.emailAddressPublic = 1 if emailAddressPublic is True else \ 136 0 if emailAddressPublic is False else emailAddressPublic 137 self.vatsimID = "" if vatsimID is None else vatsimID 138 self.ivaoID = "" if ivaoID is None else ivaoID 139 self.phoneNumber = phoneNumber 140 self.nationality = nationality 141 self.password = password 142 143 #--------------------------------------------------------------------------------------- 144 127 145 class RPCException(Exception): 128 146 """An exception thrown by RPC operations.""" … … 155 173 RESULT_DATABASE_ERROR = 3 156 174 175 # Result code: invalid data 176 RESULT_INVALID_DATA = 4 177 157 178 # Result code: the flight does not exist 158 179 RESULT_FLIGHT_NOT_EXISTS = 101 … … 160 181 # Result code: the flight has already been reported. 161 182 RESULT_FLIGHT_ALREADY_REPORTED = 102 183 184 # Result code: a user with the given e-mail address already exists 185 RESULT_EMAIL_ALREADY_REGISTERED = 103 162 186 163 187 def __init__(self, getCredentialsFn): … … 189 213 self._sessionID = None 190 214 215 def register(self, registrationData): 216 """Register with the given data. 217 218 Returns a tuple of: 219 - the error code, 220 - the PID if there is no error.""" 221 reply = Reply(self._server.register(registrationData)) 222 223 return (reply.result, 224 reply.value["pid"] if reply.result==Client.RESULT_OK else None) 225 191 226 def login(self): 192 227 """Login using the given previously set credentials. … … 194 229 The session ID is stored in the object and used for later calls. 195 230 196 Returns a boolean indicating if login has succeeded."""231 Returns the name of the pilot on success, or None on error.""" 197 232 self._sessionID = None 198 233 -
src/mlx/web.py
r746 r756 2 2 import const 3 3 import util 4 from rpc import Registration 4 5 import rpc 5 6 import rpccommon … … 620 621 super(RPCRequest, self).__init__(callback) 621 622 self._client = client 623 624 #------------------------------------------------------------------------------ 625 626 class Register(RPCRequest): 627 """A registration request.""" 628 def __init__(self, client, callback, registrationData): 629 """Construct the request.""" 630 super(Register, self).__init__(client, callback) 631 self._registrationData = registrationData 632 633 def run(self): 634 """Perform the registration.""" 635 636 registrationData = self._registrationData 637 638 (resultCode, pilotID) = self._client.register(registrationData) 639 result = Result() 640 result.registered = resultCode==rpc.Client.RESULT_OK 641 if result.registered: 642 result.pilotID = pilotID 643 644 self._client.setCredentials(pilotID, registrationData.password) 645 loginResult = self._client.login() 646 result.loggedIn = loginResult is not None 647 648 result.invalidData = \ 649 resultCode==rpc.Client.RESULT_INVALID_DATA 650 result.emailAlreadyRegistered = \ 651 resultCode==rpc.Client.RESULT_EMAIL_ALREADY_REGISTERED 652 653 return result 622 654 623 655 #------------------------------------------------------------------------------ … … 1134 1166 self._rpcClient.setCredentials(config.pilotID, config.password) 1135 1167 1168 def register(self, callback, registrationData): 1169 """Enqueue a registration request.""" 1170 self._addRequest(Register(self._rpcClient, callback, registrationData)) 1171 1136 1172 def login(self, callback, pilotID, password, entranceExam = False): 1137 1173 """Enqueue a login request."""
Note:
See TracChangeset
for help on using the changeset viewer.