Beispiel #1
0
	def post(self):
		self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
		roles=Role.all()
		if roles.count() == 0:
			# No roles were set up, set them up now
			adminRole = Role()
			adminRole.name=ROLE_ADMIN
			adminRole.put()
			role = Role()
			role.name=ROLE_DELIVERY_GUY
			role.put()
			role = Role()
			role.name=ROLE_COOK
			role.put()
			role = Role()
			role.name=ROLE_AGENT
			role.put()
			user = User()
			user.email = self.request.get("adminEmail")
			user.password = "******"
			m = hashlib.md5()
			encodedString = self.request.get("adminPassword").encode('ascii', errors='replace')
			m.update(encodedString)
			user.passwordHash = str(m.hexdigest())
			user.activated = True
			user.role = adminRole
			user.put();
			template = jinja_environment.get_template('templates/setup/setupSuccess.html')
			self.printPage("Sikeres inicializálás", template.render(), True, True)
		else:
			template = jinja_environment.get_template('templates/setup/alreadySetUp.html')
			self.printPage("Korábban inicializálva", template.render(), True, True)
Beispiel #2
0
	def post(self):
		referer = None
		refererKey = self.request.get('refererKey')
		if refererKey != None and refererKey != "":
			referer = User.get(refererKey)
		email = self.request.get('email')
		phoneNumber = self.request.get('phoneNumber')
		password = self.request.get('password')
		passwordCheck = self.request.get('passwordCheck')
		familyName= self.request.get('familyName')
		givenName= self.request.get('givenName')
		sourceOfInfo=self.request.get('sourceOfInfo')
		user = {}
		user["email"]= email
		user["familyName"]=familyName
		user["givenName"]=givenName
		user["phoneNumber"]=phoneNumber
		user["sourceOfInfo"]=sourceOfInfo
		users = User.gql('WHERE email = :1', email)
		refererUrlPart = ""
		if referer != None:
			refererUrlPart = "?refererKey=" + str(referer.key())
		self.session[USER]=user
		if (users.count(1)>0):
			self.session[REGISTRATION_ERROR_KEY]=REGISTRATION_ERROR_EXISTING_USER
			self.redirect('/registration' + refererUrlPart)
		elif (passwordCheck != password):
			self.session[REGISTRATION_ERROR_KEY] = REGISTRATION_ERROR_PASSWORD_DOESNT_MATCH
			self.redirect('/registration' + refererUrlPart)
		elif familyName==None or familyName=="" or givenName==None or givenName=="":
			self.session[REGISTRATION_ERROR_KEY] = REGISTRATION_ERROR_USER_NAME_NOT_FILLED
			self.redirect('/registration' + refererUrlPart)
		else:
			#Everything went ok, create the user and log him in
			user = User()
			user.email = email
			user.familyName=familyName
			user.givenName=givenName
			user.password = "******"
			m = hashlib.md5()
			encodedString = password.encode('ascii', errors='replace')
			m.update(encodedString)
			user.passwordHash = str(m.hexdigest())
			user.phoneNumber=phoneNumber
			user.activated = False
			user.registrationDate=datetime.datetime.now(timeZone)
			user.referer = referer
			user.sourceOfInfo = sourceOfInfo
			word = ''
			random = Random()
			for i in range(1,32):
				word += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
			user.activationCode = word			
			user.put()
			updateUser(user)
			template_values = {
				'email':email,
				'activationCode':word,
				'user':user
			}
			messageTemplate = jinja_environment.get_template('templates/userForms/activation/activation_code.html')
			message = mail.EmailMessage(sender="Diet Futar <*****@*****.**>")
			message.subject="Diet-futar, sikeres regisztracio"
			message.to = email
			message.body = messageTemplate.render(template_values)
			message.send()
			self.redirect("/activationPending")