def getform(): firstname = request.form['firstNameInput'] lastname = request.form['lastNameInput'] name = firstname + lastname email = request.form['usernameInput'] pw1 = request.form['passwordInput'] pw2 = request.form['confirmPasswordInput'] if pw1 == pw2: hash = md5(pw1).hexdigest() user = User(email_address=email, name=name, hash=hash) user.save() logger.info("Got signup request: " + repr(flask.request.form)) return '', 200
def check_auth(username, password): """This function is called to check if a username / password combination is valid. """ user=User.get_by(email_address=username) if user == None: return False if md5(password).hexdigest() != user.hash: return False return True
def add_new_entry(id): message = request.get_json() spec_message = message['text'] email = message['email'] user = User.get(email) spec_time = datetime.now() conversation = Conversation.get(id) new_message = ConversationEntry(text=spec_message, user=user, time=spec_time) conversation.entries.append(new_message) score = randint(-8, 20) vote = Vote(user=user, score=score, conversation=conversation) conversation.votes.append(vote) conversation.save() return '', 200
def get_conversations_hardcoded(): password = "******" hash = md5(password).hexdigest() user_one = User.get_by(email_address="*****@*****.**") or \ User(email_address="*****@*****.**", name="Bob", hash=hash) user_two = User.get_by(email_address="*****@*****.**") or \ User(email_address="*****@*****.**", name="Jane", hash=hash) entries = [ ConversationEntry(user=user_one, text="KILL ALL UNICORNS!!!1111", time=datetime.now()), ConversationEntry(user=user_two, text="NNNooooooooooo", time=datetime.now()) ] participants = [ ConversationParticipant(user=user_one, stance="KILL ALL UNICORNS"), ConversationParticipant(user=user_two, stance="SAVE THE UNICORNS"), ] question_text = "Should unicorn hunting be outlawed?" question = Question.get_by(text=question_text) or Question(text=question_text, topic="Conservation") conversation = Conversation( votes=[], entries=entries, participaints=participants, question=question) return flask.jsonify({"conversations": [conversation.to_json()]}), 200