def send_answer_email(self, transaction, question): email = Email(to_user_id = transaction.seller.id, transaction_id = transaction.id, email_hash = random_email_hash(), # We need it b/c we use it before commit purpose = "answer") db.session.add(email) args = {"buyer": transaction.buyer.display_name, "seller": transaction.seller.display_name, "question": question, "hash": email.email_hash } if self._send_email(transaction.seller, "Answer the question from '%s', earn bitcoin!" % (transaction.buyer.display_name), """ Hi %(seller)s, '%(buyer)s' have a question for you, please answer it by replying to this email. You will earn bitcoins for this response. Please concentrate and try to spend at least 5 minutes on it. It is ok to decline requests, but please be as helpful as possible. Question: ''' %(question)s ''' Thanks for selling your attention, Ozaur PS: Please try to write your answer within 48 hours. Otherwise you may not earn bitcoin... Hash: %(hash)s (please don't remove it)""" % args): db.session.commit() else: db.session.rollback()
def send_question_email(self, transaction): email = Email(to_user_id = transaction.buyer.id, transaction_id = transaction.id, email_hash = random_email_hash(), # We need it b/c we use it before commit purpose = "ask") db.session.add(email) args = {"buyer": transaction.buyer.display_name, "seller": transaction.seller.display_name, "hash": email.email_hash } if self._send_email(transaction.buyer, "You won '%s' attention, ask him a question" % (transaction.seller.display_name), """ Hi %(buyer)s, You won '%(seller)s' attention. Ask this person a question by replying to this email. Be concise, the question should be answerable in ~ 5 minutes. You will get an email once we get an answer to your question. Thanks for buying the attention, Ozaur PS: Please try to write your question within 48 hours. Hash: %(hash)s (please don't remove it)""" % args): db.session.commit() else: db.session.rollback()
def send_invitation_email(self, user): if user.active: app.logger.warn("User '%s' is already activate" % (user.email)) return previous_email = Email.query.filter(Email.to_user_id == user.id, Email.purpose == "verify").first() if previous_email: app.logger.warn("We already sent email to '%s'" % (user.email)) return email = Email(to_user_id = user.id, email_hash = random_email_hash(), # We need it b/c we use it before commit purpose = "verify") db.session.add(email) if self._send_email(user, "Join the Ozaur! Buy and sell attention using bitcoin.", """ Welcome %(name)s! You're about to join the attention marketplace! If you have registered, please confirm by replying "JOIN OZAUR" to this email. If you don't reply we can't proceed further. Yours truly, Ozaur PS: If you didn't register to Ozaur, please ignore this message. Hash: %(hash)s (please don't remove it) """ % {"name": user.display_name, "hash": email.email_hash }): db.session.commit() else: db.session.rollback()
def test_got_question_twice(self): transaction = Transaction(bid_id_old=42, bid_created_at=self.user.created_at, buyer_user_id=self.user.id, seller_user_id=self.another_user.id, value_satoshi=100, coinbase_order="unknown", status="wait_for_question") email = Email(to_user_id=self.user.id, purpose="ask") transaction.active_emails.append(email) db.session.add(transaction) db.session.commit() from_email = self.user.address_hash + "@example.com" self.responder.process_email(from_email, "Hash: %s ..." % (email.email_hash), "Some question?\n%s" % (from_email)) db.session.refresh(transaction) db.session.refresh(self.user) self.assertEqual(len(self.user.active_emails), 1) # We still have verification left self.trader.question_asked.assert_called_with(self.user, transaction, "Some question?")
def setUp(self): create_schema() self.user = User(email="*****@*****.**", display_name="First Last") self.another_user = User(email="*****@*****.**", display_name="Yet another user") self.email = Email(purpose="verify") self.user.active_emails.append(self.email) db.session.add(self.user) db.session.add(self.another_user) db.session.commit() self.sender = Mock() self.trader = Mock() self.responder = Responder(self.sender, self.trader)
def insertion(): user = session['username'] email = request.form['email'] msg = request.form['inputBody'] subject = request.form['subject'] time = datetime.datetime.now() obj1 = Email(subject, msg, email, user, time) db.session.add(obj1) db.session.commit() result = db.session.query(Email).filter_by(time=time).first() email_id = result.email_id obj2 = Sentbox(user, email_id) db.session.add(obj2) db.session.commit() obj3 = Inbox(email, email_id) db.session.add(obj3) db.session.commit()
def test_got_answer(self): transaction = Transaction(bid_id_old=42, bid_created_at=self.user.created_at, buyer_user_id=self.user.id, seller_user_id=self.another_user.id, value_satoshi=100, coinbase_order="unknown", status="wait_for_answer") email = Email(to_user_id=self.another_user.id, purpose="answer") transaction.active_emails.append(email) db.session.add(transaction) db.session.commit() self.responder.process_email( self.another_user.address_hash + "@example.com", "Hash: %s ..." % (email.email_hash), "Some answer") db.session.refresh(transaction) db.session.refresh(self.another_user) self.assertEqual(len(self.another_user.active_emails), 0) self.trader.question_answered.assert_called_with( self.another_user, transaction, "Some answer")