Ejemplo n.º 1
0
 def do_login(self, args):
     """
     Login using stored credentials. Starts a session to be reused for
     subsequent api calls
     """
     try:
         session, sessionkey = login(self.url, self.username, self.password)
         self.credentials['session'] = session
         self.credentials['sessionkey'] = sessionkey
     except Exception, e:
         self.monkeyprint("Error: Login failed to the server: ", unicode(e))
Ejemplo n.º 2
0
 def do_login(self, args):
     """
     Login using stored credentials. Starts a session to be reused for
     subsequent api calls
     """
     try:
         session, sessionkey = login(self.url, self.username, self.password)
         self.credentials['session'] = session
         self.credentials['sessionkey'] = sessionkey
     except Exception, e:
         self.monkeyprint("Error: Login failed to the server: ", unicode(e))
Ejemplo n.º 3
0
 def do_login(self, args):
     """
     Login using stored credentials. Starts a session to be reused for
     subsequent api calls
     """
     try:
         session, sessionkey = login(self.url, self.username, self.password)
         self.credentials['session'] = session
         self.credentials['sessionkey'] = sessionkey
     except Exception, e:
         print "Error while trying to log in to the server: ", str(e)
Ejemplo n.º 4
0
def pay(request):
    thisYear = dating.getChineseThisYear()

    payMonth = str(request.POST.get("month", ""))
    payHours = float(request.POST.get("hours", ""))

    holidays = dating.getThisMonthHolidaysFromFile(payMonth, 'holidays.json')
    payableDays = dating.getPayableDays(payMonth, holidays)

    payload = {}
    payload['staff_cd'] = str(request.POST.get("username", ""))
    payload['passwd'] = str(request.POST.get("password", ""))

    if requester.login(payload) != '200':
        return HttpResponse('incorrect username or password')

    for d in requester.getAlreadyPaidDays(thisYear, payMonth):
        if d in payableDays:
            payableDays.remove(d)

    #add hours to database get paid days list
    paidDays, leftHours = requester.addHours(thisYear, payMonth, payableDays,
                                             payHours)
    if leftHours > 0:
        return HttpResponse(
            'Fail to add hours: ' + str(leftHours) +
            ' hours remained, please declare your salary manually.')

    #get seqenceNumber and total paid days
    sequence, days = requester.submitPayment(thisYear, payMonth, paidDays)
    if sequence is False:
        return HttpResponse('Fail to add hours.')

    #True if download pdf sucessfully
    if (requester.getPDF(sequence, days, payload['staff_cd'])):
        with open(str(request.POST.get("username", "")) + '.pdf', 'rb') as pdf:
            response = HttpResponse(pdf.read(), content_type='application/pdf')
            response['Content-Disposition'] = 'filename=' + str(
                request.POST.get("username", "")) + '.pdf'
            return response
    pdf.closed
Ejemplo n.º 5
0
def login(request):
    payload = {}
    payload['staff_cd'] = str(request.POST.get("username", ""))
    payload['passwd'] = str(request.POST.get("password", ""))
    return HttpResponse(requester.login(payload))