def deposit(request): sid = request.POST.get('student_id') password = request.POST.get('password') oppassword = request.POST.get('operatorpassword') student = getstudentp(sid,password) operator = getoperatorp(request.session['data_ioests'].get('name'),oppassword) details = request.POST.get('details','amount deposited') if not (student and operator): return "Student or Operator doesn't exist" amount = request.POST.get('amount') if amount == None: return "Amount field can't be empty" try: amount = float(amount) except: return "Invalid Balance. Must be a float number" if amount >1000: return "Can't deposit more than Rs 1000 at a time" student.balance += amount student.save() activ = Activity(student=student,atype='deposit',operator=operator,details=details,amount=amount) activ.save() student.save() #TODO: create activity return True
def changepassword(request): sid = request.session['data_ioests'].get('name') password = request.POST.get('oldpassword') newpassword = request.POST.get('newpassword') student = getstudentp(sid,password) if not student: return 'Authentication error. ' if not validation.verifypassword(newpassword): return 'Password invalid. Must be more than 5 characters' student.password = validation.hash(newpassword) student.save() return True
def changeemail(request): sid = request.session['data_ioests'].get('name') password = request.POST.get('oldpassword') newemail = request.POST.get('newemail') student = getstudentp(sid,password) if not student: return 'Authentication error. ' error = validation.emailvalid(newemail) if error != 'True': return error student.email = newemail student.save() return True
def index(request): #list_by_credit = Student.objects.all().order_by('credit') #return render_to_response('ioestu/index.html', {'list_by_credit': list_by_credit}) state = "Please log in below..." username = password = '' if request.method == 'POST': state = "invalid user id or password" username = request.POST.get('username') password = request.POST.get('password') if getoperatorp(username,password): request.session['data_ioests']={'type':'operator','name':username,'balance_before':'null','action':'payment'} return HttpResponseRedirect('/logged/') elif getstudentp(username, password): request.session['data_ioests']={'type':'student','name':username,'balance_before':'null','action':'payment'} return HttpResponseRedirect('/logged/') else: student = None operator = None return render(request,'ioestu/index.html',{'state':state, 'username': username})
def payment(request): sid = request.POST.get('student_id') password = request.POST.get('password') opname = request.session['data_ioests'].get('name') student = getstudentp(sid,password) operator = getoperator(opname) details = request.POST.get('details') if not(student and operator): return "Student or Operator doesn't exist" amount = request.POST.get('amount') if not amount: return 'Amount field can\'t be empty' try: amount = float(amount) except: return "Invalid Balance. Must be a float number" if amount >1000: return "Can't pay more than Rs 1000 at a time" if amount > student.balance: return "Insufficient funds" data_ioests = request.session['data_ioests'] data_ioests['balance_before']=student.balance request.session['data_ioests']=data_ioests student.balance -= amount activ = Activity(student=student,atype='payment',operator=operator,details=details,amount=amount) activ.save() student.save() #TODO: create activity return True
def delaccount(request): s = getstudentp(request.POST.get('student_id'),request.POST.get('password')) if not s: return 'The id doesn\'t exists' s.delete() return True