def invite(project_id, username): project = Project.query.get_or_404(project_id) form = InviteForm() if form.validate_on_submit(): user_email = form.email.data user = User.query.filter_by(email=user_email).first_or_404() subss = db.session.query(subs).filter_by(project_id=project_id, user_id=user.id).all() if len(subss) == 0: project.users_in.append(user) db.session.commit() flash(user_email + ' has successfully been added.', 'success') socketio.emit('listInvitedUser', { 'project_id': project_id, 'username': username, 'new_member_username': user.username, 'new_member_photo': user.image_file }, broadcast=True) else: flash(user_email + ' is already in this project', 'success') return redirect( url_for('project', project_id=project.id, username=current_user.username)) return render_template('invite.html', title='Invite a Member', form=form, legend='Invite a Member')
def invite(): form = InviteForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None: flash('User does not exist') return redirect(url_for('invite')) flash('User will be notified of invite') return redirect(url_for('index')) return render_template('invite.html', form=form)
def index(): form = InviteForm() if form.validate_on_submit(): # reused from Company detection, git grep designation to find it designation = current_user.email.split("@")[1].split(".")[-2].upper() to_email = form.email.data.lower() if designation in to_email.upper() or current_user.is_super: to_name = form.firstname.data.capitalize() message = " ".join(form.message.data.split()) # flat 1 liner send_invite_email(current_user, to_name, to_email, message) flash('Email invitation sent to ' + to_name, category='success') else: flash( 'Sorry, you may send email invites Only Inside Your Company!', category='warning') return render_template('index.html', title=Company.query.get( current_user.company_id).name, form=form, refresh=app.config['PAGE_REFRESH'])