Skip to content

Instantly share code, notes, and snippets.

@jayeshmann
Created July 27, 2020 18:43
Show Gist options
  • Save jayeshmann/aad1d716b5709a004bdc932ab4015d16 to your computer and use it in GitHub Desktop.
Save jayeshmann/aad1d716b5709a004bdc932ab4015d16 to your computer and use it in GitHub Desktop.
Made with Love in India by Jayesh for Ritik
#!flask/bin/python
from flask import *
app = Flask(__name__)
login_info = [
{
'id': 0,
'username': 'ritik',
'password': '4pkoci52e2fu'}
]
@app.route('/')
def index():
return "Made with Love in India by Ritik"
@app.route('/login',methods=['POST'])
def login():
if not request.json or not 'username' in request.json:
abort(400)
elif (request.json['username']).isdigit():
return jsonify({"status": 203,"msg": "Failure: only characters allowed in username"}),203
elif not len(request.json.get('password',"")) >= 6:
return jsonify({"status": 201,"msg": "Failure: password should be of length 6"}),201
elif not (request.json.get('password',"").isdigit()) and (request.json.get('password',"").isalpha()):
return jsonify({"status": 202,"msg": "Failure: password to have 1 character and 1 number"}),202
else:
return jsonify({"status": 200,"msg": "Success"}),200
'''new_login = {
'id': login_info[-1]['id'] + 1,
'username': request.json['username'],
'password': request.json.get('password',"")
}
login_info.append(new_login)'''
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment