コード例 #1
0
ファイル: email.py プロジェクト: jakozaur/ozaur
  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()
コード例 #2
0
ファイル: email.py プロジェクト: jakozaur/ozaur
  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()
コード例 #3
0
ファイル: email.py プロジェクト: jakozaur/ozaur
  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()
コード例 #4
0
ファイル: test_email.py プロジェクト: jakozaur/ozaur
    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?")
コード例 #5
0
def index(page=1, pagesize=10, sortby='id', sortdir='asc', search=None):
    """
    /api/contacts
    :return: list of contacts with paging information
    """
    if search is not None:
        return searchContacts(search)

    contacts = Contact.select().order_by(
        SQL(f"{sortby} COLLATE NOCASE {sortdir}")).paginate(page, pagesize)
    emails = Email.select()
    phones = Phone.select()

    contacts_with_emails_iter = prefetch(contacts, emails, phones)
    data = []
    for contact in contacts_with_emails_iter:
        data.append(
            contact.serialize()
            # {
            #     'id': contact.id,
            #     'fname': contact.fname,
            #     'lname': contact.lname,
            #     'dob': contact.dob,
            #     'emails': [ {'id': em.id, 'email': em.email } for em in contact.emails ]
            # }
        )

    return {
        'data': data,
        'numberRecords': Contact.select().count(),
        'page': page,
        'pagesize': pagesize
    }
コード例 #6
0
 def handle_confirm_register(self):
     key = self.request.get('key')
     passwd = self.request.get('passwd')
     entity = Email.get_by_key(key)
     if not entity or entity.passwd != passwd:
         return False
     entity.registered = 1
     entity.put()
     return True, 'ok'
コード例 #7
0
ファイル: app_base.py プロジェクト: yabincui/SelfControlBoard
 def parse_email(self):
     email = self.request.get('email')
     passwd = self.request.get('passwd')
     if email and passwd:
         entity = Email.get_instance(email)
         if entity and entity.passwd == passwd and entity.registered == 1:
             return email
         if self.is_test_env() and email == '*****@*****.**':
             return email
     return None
コード例 #8
0
    def post(self):
        user_id = self.session['user_id']
        destination = self.get_argument('destination')
        content = self.get_argument('content')
        timeStamp = time.mktime(datetime.now().timetuple())

        email = Email.new(str(user_id), destination, content, timeStamp, 0,
                          self.user.screen_name)

        message = {"status": "success"}
        self.finish(json.dumps(message))
コード例 #9
0
 def handle_login(self):
     email = self.email
     if not email:
         email = self.request.get('email')
         if not email:
             return False
         entity = Email.get_instance(email)
         if entity.registered:
             return False, 'password is wrong'
         return False, "%s hasn't been registered" % email
     return True, email
コード例 #10
0
	def post(self):
		user_id				= self.session['user_id']
		destination			= self.get_argument('destination')
		content				= self.get_argument('content')
		timeStamp = time.mktime(datetime.now().timetuple())

		email				= Email.new(str(user_id),destination,content,timeStamp,
							0,self.user.screen_name)

		message	= {"status":"success"}
		self.finish(json.dumps(message))
コード例 #11
0
ファイル: test_email.py プロジェクト: jakozaur/ozaur
 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)
コード例 #12
0
	def post(self):
		email_id= self.get_argument('email')
		print 'mail id',email_id
		if not email_id:
			self.finish()

		user_id	= self.session['user_id']
		email	= Email.find(to_user_id = str(user_id), _id = email_id)
		if email == None:
			self.finish()
			return

		message	= {"status":"success", "email":str(email.content)}
		self.finish(json.dumps(message))
コード例 #13
0
    def post(self):
        email_id = self.get_argument('email')
        print 'mail id', email_id
        if not email_id:
            self.finish()

        user_id = self.session['user_id']
        email = Email.find(to_user_id=str(user_id), _id=email_id)
        if email == None:
            self.finish()
            return

        message = {"status": "success", "email": str(email.content)}
        self.finish(json.dumps(message))
コード例 #14
0
def delete(eid):
    """
    /api/emails/{eid}
    Delete email identified by eid

    :param eid:    new contact information
    :return:       the deleted email
    """
    try:
        email = Email.get(Email.id == eid)
    except:
        abort(404, f"Email with id {eid} not found")

    email.delete_instance()

    return email.serialize()
