def user_logout(): if not current_user: return else: current_user.set('authenticated', False) logout_user() flash('Logout successful.', 'success') return redirect(url_for('wiki.index'))
def user_change_password(): form = ChangePasswordForm() if form.validate_on_submit(): current_user.set_password(form.confirm_password.data) current_user.set('authenticated', True) flash('Password Change Successful.', 'success') return render_template('change_password.html', form=form) return render_template('change_password.html', form=form)
def user_profile(username): user = current_users.get_user(username) form = UserUpdateForm() if form.validate_on_submit(): if form.password.data != '': current_user.set('password', form.password.data) if form.email.data != '': current_user.set('email', form.email.data) flash('Profile Updated!', 'success') return render_template('profile.html', user=user, form=form)
def post_change_email(): pw_form = PasswordForm() email_form = EmailForm() deactivate_form = DeactivateForm() if email_form.validate(): if email_form.email.data != current_user.email: current_user.change_email(email_form.email.data) flash("Email successfully changed", "success") if email_form.public.data != current_user.email_public: current_user.set("email_public", email_form.public.data) return render_template( "settings-account.html", pw_form=pw_form, email_form=email_form, deactivate_form=deactivate_form, )
def rssfeed(): """ The user can provide the RSS Feed's url that they wish to view title/link information for. To view a different RSS Feed's data they just need to enter another feed's url. :return: rssfeed.html and the feed data that was parsed (each entry's title and link) """ form = RssfeedForm() if form.validate_on_submit(): rssurl = form.rssurl.data if (get_feed_title(rssurl) != "PLEASE PROVIDE A DIFFERENT RSS FEED URL"): # save rssurl in users.json current_user.set('rssurl', rssurl) form.rssurl.data = current_user.get('rssurl') rssurl = form.rssurl.data rssdata = get_rss_data(rssurl) channeltitle = get_feed_title(rssurl) return render_template('rssfeed.html', form=form, rssdata=rssdata, channeltitle=channeltitle)
def vote(product_id, action): if datetime.datetime.utcnow() > datetime.datetime(2017, 3, 16, 16, 0, 0): return jsonify({'success': False, 'error': '投票已截止'}) if action == 'vote': ff_vote_count = FFVote.query.equal_to('authUser', current_user).count() if ff_vote_count >= const.VOTE_LIMIT: return jsonify({ 'success': False, 'error': '最多只能投 ' + str(const.VOTE_LIMIT) + ' 票' }) try: ff_product = FFProduct.query.get(product_id) except LeanCloudError as _: return jsonify({'success': False, 'error': '没有查询到该作品'}) try: ff_auth = FFAuth.query.get(current_user.id) except LeanCloudError as _: return jsonify({'success': False, 'error': '没有查询到该用户'}) ff_vote = None try: ff_vote = FFVote.query.equal_to('authUser', ff_auth).equal_to( 'targetProduct', ff_product).first() except LeanCloudError as _: pass if action == 'vote': if ff_vote: return jsonify({'success': False, 'error': '已经投过'}) try: ff_vote = FFVote() ff_vote.set('authUser', ff_auth) ff_vote.set('targetProduct', ff_product) ff_vote.save() except LeanCloudError as _: return jsonify({'success': False, 'error': '写入数据库失败'}) try: vote_count = ff_product.get('vote') + 1 ff_product.set('vote', vote_count) ff_product.save() vote_result = current_user.get('voteResult') if ff_product.id not in vote_result: vote_result.append(ff_product.id) current_user.set('voteResult', vote_result) current_user.save() except LeanCloudError as _: pass return jsonify({'success': True, 'error': ''}) if action == 'undo': if not ff_vote: return jsonify({'success': True, 'error': ''}) try: ff_vote.destroy() except LeanCloudError as _: return jsonify({'success': False, 'error': '删除失败'}) try: vote_count = ff_product.get('vote') - 1 ff_product.set('vote', vote_count) ff_product.save() vote_result = current_user.get('voteResult') if ff_product.id in vote_result: vote_result.remove(ff_product.id) current_user.set('voteResult', vote_result) current_user.save() except LeanCloudError as _: pass return jsonify({'success': True, 'error': ''})
def user_logout(): current_user.set('authenticated', False) logout_user() flash('Logout successful.', 'success') return redirect(url_for('wiki.user_login'))
def update_activity(): if current_user.is_authenticated: current_date = datetime.now().strftime("%I:%M%p %m/%d/%y") current_user.set('last_active', current_date)
def user_logout(): current_user.set('authenticated', False) logout_user() flash('Logout successful.', 'success') return redirect(url_for('wiki.index'))
def setEmail(url): email = request.form['value'] current_user.set('email', email) return redirect(url)
def setEditor(url): editor = request.form['value'] current_user.set('editor', editor) return redirect(url)
def user_logout(): current_user.set('authenticated', False) current_user.set('active', False)