working login form from html. needs refactoring

This commit is contained in:
deflax 2018-10-18 03:34:29 +03:00
parent 8738ad8e36
commit eb49417935
5 changed files with 46 additions and 17 deletions

View file

@ -52,8 +52,8 @@ app.register_blueprint(panel_blueprint, url_prefix='/panel')
from .auth import auth as auth_blueprint from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint, url_prefix='/auth') app.register_blueprint(auth_blueprint, url_prefix='/auth')
from .news import news as news_blueprint #from .news import news as news_blueprint
app.register_blueprint(news_blueprint, url_prefix='/news') #app.register_blueprint(news_blueprint, url_prefix='/news')
from .admin import admin as admin_blueprint from .admin import admin as admin_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/' + app.config['ADMIN_PREFIX']) app.register_blueprint(admin_blueprint, url_prefix='/' + app.config['ADMIN_PREFIX'])

26
app/main/forms.py Normal file
View file

@ -0,0 +1,26 @@
from flask_wtf import FlaskForm, RecaptchaField
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
from wtforms import validators, ValidationError
from wtforms.fields.html5 import EmailField
from ..models import User
class LoginForm(FlaskForm):
email = EmailField('', [validators.DataRequired(), validators.Length(1,64), validators.Email()], render_kw={"placeholder": "username"})
password = PasswordField('', [validators.DataRequired(), validators.Length(1,128)], render_kw={"placeholder": "password"})
remember_me = BooleanField('Remember?', render_kw={"placeholder": "remember"})
#recaptcha = RecaptchaField()
submit = SubmitField('Login', render_kw={"placeholder": "submit"})
class RegistrationForm(FlaskForm):
email = StringField('E-Mail', [validators.DataRequired(), validators.Length(6,35), validators.Email()])
def validate_email(self, field):
if User.query.filter_by(email=field.data).first():
raise ValidationError('Error. Please try again.')
password = PasswordField('Password', [validators.DataRequired(), validators.EqualTo('confirm', message='Both passwords must be equal')])
confirm = PasswordField('Your password again', [validators.DataRequired()])
accept_tos = BooleanField('I accept the <a href="/terms">Terms of Service</a>', [validators.DataRequired()])
recaptcha = RecaptchaField()
submit = SubmitField('REGISTER')

View file

@ -3,6 +3,7 @@ from flask_login import login_required, login_user, logout_user, current_user
from flask_sqlalchemy import get_debug_queries from flask_sqlalchemy import get_debug_queries
from . import main from . import main
from .forms import LoginForm, RegistrationForm
from .. import db from .. import db
from ..email import send_email from ..email import send_email
from ..models import User, Permission, Server, Deployment, Service, Region, Address, Domain, contact_proxmaster from ..models import User, Permission, Server, Deployment, Service, Region, Address, Domain, contact_proxmaster
@ -19,8 +20,9 @@ def after_request(response):
#STATIC PAGES #STATIC PAGES
@main.route("/", methods=['GET']) @main.route("/", methods=['GET'])
def index(): def index():
form = LoginForm()
allservers = Server.query.filter_by(enabled=True) allservers = Server.query.filter_by(enabled=True)
return render_template('main/index.html', servers=allservers) return render_template('main/index.html', servers=allservers, form=form)
@main.route("/chat", methods=['GET']) @main.route("/chat", methods=['GET'])
def chat(): def chat():

View file

@ -4,10 +4,10 @@
.panel-transparent .panel-heading { .panel-transparent .panel-heading {
background: rgb(255, 255, 255); /* fallback */ background: rgb(255, 255, 255); /* fallback */
background: rgba(255, 255, 255, 0.7)!important; background: rgba(255, 255, 255, 0.6)!important;
} }
.panel-transparent .panel-body{ .panel-transparent .panel-body{
background: rgb(255, 255, 255); /* fallback */ background: rgb(255, 255, 255); /* fallback */
background: rgba(255, 255, 255, 0.7)!important; background: rgba(255, 255, 255, 0.5)!important;
} }

View file

@ -74,19 +74,21 @@
<div class="panel-body"> <div class="panel-body">
<div class="form"> <div class="form">
<form class="register-form"> <form class="register-form" actoion="{{ url_for('auth.register') }}" method="POST">
<input type="text" placeholder="name"/> <input type="text" placeholder="name"/>
<input type="password" placeholder="password"/> <input type="password" placeholder="password"/>
<input type="text" placeholder="email address"/> <input type="text" placeholder="email address"/>
<button>create</button> <button>create</button>
<p class="message">Already registered? <a href="#">Sign In</a></p> <p class="message">Already registered? <a href="#">Sign In</a></p>
</form> </form>
<form class="login-form"> <form class="login-form" action="{{ url_for('auth.login') }}" method="POST">
<input type="text" placeholder="username"/> <input name="email" type="text" placeholder="username"/>
<input type="password" placeholder="password"/> <input name="password" type="password" placeholder="password"/>
<button>login</button> <input name="remember_me" type="checkbox"/>
<p class="message">Not registered? <a href="#">Create an account</a></p> {{ form.csrf_token }}
</form> <button name="submit">login</button>
<p class="message">Not registered? <a href="#">Create an account</a></p>
</form>
</div> </div>
</div> </div>
@ -97,7 +99,7 @@
<div class="container-fluid-index"> <div class="container-fluid-index">
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-5 col-md-offset-1">
<div class="panel panel-primary panel-transparent"> <div class="panel panel-primary panel-transparent">
<div class="panel-body"> <div class="panel-body">
<img src="../../static/images/VPS-equipment.png" width="64" height="64" /> <img src="../../static/images/VPS-equipment.png" width="64" height="64" />
@ -112,12 +114,11 @@
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-5 col-md-offset-0">
<div class="panel panel-primary panel-transparent"> <div class="panel panel-primary panel-transparent">
<div class="panel-body"> <div class="panel-body">
<img src="../../static/images/VPS-Mission.png" width="64" height="64" /> <p><img src="../../static/images/VPS-Mission.png" width="64" height="64" align="top"><h2 class="media-heading">Мисия</h2></p>
<h2 class="media-heading">Мисия</h2> <p>Предоставяме платформа за управление на Вашите изчислителни процеси</p>
<p>Предоставяме платформа за управление на Вашите изчислителни процеси,</p>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<img src="../../static/images/VPS-Support.png" width="64" height="64" /> <img src="../../static/images/VPS-Support.png" width="64" height="64" />