コード例 #15
0
    def post(self):
        page = int(self.get_argument('page', 1))
        user_id = self.session['user_id']
        all_emails = [
            email for email in Email.find_all(to_user_id=str(user_id))
        ]
        #sort=[('send_date',1)]) ]
        total_emails = len(all_emails)
        pages = math.ceil((1.0 * total_emails) / self.PAGE_SIZE)
        if page > pages:
            current = pages
        else:
            if page <= 0:
                current = 1
            else:
                current = page
        start = (current - 1) * self.PAGE_SIZE
        if start < 0:
            start = 0
        end = start + self.PAGE_OFFSET
        print "[%d,%d, %d, %d] " % (page, pages, start, end)
        emails = all_emails[start:end]
        email_list = list()
        for email in emails:
            email_list.append({
                "id":
                email.id,
                "date":
                datetime.fromtimestamp(
                    email.send_date).strftime("%Y-%m-%d %H:%M:%S"),
                "sender_name":
                email.sender_name,
                "sender_id":
                str(email.from_user_id),
                "message":
                email.content
            })

        message = {
            "status": "success",
            "total": int(total_emails),
            "pages": int(pages),
            "current": int(current),
            "emails": email_list
        }

        self.finish(json.dumps(message))
コード例 #16
0
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()
コード例 #17
0
def update(eid, email):
    """
    /api/emails/{eid}
    Update email identified by eid
   
    :param eid:    id of the email to retrieve
    :param email:  new email information
    :return:       the new email information
    """
    try:
        theEmail = Email.get(Email.id == eid)
    except DoesNotExist:
        abort(404, f"Email with ie {eid} for contact {cid} not found")
    theEmail.email = email.get("email")
    theEmail.save()

    return theEmail.serialize()
コード例 #18
0
def create(cid, email):
    """
    /api/contacts/{cid}/emails
    Create new contact email
    
    :param email: email information
    :return:      matching email
    """
    emailAddress = email.get("email", None)

    if emailAddress is None:
        abort(406, "Email field must not be empty")

    model = Email.create(**{
        'email': emailAddress,
        'contact_id': cid
    })

    return make_response(f"{emailAddress} successfully created for contact {cid}", 201)
コード例 #19
0
 def handle_register(self):
     email = self.request.get('email')
     passwd = self.request.get('passwd')
     if not email or not passwd:
         return False
     entity = Email.create(email, passwd)
     if not entity:
         return False, '%s has been registered' % email
     url = UrlUtil.urlencode('/confirm_register', {
         'key': entity.key.urlsafe(),
         'passwd': passwd
     })
     self.send_email(
         email, 'Register confirm mail', """Please click below url to login:
             %s
         """ % ('https://selfcontrolboard.appspot.com' + url))
     if self.is_test_env():
         return True, 'http://localhost:8080' + url
     else:
         return True, 'ok'
コード例 #20
0
	def post(self):
		page		= int(self.get_argument('page', 1))
		user_id		= self.session['user_id']
		all_emails	= [ email for email in Email.find_all(to_user_id=str(user_id)) ]
			#sort=[('send_date',1)]) ]
		total_emails=  len(all_emails)
		pages		= math.ceil((1.0 *total_emails) / self.PAGE_SIZE)
		if page > pages:
			current = pages
		else:
			if page <= 0:
				current	= 1
			else:
				current = page
		start		= (current - 1) * self.PAGE_SIZE
		if start < 0:
			start = 0
		end			= start + self.PAGE_OFFSET
		print "[%d,%d, %d, %d] " % (page,pages, start, end)
		emails		= all_emails[start:end]
		email_list	= list()
		for email in emails:
			email_list.append({
								"id": email.id,
								"date": datetime.fromtimestamp(email.send_date).strftime("%Y-%m-%d %H:%M:%S"),
								"sender_name": email.sender_name,
								"sender_id":str(email.from_user_id),
								"message": email.content
							})

		message =	{
						"status":	"success",
						"total":	int(total_emails),
						"pages":	int(pages),
						"current":	int(current),
						"emails":	email_list
		}

		self.finish(json.dumps(message))
コード例 #21
0
ファイル: test_email.py プロジェクト: jakozaur/ozaur
    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")
コード例 #22
0
	def post(self):
		user_id = self.session['user_id']
		email_id= self.get_argument('email_id')
		Email.find(_id = email_id, to_user_id = str(user_id)).remove()
		message = {"status":"success"}
		self.finish(json.dumps(message))
コード例 #23
0
 def post(self):
     user_id = self.session['user_id']
     email_id = self.get_argument('email_id')
     Email.find(_id=email_id, to_user_id=str(user_id)).remove()
     message = {"status": "success"}
     self.finish(json.dumps(message))