def userExist(): username = request.form['username'] exist = account.searchUser(username=username) if exist is not None: return 'success' else: return 'fail'
def test_registerUser(self): with main.app.app_context(): user = { "username": "******", "password": "******", "email": "*****@*****.**", "zipcode": "10026" } rv = self.app.post("/registerUser", data=user, follow_redirects=True) assert b'User exists!' not in rv.data assert account.searchUser("testUser") rv = self.app.post("/registerUser", data=user, follow_redirects=True) assert b'User exists!' in rv.data print "user registration pass\n"
def sendMessage(receiver, content, sender='system', title=''): # create system account if not exists if sender == 'system' and account.searchUser('system') is None: account.registerUser('system', '*****@*****.**', 'system-pwd', 10000) time = datetime.datetime.now(pytz.timezone('US/Eastern')) message = Message(senderUsername=sender, receiverUsername=receiver, title=title, content=content, time=time) try: db.session.add(message) db.session.commit() return message.messageId except Exception as e: print e db.session.rollback() return None
def createOrder(postId, buyerName, transactionType, rcvAddress): time = datetime.datetime.now(pytz.timezone('US/Eastern')) post = searchSellerPosts(postId) if post == None: return None if not invalidSellerPost(postId): return None sellerName = post['sellerName'] seller = account.searchUser(sellerName) if seller == None: return None sndAddress = seller['address'] order = Order(postId=postId, buyerName=buyerName, sellerName=sellerName, time=time, status="In progress", transactionType=transactionType, senderAddress=sndAddress, receiverAddress=rcvAddress) try: db.session.add(order) db.session.commit() return order.orderId except Exception as e: print e db.session.rollback() return None
def userinfo(): if not loggedIn(): return redirect('/login') username = session['username'] user = account.searchUser(username) return json.dumps(user)