def register(): data = request.json name = data.get('name') password = data.get('password') email = data.get('email') assert_if(password and len(password) >= 5 and len(password) < 20, "password len > 5 and < 20 ") assert_if(email and len(email) >= 3 and len(email) < 50 and '@' in email, "email needed ") # check unique assert_if(not db.users.find_one(dict(email=email)), "email not unique") hashed_password = sha1_string(force_utf8(password) + "users") token = sha1_string(str(uuid.uuid4())) bundle = { 'name': name, 'email': email, 'password': hashed_password, 'token': token } db.users.insert(bundle) return jsonify(bundle)
def login(): data = request.json password = data.get('password') email = data.get('email') assert_if(email, 'email needed') assert_if(password, 'password needed') hashed_password = sha1_string(force_utf8(password) + "users") user = db.users.find_one(dict( email=email, password=hashed_password )) assert_if(user, "email or password wrong") return jsonify(user)