コード例 #1
0
ファイル: login.py プロジェクト: algby/basic-wikiblog
	def post(self):
		username = self.request.get('username')
		password = self.request.get('password')
		verify = self.request.get('verify')
		email = self.request.get('email')
		usernameerror = ''
		if not re.compile(r'^[a-zA-Z0-9_-]{3,20}$').match(username):
			usernameerror = 'Username must consist of 3-20 alphanumeric characters.'
		elif authentication.User.get_by_key_name(username):
			usernameerror = 'That user already exists'
		passworderror = '' if re.compile('^.{3,20}$').match(password) \
			else 'Password must be 3 to 20 characters long.'
		verifyerror = '' if password == verify \
			else 'Passwords did not match.'
		emailerror = 'Not a valid email address.' if \
			(email and not re.compile('^[\S]+@[\S]+\.[\S]+$').match(email)) else ''
		if (usernameerror+passworderror+verifyerror+emailerror):
			self.render_signup(username = username, password = password,
				verify = verify, email = email, usernameerror = usernameerror,
				passworderror = passworderror, verifyerror = verifyerror,
				emailerror = emailerror)
		else:
			user = authentication.User(key_name = username,
				email = email, password = authentication.hashText(password, 3),
				ip = self.request.remote_addr)
			authentication.setCookie(self, username)
			user.put()
			redirect = str(self.request.get('redirect'))
			if redirect:
				self.redirect(redirect)
			else:
				self.redirect('/welcome')
コード例 #2
0
ファイル: login.py プロジェクト: algby/basic-wikiblog
	def post(self):
		username = self.request.get('username')
		password = self.request.get('password')
		redirect = str(self.request.get('redirect'))
		if re.compile(r'^[a-zA-Z0-9_-]{3,20}$').match(username) \
			and authentication.login(username, password):
			authentication.setCookie(self, username)
			if redirect:
				self.redirect(redirect)
			else:
				self.redirect('/welcome')
		else:
			self.render_login(username = username, password = password,
				error = 'Invalid details')