Open slippers opened 8 years ago
@slippers
SECURITY_LOGIN_USER_TEMPLATE = 'custom/login.html'
# forms.py
from flask.ext.security.forms import LoginForm
class ExtendedLoginForm(LoginForm):
email = EmailField('Email', [validators.DataRequired(message='email is required '), validators.Email(message='invalid email address')])
password = PasswordField('Password', [validators.DataRequired(message='password is required')])
remember = BooleanField('Remember Me')
custom template
# templates/custom/login.html
<form action="{{ url_for_security('login') }}" method="POST" name="login_form" class="form">
{{ login_user_form.hidden_tag() }}
<div class="form-group">
{{ login_user_form.email(class='form-control', placeholder='email address') }}
</div>
<div class="form-group">
{{ login_user_form.password(class='form-control', placeholder='password') }}
</div>
<div class="form-group">
<div class="col-md-12">
<div class="checkbox">
<label>
{{ login_user_form.remember }} {{ login_user_form.remember.label }}
</label>
</div>
{{ login_user_form.submit(class='btn btn-primary pull-right') }}
</div>
</div>
</form>
Setup your flask security
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore, login_form=ExtendedLoginForm)
Hope thats help
It would be nice to add support for themes similar to Flask-Admin (https://github.com/flask-admin/flask-admin/tree/master/flask_admin/templates)
@erwinyusrizal Thanks a lot, solved the issue for me!
@jirikuncar I know this thread is old - but this is just what I was thinking and am still searching for!
is there a way to avoid copying the security templates to the local app? how can I just include the site-package/flask_security/templates into a generic page template? maybe interrupt the render_template from that view.login from the main app via some kind of pre-process?
was able to customize the security.login page by creating the local application /templates/security/login_user.html.