def send(): form = request.form.to_dict() form['receiver_id'] = int(request.args['id']) u = current_user() form['sender_id'] = u.id Messages.new(form) return redirect(url_for('.index'))
def add(): """发送新私信""" form = request.form.to_dict() u = current_user() receiver_id = form.get('receiver_id', None) if receiver_id is None: r_name = form.get('receiver_name', None) receiver = User.one(username=r_name) else: # receiver = User.one(id=receiver_id) receiver = cached_user_id2user(receiver_id) if receiver is None: flash('收件人不存在') elif receiver.id == u.id or receiver.username == u.username: flash('私信是发给其他人的哦,请重新输入收件人') else: Messages.send( title=form['title'], content=form['content'], sender_id=u.id, receiver_id=receiver.id, ) flash('发送成功') with data_cache.pipeline(transaction=False) as pipe: key = 'user_id_{}.sent_message'.format(u.id) key2 = 'user_id_{}.received_message'.format(receiver_id) pipe.delete(key) pipe.delete(key2) pipe.execute() return redirect(url_for('.index'))
def send_like(sender, receiver, reply_link, reply_content): form = dict(title=reply_link, content=reply_content, sender_id=sender.id, receiver_id=receiver.id, type='like') Messages.new(form)
def send_mails(sender, receivers, content): print('send_mail', sender, receivers, content) for r in receivers: form = dict(title='你被 {} AT 了'.format(sender.username), content=content, sender_id=sender.id, receiver_id=r.id) Messages.new(form)
def send_mails(sender, receivers, reply_link, reply_content): content = '链接:{}\n内容:{}'.format(reply_link, reply_content) for r in receivers: title = '你被 {} AT 了'.format(sender.username) Messages.send(title=title, content=content, sender_id=sender.id, receiver_id=r.id)
def send_mails(sender, receivers, reply_link, reply_content): print('send_mail', sender, receivers, reply_content) content = '链接:{}\n内容:{}'.format(reply_link, reply_content) for r in receivers: form = dict(title='你被 {} @ 了'.format(sender.username), content=content, sender_id=sender.id, receiver_id=r.id) Messages.new(form)
def index(): u = current_user() send = Messages.all(sender_id=u.id) received = Messages.all(receiver_id=u.id) t = render_template('mail/index.html', send=send, received=received, user=u) return t
def add(): form = request.form.to_dict() u = current_user() receiver_id = int(form['receiver_id']) Messages.send(title=form['title'], content=form['content'], sender_id=u.id, receiver_id=receiver_id) return redirect(url_for('.index'))
def send_mails(sender, receivers, reply_link, reply_content): for r in receivers: form = dict( title=reply_link, content=reply_content, sender_id=sender.id, receiver_id=r.id, type='at' ) Messages.new(form)
def send_collect(sender, receiver, reply_link, reply_content): # 更新message信息表 form = dict( title=reply_link, content=reply_content, sender_id=sender.id, receiver_id=receiver.id, type='collect' ) Messages.new(form)
def index(): u = current_user() token = new_csrf_token() sent_mail = Messages.all(sender_id=u.id) received_mail = Messages.all(receiver_id=u.id) t = render_template('mail/index.html', send=sent_mail, received=received_mail, user=u, csrf_token=token) return t
def index(u): send = Messages.all(sender_id=u.id) received = Messages.all(receiver_id=u.id) t = render_template( './mail/index.html', user=u, send=send, received=received, ) return t
def send_reply_me(sender, receiver, reply_link, replied_topic_title): print('send_reply_me', sender, receiver, replied_topic_title) content = reply_link title = '{} 回复了你 {}'.format(sender.username, replied_topic_title) Messages.send( title=title, content=content, sender_id=sender.id, receiver_id=receiver.id, type='reply_me', )
def send_at_me(sender, receivers, reply_link, reply_content): print('send_at_me', sender, receivers, reply_content) content = '链接:{}\n内容:{}'.format(reply_link, reply_content) for r in receivers: title = '你被 {} AT 了'.format(sender.username) Messages.send( title=title, content=content, sender_id=sender.id, receiver_id=r.id, type='at_me', )
def send_like_me(sender, receiver, topic_link, topic_title): print('send_reply_me', sender, receiver, topic_title) content = topic_link title = '{} 点赞了你的 {}'.format(sender.username, topic_title) Messages.send( title=title, content=content, sender_id=sender.id, receiver_id=receiver.id, type='like_me', )
def add(): form = request.form.to_dict() u = current_user() receiver_username = form['receiver_username'] r = User.one(username=receiver_username) receiver_id = r.id Messages.send(title=form['title'], content=form['content'], sender_id=u.id, receiver_id=receiver_id) return redirect(url_for('.index'))
def message(): u = current_user() if u is None: return redirect(url_for('topic.index')) else: sent_mail = Messages.all(sender_id=u.id) received_mail = Messages.all(receiver_id=u.id) print('send:', sent_mail) return render_template( 'mail/message.html', send=sent_mail, received=received_mail, )
def index(): u = current_user() unread = Messages.all(receiver_id=u.id, read=False) reads = Messages.all(receiver_id=u.id, read=True) sends = Messages.all(sender_id=u.id) token = new_csrf_token() t = render_template('mail/index.html', user=u, unread=unread, read=reads, sends=sends, token=token) return t
def delete_topic(): topic_title = request.form['title'] t = Topic.one(title=topic_title) topic_id = t.id user_id = t.user_id content = '您的帖子《{}》已被管理员删除'.format(t.title) form = dict(receiver_id=user_id, sender_id=current_user().id, content=content) Messages.new(form) Topic.delete(id=topic_id) Reply.delete(topic_id=topic_id) return redirect(url_for('.index'))
def reset_send_mail(): username = request.form['username'] u = User.one(username=username) if u is None: flash('该用户不存在!') return redirect(url_for('index.index')) token = new_csrf_token(u) Messages.send( title='sc论坛重置密码', content='http://152.136.129.239/reset/view?token={}'.format(token), sender_id=0, receiver_id=u.id) flash('邮件发送成功!') return redirect(url_for('index.index'))
def index(): u = current_user() if u is None: return redirect(url_for('index.index')) send = Messages.all(sender_id=u.id) received = Messages.all(receiver_id=u.id) t = render_template( 'mail/index.html', send=send, received=received, ) return t
def reset_send(): form = request.form.to_dict() username = form['username'] u = User.one(username=username) token = str(uuid.uuid4()) cache.set(token, u.id) # csrf_tokens[token] = u.id link = 'https://www.fengfan620.com/reset/view?token={}'.format(token) Messages.send(title='小破站重置密码', content='点击链接重置密码啦~~点击<br>{}'.format(link), sender_id=1, receiver_id=u.id) return redirect(url_for('index.index'))
def index(): u = current_user() if u: sent_messages = Messages.all(sender_id=u.id) received_messages = Messages.all(receiver_id=u.id) t = render_template( 'message/index.html', send=sent_messages, received=received_messages, ) return t else: return redirect(url_for('index.index'))
def add(): form = request.form.to_dict() u = current_user() form['sender_id'] = u.id r = User.one(username=form['receiver_name']) form['receiver_id'] = r.id m = Message(subject=form['title'], body=form['content'], sender=admin_mail, recipients=[r.email]) mail.send(m) Messages.new(form) return redirect(url_for('.index'))
def index(): rec_id = request.args.get('rec_id', None) u = current_user() send = Messages.all(sender_id=u.id) received = Messages.all(receiver_id=u.id) t = render_template( 'mail/index.html', user=u, receiver_id=rec_id, send=send, received=received, ) return t
def add(u): form = request.form.to_dict() form['receiver_id'] = int(form['receiver_id']) form['sender_id'] = u.id # 发邮件 r = User.one(id=form['receiver_id']) m = flask_mail.Message(subject=form['title'], body=form['content'], sender=admin_mail, recipients=[r.email]) mail.send(m) Messages.new(form) return redirect(url_for('.index'))
def addin(): form = request.form.to_dict() u = current_user() receiver = User.one(username=form['receiver']) if receiver is not None: # 发邮件 receiver_id = receiver.id title = '{}'.format(form['title']) Messages.send_in(title=title, content=form['content'], sender_id=u.id, receiver_id=receiver_id) return redirect(url_for('.index')) else: return redirect(url_for('.index'))
def reset(): form = request.form user = form['username'] u = User.one(username=user) token = int(uuid.uuid4()) csrf_tokens[token] = u.id print(csrf_tokens) # key = 'token_{}'.format(token) # cache.set(key, u.id) Messages.send( title='重置密码', content='http://localhost:3000/reset/view?token={}'.format(token), sender_id=u.id, receiver_id=u.id, ) return render_template('index_1.html')
def view(id): mail = Messages.one(id=id) u = current_user() if u.id in [mail.receiver_id, mail.sender_id]: return render_template('mail/detail.html', mail=mail) else: return redirect(url_for('.index'))
def view(u, id): message = Messages.one(id=id) # if u.id == mail.receiver_id or u.id == mail.sender_id: if u.id in [message.receiver_id, message.sender_id]: return render_template('mail/detail.html', message=message) else: return redirect(url_for('py_mail.index'))