def validate(self): if not Form.validate(self): return False # First check if the user has already created an account user = User.get_by_email(self.email.data) if user and user.check_password(self.password.data): self.user = user return True if self.gender.data not in range(0, 4): self.gender.errors.append('Please select a valid gender.') return False if ((datetime.now().date() - self.birthdate.data).days / 365) < 35: self.birthdate.errors.append( 'Sorry, you must be 18 or older to use ChatSchoolette :(', ) return False if User.get_by_username(self.username.data): self.username.errors.append( 'Sorry, that username is already taken.', ) return False if User.get_by_email(self.email.data): self.email.errors.append( 'It looks like that email address is already registered!', ) return False # Add each of the user's interests self.interests = filter(None, self.interests_text.data.splitlines()) self.interests = [s.lower() for s in self.interests] self.interests = [ Interest.get_or_create(interest) for interest in self.interests ] # Create a new user self.user = User( username=self.username.data, email=self.email.data, password=self.password.data, ) # Create a new user profile self.profile = Profile( user=self.user, domain=self.email.data.split('@')[1], gender=self.gender.data, birthdate=self.birthdate.data, body=self.profile_description.data, interests=self.interests, ) return True
def update_account(self, form): if form.password.data != '': self.reset_password(form.password.data) self.profile.gender = form.gender.data self.profile.body = form.profile_description.data # Update the user's interests self.profile.interests = [ Interest.get_or_create(interest) for interest in form.interests ] if form.profile_picture.has_file(): self.profile.set_profile_picture(form.profile_picture) db.session.commit()