예제 #1
0
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
예제 #2
0
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