Skip to content

Instantly share code, notes, and snippets.

@mohanadkaleia
Created October 21, 2019 06:49
Show Gist options
  • Save mohanadkaleia/31e51fe19653f7fdfd4062e3c23f0f81 to your computer and use it in GitHub Desktop.
Save mohanadkaleia/31e51fe19653f7fdfd4062e3c23f0f81 to your computer and use it in GitHub Desktop.
# 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