Exemplo n.º 1
0
	def post(self):

		# setup regex expressions
		username_re = re.compile(r"^[a-zA-Z0-9_-]{3,20}$")
		password_re = re.compile(r"^.{3,20}$")
		email_re = re.compile(r"^[\S]+@[\S]+\.[\S]+$")

		# pull data from form
		username = self.request.get('username')
		password = self.request.get('password')
		verify = self.request.get('verify')
		email = self.request.get('email')

		has_error = False
		fields = {}
		fields['username'] = username
		fields['email']  = email

		# perform validation checks
		if username_re.search(username) is None:
			has_error = True
			fields['username_error'] = "That's not a valid username"
		if password_re.match(password) is None:
			has_error = True
			fields['password_error'] = "That wasn't a valid password"
		if password != verify:
			has_error = True
			fields['verify_error'] = "Your passwords do not match"
		if email and (email_re.match(email) is None):
			has_error = True
			fields['email_error'] = 'Bad e-mail entered'

		# check is username already exists
		query =  db.GqlQuery("SELECT * FROM User WHERE username=:1", username)
		existing_users = query.get()
		if existing_users:
			has_error = True
			fields['username_error'] = "That user is already registered"
		if has_error:
			self.render('signup.html', **fields)
		else:
			if email:
				user  = User(username = username, password_hash = blogcrypt.make_pw_hash(username,password), email = email)
			else:
				user  = User(username = username, password_hash = blogcrypt.make_pw_hash(username,password))
			user.put() #stores user
			self.login(user)
			self.redirect('/blog/welcome')
Exemplo n.º 2
0
	def post(self):
		username_re = re.compile(r"^[a-zA-Z0-9_-]{3,20}$")
		password_re = re.compile(r"^.{3,20}$")
		email_re = re.compile(r"^[\S]+@[\S]+\.[\S]+$")

		username = self.request.get('username') 
		password = self.request.get('password') 
		verify = self.request.get('verify') 
		email = self.request.get('email')

		has_error = False
		fields = {}
		fields['username'] = username
		fields['email']  = email

		if username_re.search(username) is None:
			has_error = True
			fields['username_error'] = "That's not a valid username" 
		if password_re.match(password) is None:
			has_error = True
			fields['password_error'] = "That wasn't a valid password"
		if password != verify:
			has_error = True
			fields['verify_error'] = "Your passwords do not match"
		if email and (email_re.match(email) is None):
			has_error = True
			fields['email_error'] = 'Bad e-mail entered'
		if has_error:
			self.render('signup.html', **fields)
		else:
			user  = User(username = username, password_hash = blogcrypt.make_pw_hash(username,password), email = email)
			user.put() #stores user
			self.redirect('/blog/welcome?username='+username)
Exemplo n.º 3
0
	def register(cls,name,pw,email = None):
		pw_hash = blogcrypt.make_pw_hash(name,pw)
		return cls(name = name, pw_hash = pw_hash, email = email)