#
# list.py : Interfaces to access list.
#

from db import user
from interfaces import app
import json


@@ -96,9 +96,1231 @@
 rt json%0A
-%0A
+from flask import request%0Afrom flask import make_response%0Afrom flask import session%0A%0A# /login : Login to user's account%0A@app.route(%22/login%22, methods=%5B%22POST%22%5D)%0Adef login():%0A    %22%22%22 Login to user's account %22%22%22%0A%0A    # Get login and password%0A    login = request.authorization%5B%22username%22%5D%0A    password = request.authorization%5B%22password%22%5D%0A%0A    # Do some check in the database%0A    if True:%0A        # Set username/password in the response%0A        session%5B%22username%22%5D = login%0A        session%5B%22password%22%5D = password%0A%0A        # Send ok response with cookie%0A        return json.dumps(%7B%22response%22 : 0%7D)%0A    else:%0A        # Sorry man%0A        return json.dumps(%7B%22reponse%22 : -1, %22error%22 : %22Wrong username or password%22%7D, sort_keys=True)%0A%0A# /login/signup : Create an account%0A@app.route(%22/login/signup%22, methods=%5B%22POST%22%5D)%0Adef signup():%0A    %22%22%22 Create a new account %22%22%22%0A%0A    # Get new username and password%0A    username = request.form%5B%22username%22%5D%0A    password = request.form%5B%22password%22%5D%0A%0A    # Try to create account%0A    resp, msg = user.create_account(username, password)%0A%0A    # Create the account%0A    if resp:%0A        return json.dumps(%7B%22response%22 : 0, %22message%22 : msg%7D)%0A    else:%0A        return json.dumps(%7B%22response%22 : -1, %22message%22 : msg%7D)

Create account and login