def login():
#Login method
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
user = User.query.filter_by(username=username, password=password).first()
if user is None:
return Response(status=400)
else:
token = random.randint(1000000000, 9999999999)
user.token = token
user.token_expiry_date = datetime.datetime.now() + datetime.timedelta(minutes=15)
db.session.commit()
return jsonify(id=user.id, user_type=user.user_type, token=token)
Now how can I use the above Python method in the below HTML form to login?
<form> <br> <center> Username: <input type="text" name="username" style="background:#bfbfbf;color:#212121;border-color:#212121;" onfocus="this.style.background = '#ffffff';" onblur="this.style.background = '#bfbfbf';"> <br> Password: <input type="password" name="password" style="background:#bfbfbf;color:#212121;border-color:#212121;" onfocus="this.style.background = '#ffffff';" onblur="this.style.background = '#bfbfbf';"> <br> <input type="button" value="Login" onclick="Login(this.form);" style="background:#bfbfbf;color:#000000;border-color:#212121;" onmouseover="this.style.color = '#404040';" onmouseout="this.style.color = '#000000';" onfocusr="this.style.color = '#404040';" onblur="this.style.color = '#000000';"> </center> </form>
Thanks

New Topic/Question
Reply




MultiQuote







|