def manage_channel(channel_short): if request.method == 'POST': channel_short = request.form.get('channel_short') func = request.form.get('func') if func == 'del_member': channel_member = Member.objects.get(id=request.form.get('member_id')) MiningChannel.objects(short=channel_short).update_one(pull__members=channel_member) MiningChannel.objects(short=channel_short).update_one(pull__captains=channel_member) channel = MiningChannel.objects.get(short=channel_short) Member.objects(id=request.form.get('member_id')).update_one(pull__mining_channels=channel) elif func == 'set_capt': channel_member = Member.objects.get(id=request.form.get('member_id')) MiningChannel.objects(short=channel_short).update_one(push__captains=channel_member) elif func == 'rm_capt': channel_member = Member.objects.get(id=request.form.get('member_id')) resp = MiningChannel.objects(short=channel_short).update_one(pull__captains=channel_member) elif func == 'del_channel': MiningChannel.objects(short=channel_short).delete() return redirect(url_for('mining.mining_channels')) member = Member.get_member(current_user.email) channel = MiningChannel.objects.get(short=channel_short) is_creator = True if member == channel.createdby else False if not is_creator: abort(403) return render_template('mining/manage_channel.html', channel=channel)
def quit_channel(channel_short): member = Member.get_member(current_user.email) channel = MiningChannel.objects.get(short=channel_short) if request.method == 'POST': MiningChannel.objects(short=channel_short).update_one(pull__members=member) Member.objects(email=current_user.email).update_one(pull__mining_channels=channel) member = Member.get_member(current_user.email) channels = member.mining_channels return redirect(url_for('mining.mining_channels', member=member, channels=channels)) return render_template('mining/quit_channel.html', channel_short=channel_short)
def mining_channels(): if request.method == 'POST': member = Member.get_member(current_user.email) channel_short = request.form.get('channel_short') channel = MiningChannel.objects.get(short=channel_short) Member.objects(id=member.id).update_one(pull__mining_channels=channel) MiningChannel.objects(short=channel_short).update_one(pull__captains=member) MiningChannel.objects(short=channel_short).update_one(pull__members=member) member = Member.get_member(current_user.email) channels = member.mining_channels return render_template('mining/mining_channels.html', member=member, channels=channels)
def reset_password_with_token(token): try: email = ts.loads(token, salt=app.config['SALT'], max_age=86400) except: abort(404) form = PasswordForm() if form.validate_on_submit(): Member.objects(email=email).update_one( set__password=generate_password_hash(form.password.data)) return redirect(url_for('general.password_reset_success')) return render_template('general/please_set_your_new_password.html', form=form, token=token)