Changeset 756:673a9809df08


Ignore:
Timestamp:
01/11/16 15:56:23 (9 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Implemented the basic GUI logic of the registration (re #285)

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • locale/en/mlx.po

    r755 r756  
    22182218msgid "register_password_mismatch"
    22192219msgstr "<span foreground=\"red\">Passwords differ</span>"
     2220
     2221msgid "register_busy"
     2222msgstr "Registering..."
     2223
     2224msgid "register_ok"
     2225msgstr "Registration successful."
     2226
     2227msgid "register_failed"
     2228msgstr "Registration failed!"
     2229
     2230msgid "register_info"
     2231msgstr ""
     2232"Congratulations! You are now a MAVA pilot\n"
     2233"in status STU (student).\n"
     2234"\n"
     2235"Your pilot ID is: <b>%s</b>.\n"
     2236"\n"
     2237"You will now be taken to the student page,\n"
     2238"where you can initiate the taking of the\n"
     2239"entrance exam or start your check flight.\n"
     2240"\n"
     2241"You can return to the page anytime later\n"
     2242"by starting the program, and logging in."
     2243
     2244msgid "register_nologin"
     2245msgstr ""
     2246"Congratulations! You are now a MAVA pilot\n"
     2247"in status STU (student).\n"
     2248"\n"
     2249"Your pilot ID is: <b>%s</b>.\n"
     2250"\n"
     2251"For some reason, we could not log you in\n"
     2252"(perhaps a server failure).\n"
     2253"\n"
     2254"You will now be taken to the login page,\n"
     2255"where you can try logging in again. You can,\n"
     2256"of course, start the program at any time\n"
     2257"later on and attempt logging in."
     2258
     2259msgid "register_email_already"
     2260msgstr "The given e-mail is already registered."
     2261
     2262msgid "register_invalid_data"
     2263msgstr ""
     2264"The program has sent invalid data to the server.\n"
     2265"This may be a program error. You may try to alter some\n"
     2266"data (e.g. accented characters), or send a bug report."
     2267
     2268msgid "register_error"
     2269msgstr ""
     2270"Some error, most likely in the server, has occured.\n"
     2271"Please, try again later."
     2272
     2273msgid "register_result_title"
     2274msgstr "Registration"
  • locale/hu/mlx.po

    r755 r756  
    22322232msgid "register_password_mismatch"
    22332233msgstr "<span foreground=\"red\">A két jelszó különbözik</span>"
     2234
     2235msgid "register_busy"
     2236msgstr "Regisztráció..."
     2237
     2238msgid "register_ok"
     2239msgstr "A regisztráció sikerült."
     2240
     2241msgid "register_failed"
     2242msgstr "A regisztráció nem sikerült!"
     2243
     2244msgid "register_info"
     2245msgstr ""
     2246"Gratulálunk! Ezennel a MAVA pilótája lettél\n"
     2247"STU (student - tanuló) státuszban.\n"
     2248"\n"
     2249"Pilóta azonosítód: <b>%s</b>.\n"
     2250"\n"
     2251"Most a tanulók oldala fog megjelenni,\n"
     2252"ahol kezdeményezheted a belépő teszt\n"
     2253"kitöltését vagy elindíthatod az ellenőrző\n"
     2254"repülést.\n"
     2255"\n"
     2256"A tanulók oldalára bármikor visszatérhetsz\n"
     2257"ha elindítod a programot és bejelentkezel."
     2258
     2259msgid "register_nologin"
     2260msgstr ""
     2261"Gratulálunk! Ezennel a MAVA pilótája lettél\n"
     2262"STU (student - tanuló) státuszban.\n"
     2263"\n"
     2264"Pilóta azonosítód: <b>%s</b>.\n"
     2265"\n"
     2266"Valamilyen oknál fogva a bejelentkezés viszont\n"
     2267"nem sikerült (talán szerverhiba).\n"
     2268"\n"
     2269"A bejelentkező oldal fog megjelenni,\n"
     2270"ahol megpróbálhatsz belépni. Természetesen\n"
     2271"a programot bármikor futtathatod és\n"
     2272"megpróbálhatod a belépést."
     2273
     2274msgid "register_email_already"
     2275msgstr "A megadott e-mail címmel már regisztráltak."
     2276
     2277msgid "register_invalid_data"
     2278msgstr ""
     2279"A program érvényelen adatokat küldött a szervernek.\n"
     2280"Ez programhiba lehet. Megpróbálhatsz megváltoztatni\n"
     2281"bizonyos adatokat (pl. az ékezetes karaktereket),\n"
     2282"vagy küldhetsz hibajelentést."
     2283
     2284msgid "register_error"
     2285msgstr ""
     2286"Valamilyen, valószínűleg szerverhiba történt.\n"
     2287"Kérlek, próbáld meg később."
     2288
     2289msgid "register_result_title"
     2290msgstr "Regisztráció"
  • src/mlx/gui/flight.py

    r754 r756  
    11271127        self._updateButtons()
    11281128
     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
    11291180    def activate(self):
    11301181        """Setup the route from the booked flight."""
     
    11351186    def _updateButtons(self, widget = None):
    11361187        """Update the sensitive state of the buttons"""
    1137         name = self._name.get_text()
     1188        name = self.name
    11381189        nameLength = len(name)
    11391190        nameSpacePosition = name.find(" ")
    11401191
    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
    11511201        password2 = self._password2.get_text()
    11521202        if not password:
     
    11831233    def _registerClicked(self, button):
    11841234        """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")
    11851323
    11861324#-----------------------------------------------------------------------------
  • src/mlx/rpc.py

    r745 r756  
    125125#---------------------------------------------------------------------------------------
    126126
     127class 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
    127145class RPCException(Exception):
    128146    """An exception thrown by RPC operations."""
     
    155173    RESULT_DATABASE_ERROR = 3
    156174
     175    # Result code: invalid data
     176    RESULT_INVALID_DATA = 4
     177
    157178    # Result code: the flight does not exist
    158179    RESULT_FLIGHT_NOT_EXISTS = 101
     
    160181    # Result code: the flight has already been reported.
    161182    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
    162186
    163187    def __init__(self, getCredentialsFn):
     
    189213        self._sessionID = None
    190214
     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
    191226    def login(self):
    192227        """Login using the given previously set credentials.
     
    194229        The session ID is stored in the object and used for later calls.
    195230
    196         Returns a boolean indicating if login has succeeded."""
     231        Returns the name of the pilot on success, or None on error."""
    197232        self._sessionID = None
    198233
  • src/mlx/web.py

    r746 r756  
    22import const
    33import util
     4from rpc import Registration
    45import rpc
    56import rpccommon
     
    620621        super(RPCRequest, self).__init__(callback)
    621622        self._client = client
     623
     624#------------------------------------------------------------------------------
     625
     626class 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
    622654
    623655#------------------------------------------------------------------------------
     
    11341166            self._rpcClient.setCredentials(config.pilotID, config.password)
    11351167
     1168    def register(self, callback, registrationData):
     1169        """Enqueue a registration request."""
     1170        self._addRequest(Register(self._rpcClient, callback, registrationData))
     1171
    11361172    def login(self, callback, pilotID, password, entranceExam = False):
    11371173        """Enqueue a login request."""
Note: See TracChangeset for help on using the changeset viewer.