示例#1
0
文件: membership.py 项目: masyl/wrook
	def get(self, key):
		import app
		self.onRequest()
		if self.CurrentMember:
			self.redirect("/") # Refactor: This special case should be handled: "Accept invite while being already logged in"
		else:
			if key: invite = Invite.get(key)
			else: invite = Invite()
			self.Model.update({
				"wrookAdmin": app.getWrookAdmin(),
				"invite": invite,
				"email": invite.Email.strip().lower(),
				"firstname": invite.Firstname.strip(),
				"lastname": invite.Lastname.strip()
				})
			self.render2('views/join.html')
示例#2
0
文件: membership.py 项目: masyl/wrook
	def post(self, key): #TODO: Refactor -  This handler should be moved to the membership module and actuel business logic should be in separate methods
		import app
		self.onRequest()
		if key: invite = Invite.get(key)
		else: invite = None
		username = self.request.get("Username").strip().lower() #TODO: Stripping and lowercasing should also be in the class logic
		email = self.request.get("Email").strip().lower() #TODO: Stripping and lowercasing should also be in the class logic
		firstname = self.request.get("Firstname").strip()
		lastname = self.request.get("Lastname").strip()
		gender = self.request.get("Gender")
		preferedLanguage = self.request.get("PreferedLanguage")
		isValid = True
		if (firstname == "" or lastname == "" or email == "" or username == ""):
			isValid = False
			error = _("Username, email, firstname and lastname are madatory!")
		elif (not username.isalnum()):
			isValid = False
			error = _("Sorry, the username can only contain letters and numbers.")
		elif (getMemberFromCredentials(email)): #TODO: Refactor -  This constraint should be built into the Member entity
			isValid = False
			error = _("This email address is already used by another member")
		elif (getMemberFromCredentials(username)): #TODO: Refactor -  This constraint should be built into the Member entity
			isValid = False
			error = _("This username address is already used by another member")

		# If no admin is setup and the email matches the one in the config. Gite admin rights
		admin = app.getWrookAdmin()
		if not admin:
			isNewAdmin = True
			wrookAppConfig = app.getWrookAppConfig(flushCache=True)
			if (wrookAppConfig.SiteAdminEmail.lower() != email):
				isValid = False
				error = _("The email address provided does not match the site administrator email provided during the initial setup.")

		if (not isValid):
			self.Model.update({
				'username': username,
				'email': email,
				'firstname': firstname,
				'lastname': lastname,
				'gender': gender,
				'preferedLanguage': preferedLanguage,
				'error': error
				})
			self.render2("views/join.html")
		else:
			member = Member(
				Username = username,
				Email = email,
				Firstname = firstname,
				Lastname = lastname,
				Gender = gender,
				PreferedLanguage = preferedLanguage,
				)
			member.Firstname = firstname
			member.Lastname = lastname

			if isNewAdmin:
				member.isAdmin = True
				member.save() # attribute assignation is repeated for them to be catched by the searchable model
				member.setPassword(email, self.AppConfig.EncryptionKey)
				self.redirect("/Login")
			else:
				member.save() # attribute assignation is repeated for them to be catched by the searchable model
				member.resetPassword(self.AppConfig.EncryptionKey)
				self.redirect("/ResetPassword/%s" % member.key())