Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2018
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. from processing import *
  2. import firebase
  3. import time
  4. signedIn = False
  5. users = {
  6.  
  7. }
  8. sendBtn = {
  9. "x": 5,
  10. "y": 5,
  11. "w": 130,
  12. "h": 30,
  13. "text": "Send A Message"
  14. }
  15.  
  16. createAccBtn = {
  17. "x": 140,
  18. "y": 5,
  19. "w": 140,
  20. "h": 30,
  21. "text": "Create An Account"
  22. }
  23.  
  24. signInBtn = {
  25. "x": 5,
  26. "y": 40,
  27. "w": 130,
  28. "h": 30,
  29. "text": "Sign In"
  30. }
  31.  
  32. btns = [sendBtn, createAccBtn, signInBtn]
  33.  
  34.  
  35. db = firebase.loadFirebase("AIzaSyDu********1917NqwNDy_vzqdb841xMyqCpeI", "chatroom-b7ae9", "chatroom-b7ae9")
  36.  
  37. def setup():
  38.  
  39. size(285, 200)
  40.  
  41. def draw():
  42. background(0)
  43. drawBtns()
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. def printOnSent(url, data):
  51. print str(data["value"]["time"]), "|", data["value"]["name"], "|", data["value"]["text"]
  52.  
  53. def addUsers(url, data):
  54. users[data["value"]["username"]] = data["value"]["password"]
  55. db.child_added('users/', addUsers)
  56.  
  57. def drawBtns():
  58. for b in btns:
  59. stroke(255)
  60. fill(255)
  61. rect(b["x"], b["y"], b["w"], b["h"])
  62. stroke(0)
  63. fill(0)
  64. textSize(14)
  65. text(b["text"], b["x"]+10, b["y"]+20)
  66. def mouseClicked():
  67. global signedIn, signInUsername
  68. if (signInBtn["x"] <= mouse.x <= signInBtn["x"] + signInBtn["w"] and signInBtn["y"] <= mouse.y <= signInBtn["y"] + signInBtn["h"]):
  69. signInUsername = raw_input("What is your username?")
  70. if signInUsername not in users:
  71. print "Username Invalid!"
  72. if signInUsername in users:
  73. signInPassword = raw_input("What is your password?")
  74.  
  75. if signInPassword == users[signInUsername]:
  76.  
  77. signedIn = True
  78. print "You are now signed in as", signInUsername
  79. if (sendBtn["x"] <= mouse.x <= sendBtn["x"] + sendBtn["w"] and sendBtn["y"] <= mouse.y <= sendBtn["y"] + sendBtn["h"]):
  80. if signedIn:
  81. newMessage = raw_input("What is your message?")
  82. curr = time.localtime(time.time())
  83. if curr[3] > 12:
  84. curr_hour = "pm"
  85. else:
  86. curr_hour = "am"
  87. curr_str = "%d:%d:%02d"%(curr[3]%12, curr[4], curr[5])+ curr_hour
  88. message = {
  89. 'name': signInUsername,
  90. 'text': newMessage,
  91. 'time': curr_str
  92. }
  93. db.push('messages/', message)
  94.  
  95. db.child_added('messages/', printOnSent)
  96.  
  97. else:
  98. print "You must be signed in to send messages!"
  99.  
  100. if (createAccBtn["x"] <= mouse.x <= createAccBtn["x"] + createAccBtn["w"] and createAccBtn["y"] <= mouse.y <= createAccBtn["y"] + createAccBtn["h"]):
  101. newUsername = raw_input("Enter your new username.")
  102. if newUsername in users:
  103. print "Username Already Exists."
  104. if newUsername not in users:
  105. newPassword = raw_input("Enter your new password. (Note: Passwords are not encrypted and could be stolen.)")
  106. newAcc = {
  107. "username": newUsername,
  108. "password": newPassword
  109. }
  110. db.push("/users", newAcc)
  111.  
  112.  
  113.  
  114.  
  115. run()
  116. # (c) 2018 Henry Langmack under the GNU GPLv3 license.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement