def addaccount(request): #check if another operator and student has this name uname = request.POST.get('student_id') if getoperator(uname) or getstudent(uname): return 'The id already exists' password = validation.hash(uname) email = request.POST.get('email') firstname = request.POST.get('fname') lastname = request.POST.get('lname') operator = getoperator(request.session['data_ioests'].get('name')) if not operator: return "Operator doesn't exist. Please Log in first " details = request.POST.get('details','new account created') #validate these credentials error = validation.usernamevalid(uname) if error != 'True': return error error = validation.emailvalid(email) if error != 'True': return error error = validation.namevalid(firstname) if error != 'True': return error error = validation.namevalid(lastname) if error != 'True': return error s = Student(student_id=uname,firstname=firstname,lastname=lastname,password=password,balance=100.,emailid=email,lastlogin=datetime.now()) s.save() activ = Activity(student=s,atype='newaccount',operator=operator,details=details,amount=100.) activ.save() 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