Created
October 21, 2019 06:49
-
-
Save mohanadkaleia/31e51fe19653f7fdfd4062e3c23f0f81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app.py | |
import user as user_service | |
from flask import request, make_response, jsonify, Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def hello(): | |
return "Hello World!" | |
@app.route('/login', methods=['POST']) | |
def login_view(): | |
name = request.form.get('name', None) | |
password = request.form.get('password', None) | |
if not name or not password: | |
return make_response(jsonify({'status': 'fail', 'message': 'name and password required'})), 404 | |
user = user_service.get_by_name_password(name=name, password=password) | |
if user: | |
token = user_service.encode_auth_token(user['name']).decode('utf8') | |
return token | |
else: | |
return make_response(jsonify({'status': 'fail', 'message': 'bad email or password'})), 404 | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment