def login():
if request.method == 'GET':
return '''
<form action='login' method='POST'>
<input type='text' name='name' id='name' placeholder='name'></input>
<input type='password' name='pw' id='pw' placeholder='password'></input>
<input type='submit' name='submit'></input>
</form>
'''
name = request.form.get('name')
if request.form.get('pw') == password:
user = User.query.filter_by(name=name).first()
if not user:
user = User(name=name)
db.session.add(user)
db.session.commit()
flask_login.login_user(user)
return redirect(url_for('protected'))
return 'Bad login'