def sign_in(): email = request.form['username'] password = request.form['password'] is_valid = database_helper.is_valid_login(email, password) if is_valid: token = str(uuid.uuid4()) logged_in_users[token] = email return jsonify({"success": True, "message": "Successfully signed in.", "data": token}) else: return jsonify({"success": False, "message": "Wrong username or password."})
def change_password(): token = request.form['token'] new_password = request.form['new_password'] old_password = request.form['old_password'] if token not in logged_in_users: return jsonify({"success": False, "message": "You must be logged in to change password."}) else: email = logged_in_users[token] is_valid = database_helper.is_valid_login(email, old_password) if not is_valid: return jsonify({"success": False, "message": "Old password is not correct."}) else: database_helper.update_password(email, new_password) return jsonify({"success": True, "message": "Password changed successfully."})