def app_before_req(): # 每次请求获取当前用户,设置全局变量 g.user = current_user() # log('='*20) # log('remote address and user:'******'x-real-ip:', request.headers['x-real-ip']) # log('x-forwarded-for:', request.headers['x-forwarded-for']) # log('=' * 20) log('before_request current_user:', g.user)
def change_password(): u = current_user() form = request.form.to_dict() if u.check_password(form['old_pass']): u.change_password(form['new_pass']) flash('密码修改成功') else: flash('输入的旧密码不一致') return redirect(url_for('.setting'))
def image_add(): file = request.files['avatar'] suffix = file.filename.rsplit('.', 1)[1] filename = '{}.{}'.format(str(uuid4()), suffix) path = os.path.join('app/images', filename) file.save(path) u = current_user() User.update(u.id, image='/images/{}'.format(filename)) flash('头像修改成功') return redirect(url_for('.setting'))
def add(): form = request.form.to_dict() u = current_user() reply = Reply.new(user_id=u.id, **form) Topic.update(reply.topic_id) # 主题更新时间 # 发送站内消息 receivers = users_from_content(form['content']) send_message(u, receivers, title='你被 {} AT了'.format(u.username), content=form['content']) log('sender At message: sender-{}; receivers={}'.format(u, receivers)) return redirect(url_for('topic.detail', id=form['topic_id']))
def register(): user = current_user() if user: return redirect('/') return render_template('user/register.html', token=new_csrf_token())
def login(): user = current_user() if user: return redirect('/') return render_template('user/login.html', token=new_csrf_token())
def add(): form = request.form.to_dict() u = current_user() tab = Tab.new(user_id=u.id, **form) flash('新增 [{}] Tab'.format(tab.title)) return redirect(url_for('.index'))
def index(): u = current_user() receive_messages = Message.find_all(receiver_id=u.id) return render_template('message/index.html', receive_messages=receive_messages)
def add_post(): form = request.form.to_dict() u = current_user() Topic.new(user_id=u.id, **form) return redirect(url_for('.index'))