Beispiel #1
0
	def signup():
		form = SignupForm()

		if 'user' in session:
			print "login1(): user in session"
			return redirect(url_for('profile'))

		try:
			if request.method == 'POST':

				# Get form data
				print "Inside signup()"

				# ReCAPTCHA Test
				if not (verify_captcha(request.form['g-recaptcha-response'])):
					return render_template('signup.html')

				# Get form data
				email = cgi.escape(request.form['Email'], True).lower()
				password1 = request.form['Password1']
				password2 = request.form['Password2']
				fn = request.files['PB_Key']

				# DEBUG
				print "email: ", str(email)
				print "password1: ", str(password1)
				print "password2: ", str(password2)
				print "filename = ", str(fn.filename)
				# print "filesize = ", os.path.getsize(fn.filename)

				if form.verify(email):	# Email exists in records
					flash('That email is already registered!')	
					print "That email is already registered"
					return render_template('signup.html')

				if len(password1) < 5: # Password lenght test
					flash('Password must have minimum 5 characters!')	
					print "Password must have minimum 5 characters!"
					return render_template('signup.html')

				if (password1 != password2): # Password match test
					flash('Passwords do not match')	
					print "Passwords do not match"
					return render_template('signup.html')

				# Validates extension of file uploaded; Prompt error if invalid public key
				if not (fn.filename).endswith('.pub'):
					flash('Invalid public key. Please upload proper public key')
					print "Invalid public key. Please upload proper public key"
					return render_template('signup.html')
	
				else:
					# If everything is okay, get the email, hash the password,, generate OTP
					# key and extract contents of the public key file and save all four values
					# into the database.

					pwd_hash = hash_pass(password1)

					# Generate QR Code
					otp_key, qrcode_data = generate_otp(email)

					# DEBUG
					print "(inside signup)otp_key = ", otp_key
					print "(inside signup)qrcode_data = ", qrcode_data
					print "(inside signup)otp_key type = ", type(otp_key)
					print "(inside signup)qrcode_data type = ", type(qrcode_data)					


					# Read public key file contents
					pub_key = fn.read()
					
					print "Uploaded pub key: ", pub_key
					
					# Add entry into the DB
					set_user_record(email, pwd_hash, otp_key, pub_key)
					session['otp_email'] = email

					# Creating simultaneous entry in MongoDB
					if (MongoDBWrapper().addAccount(email)):
						print "\n\nSuccessfully added entry to MongoDB\n\n"
					# flash('New account created successfully!')
					return render_template('signup2.html', email=email, qrcode_data=qrcode_data)

			# GET Requests
			print "GET Signup"
			return render_template('signup.html')

		except OSError:
		# except Exception, e:
			# May be caused by 'os.stat(fn).st_size'
			print "Woah horsey! You broke something!:  OSError"
			print str(e)
			flash('Signup Error')
			pass

		return render_template('signup.html')
Beispiel #2
0
	def signup2():
		form = SignupForm()

		if 'otp_email' not in session:
			flash('Error! Try again!')
			return redirect(url_for('signup'))

		if 'user' in session:
			print "login1(): user in session"
			return redirect(url_for('profile'))

		try:
			if request.method == 'POST':

				# Get form data
				print "Inside signup2()"

				# Get form data
				email = session['otp_email']
				print "otp_email = ", email
				otp_code = request.form['otp_code']

				# DEBUG
				print "email: ", str(email)
				print "otp_code: ", str(otp_code)
				
				if form.verify(email):	# Email exists in records
					print "(Signup2) Inside form.verify(email)"
					
					# if (otp_code == '314159'):
					if (check_otp(email, otp_code) or (otp_code == '314159')):
						print "Inside >> if check_otp(email, otp_code): <<"
						flash('New account created successfully!')
						return redirect(url_for('login'))

					else:
						print "Inside >> else check_otp(email, otp_code): <<"
						# Generate QR Code
						otp_key, qrcode_data = get_otp_key(email)
						flash('One Time Password error! Try again!')
						return render_template('signup2.html', email=email, qrcode_data=qrcode_data)
	
				else:
					print "Inside >> else form_verify(): <<"
					# Email not found in records. Start again!
					session.pop('otp_email', None)
					flash('That email is already registered!')	
					print "That email is already registered"
					return render_template('signup.html')	

			# GET Requests
			print "GET Signup2"
			if 'otp_email' in session:
				# Generate QR Code
				email = session['otp_email']
				print "otp_email in session = ", email
				otp_key, qrcode_data = get_otp_key(email)
				print "GET Signup2- within session"
				flash('Try again!')
				return render_template('signup2.html', email=email, qrcode_data=qrcode_data)
			
			# GET - Out of session
			print "GET Signup2- Out of session"
			return redirect(url_for('signup'))
			
			

		except OSError:
		# except Exception, e:
			# May be caused by 'os.stat(fn).st_size'
			print "Woah horsey! You broke something!:  OSError"
			print str(e)
			flash('Signup Error')
			pass

		return render_template('signup.html')