def login(): form = LoginForm() if form.validate_on_submit(): # User has authenticated. Log in. # Remove the user from all chat queues form.user.chat = None db.session.commit() flash('Welcome back to ChatSchoolette!', 'alert-success') login_user(form.user, remember=form.remember.data, force=True) return redirect(request.args.get('next') or url_for('default.home')) else: flash_form_errors(form) return render_template('auth/login.html', form=form)
def search(): form = SearchForm() if form.validate_on_submit(): if len(form.users) == 0: flash( "Oops! No results! Maybe you shouldn't be so picky :)", "alert-warning", ) return render_template('account/search.html', form=form) return render_template('account/search_results.html', users=form.users) else: flash_form_errors(form) return render_template('account/search.html', form=form)
def reset(key): form = ResetPasswordForm() if form.validate_on_submit(): form.user.reset_password(form.password.data) flash( "Your password has been successfully reset!", "alert-success", ) login_user(form.user, force=True) return redirect(url_for('default.home')) else: flash_form_errors(form) form.key.data = key return render_template('auth/reset.html', form=form, key=key)
def edit(): form = EditAccountForm() if form.validate_on_submit(): current_user.update_account(form) flash( "Your account has been updated successfully.", "alert-success", ) return redirect(url_for('account.home')) else: flash_form_errors(form) form.gender.data = current_user.profile.gender form.profile_description.data = current_user.profile.body form.interests_text.data = '\n'.join( interest.name for interest in current_user.profile.interests ) return render_template('account/edit.html', form=form)
def home(): form = StartChatForm() form.domain.data = current_user.profile.domain # The user is loading the chat select screen and doesn't have a match yet if form.validate_on_submit(): if form.is_video: if form.is_new: db.session.add(form.room) form.room.users.append(current_user) db.session.commit() return redirect(url_for('chat.video_chat', room_id=form.room.id)) else: if form.is_new: db.session.add(form.room) form.room.users.append(current_user) db.session.commit() return redirect(url_for('chat.text_chat', room_id=form.room.id)) else: flash_form_errors(form) return render_template('chat/home.html', form=form)
def register(): form = RegistrationForm() if form.validate_on_submit(): # Create the user account by first db.session.add(form.user) db.session.add(form.profile) db.session.commit() # Add the user's profile picture if they provided one if form.profile_picture.has_file(): form.profile.set_profile_picture(form.profile_picture) # Finally, commit the db session db.session.commit() # Log the user in and redirect to the homepage login_user(form.user, remember=form.remember.data, force=True) flash('Your account has been created.', 'alert-success') return redirect(request.args.get('next') or url_for('default.home')) else: flash_form_errors(form) return render_template('auth/register.html', form=form)