Ignore:
Timestamp:
02/14/16 09:17:27 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The rank is returned when logging in, and in case of a student, we jump to the student page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/web.py

    r756 r760  
    659659    iso88592decoder = codecs.getdecoder("iso-8859-2")
    660660
    661     def __init__(self, callback, pilotID, password, entranceExam):
     661    def __init__(self, callback, pilotID, password):
    662662        """Construct the login request with the given pilot ID and
    663663        password."""
     
    666666        self._pilotID = pilotID
    667667        self._password = password
    668         self._entranceExam = entranceExam
    669668
    670669    def run(self):
     
    678677        password = md5.hexdigest()
    679678
    680         if self._entranceExam:
    681             url = MAVA_BASE_URL + "/ellenorzo/getflightplan.php?pid=%s" % \
    682                   (pilotID,)
    683         else:
    684             url = MAVA_BASE_URL + "/leker2.php?pid=%s&psw=%s" % \
    685                   (pilotID, password)
     679        url = MAVA_BASE_URL + "/leker2.php?pid=%s&psw=%s" %  (pilotID, password)
    686680
    687681        result = Result()
    688         result.entranceExam = self._entranceExam
    689682
    690683        f = urllib2.urlopen(url, timeout = 10.0)
    691684
    692685        status = readline(f)
    693         if self._entranceExam:
    694             result.loggedIn = status != "#NOEXAM"
    695         else:
    696             result.loggedIn = status == ".OK."
     686        result.loggedIn = status == ".OK."
    697687
    698688        if result.loggedIn:
    699689            result.pilotID = self._pilotID
    700690            result.password = self._password
     691            result.rank = "FO"
    701692            result.flights = []
    702             # FIXME: this may not be the correct behaviour
    703             # for an entrance exam, but the website returns
    704             # an error
    705             if self._entranceExam:
    706                 result.pilotName = result.pilotID
    707                 result.exams = ""
    708             else:
    709                 result.pilotName = self.iso88592decoder(readline(f))[0]
    710                 result.exams = readline(f)
    711 
    712                 while True:
    713                     line = readline(f)
    714                     if not line or line == "#ENDPIREP": break
    715 
    716                     flight = BookedFlight(line)
    717                     flight.readFromWeb(f)
    718                     result.flights.append(flight)
     693
     694            result.pilotName = self.iso88592decoder(readline(f))[0]
     695            result.exams = readline(f)
     696
     697            while True:
     698                line = readline(f)
     699                if not line or line == "#ENDPIREP": break
     700
     701                flight = BookedFlight(line)
     702                flight.readFromWeb(f)
     703                result.flights.append(flight)
    719704
    720705            result.flights.sort(cmp = lambda flight1, flight2:
     
    730715class LoginRPC(RPCRequest):
    731716    """An RPC-based login request."""
    732     def __init__(self, client, callback, pilotID, password, entranceExam):
     717    def __init__(self, client, callback, pilotID, password):
    733718        """Construct the login request with the given pilot ID and
    734719        password."""
     
    737722        self._pilotID = pilotID
    738723        self._password = password
    739         self._entranceExam = entranceExam
    740724
    741725    def run(self):
    742726        """Perform the login request."""
    743727        result = Result()
    744         # FIXME: handle the entrance exam case
    745         result.entranceExam = self._entranceExam
    746728
    747729        self._client.setCredentials(self._pilotID, self._password)
    748         pilotName = self._client.login()
    749         result.loggedIn = pilotName is not None
     730        loginResult = self._client.login()
     731        result.loggedIn = loginResult is not None
    750732        if result.loggedIn:
    751733            result.pilotID = self._pilotID
    752             result.pilotName = pilotName
     734            result.pilotName = loginResult[0]
     735            result.rank = loginResult[1]
    753736            result.password = self._password
    754737            result.flights = self._client.getFlights()
     
    11701153        self._addRequest(Register(self._rpcClient, callback, registrationData))
    11711154
    1172     def login(self, callback, pilotID, password, entranceExam = False):
     1155    def login(self, callback, pilotID, password):
    11731156        """Enqueue a login request."""
    11741157        request = \
    1175           LoginRPC(self._rpcClient, callback, pilotID, password, entranceExam) \
    1176           if self._config.useRPC and not entranceExam \
    1177           else Login(callback, pilotID, password, entranceExam)
     1158          LoginRPC(self._rpcClient, callback, pilotID, password) \
     1159          if self._config.useRPC else Login(callback, pilotID, password)
    11781160
    11791161        self._addRequest(request)
Note: See TracChangeset for help on using the changeset viewer.