return to copy base
This commit is contained in:
parent
2aa8f95817
commit
76c5100fa3
|
@ -101,3 +101,50 @@ class PasswordForm(FlaskForm):
|
||||||
if commit:
|
if commit:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class UserNewRegisterForm(FlaskForm):
|
||||||
|
email = EmailField('Email Address', [
|
||||||
|
validators.DataRequired(),
|
||||||
|
validators.Length(min=6, max=35)
|
||||||
|
])
|
||||||
|
password = PasswordField('Password', [validators.DataRequired()])
|
||||||
|
password2 = PasswordField('Password', [validators.DataRequired()])
|
||||||
|
|
||||||
|
error_messages = {
|
||||||
|
'invalid_login': (
|
||||||
|
"Please enter a correct email and password. Note that both "
|
||||||
|
"fields may be case-sensitive."
|
||||||
|
),
|
||||||
|
'inactive': "This account is inactive.",
|
||||||
|
}
|
||||||
|
|
||||||
|
def validate(self, extra_validators=None):
|
||||||
|
is_valid = super().validate(extra_validators)
|
||||||
|
|
||||||
|
if not is_valid:
|
||||||
|
return False
|
||||||
|
|
||||||
|
email = self.email.data
|
||||||
|
password = self.password.data
|
||||||
|
password2 = self.password2.data
|
||||||
|
if password != password2:
|
||||||
|
self.form_errors.append('The passwords are not equal.')
|
||||||
|
|
||||||
|
txt = 'This email are in use.'
|
||||||
|
email = self.email.data
|
||||||
|
if User.query.filter_by(email=email).first():
|
||||||
|
self.form_errors.append(txt)
|
||||||
|
|
||||||
|
# def authenticate(self, email, password):
|
||||||
|
# if email is None or password is None:
|
||||||
|
# return
|
||||||
|
# user = User.query.filter_by(email=email).first()
|
||||||
|
# if user is None:
|
||||||
|
# # Run the default password hasher once to reduce the timing
|
||||||
|
# # difference between an existing and a nonexistent user (#20760).
|
||||||
|
# generate_password_hash(password)
|
||||||
|
# else:
|
||||||
|
# if user.check_password(password):
|
||||||
|
# return user
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
<button class="btn btn-primary w-100" type="submit">Login</button>
|
<button class="btn btn-primary w-100" type="submit">Login</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<p class="small mb-0">Don't have account? <a href="#TODO" onclick="$('#exampleModal').modal('show')" data-toggle="modal" data-target="#exampleModal">Create an account</a></p>
|
<p class="small mb-0">Don't have account? <a href="{{ url_for('core.user-registration') }}">Create an account</a></p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
{% extends "ereuse_devicehub/base.html" %}
|
||||||
|
|
||||||
|
{% block page_title %}Login{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<main>
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-center py-4">
|
||||||
|
<a href="{{ url_for('core.login') }}" class="logo d-flex align-items-center w-auto">
|
||||||
|
<img src="{{ url_for('static', filename='img/logo_usody_clock.png') }}" alt="">
|
||||||
|
</a>
|
||||||
|
</div><!-- End Logo -->
|
||||||
|
|
||||||
|
<div class="card mb-3">
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<div class="pt-4 pb-2">
|
||||||
|
<h5 class="card-title text-center pb-0 fs-4">Register as a new User</h5>
|
||||||
|
<p class="text-center small">Enter an Email & password for to do a new register.</p>
|
||||||
|
{% if form.form_errors %}
|
||||||
|
<p class="text-danger">
|
||||||
|
{% for error in form.form_errors %}
|
||||||
|
{{ error }}<br/>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="post" class="row g-3 needs-validation" novalidate>
|
||||||
|
{{ form.csrf_token }}
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<label for="yourEmail" class="form-label">Email</label>
|
||||||
|
<input type="email" name="email" class="form-control" id="yourEmail" required value="{{ form.email.data|default('', true) }}">
|
||||||
|
<div class="invalid-feedback">Please enter your email.</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<input type="password" name="password" class="form-control" id="password" required>
|
||||||
|
<div class="invalid-feedback">Please enter a password!</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<label for="password2" class="form-label">Password</label>
|
||||||
|
<input type="password" name="password2" class="form-control" id="password2" required>
|
||||||
|
<div class="invalid-feedback">Please enter a password again!</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<button class="btn btn-primary w-100" type="submit">Login</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-12">
|
||||||
|
<p class="small mb-0">Don't have account? <a href="#TODO" onclick="$('#exampleModal').modal('show')" data-toggle="modal" data-target="#exampleModal">Create an account</a></p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="credits">
|
||||||
|
Designed by <a href="https://bootstrapmade.com/">BootstrapMade</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</main><!-- End #main -->
|
||||||
|
|
||||||
|
<!-- Modal -->
|
||||||
|
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="exampleModalLabel">Do you want to try USOdy tools?</h5>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
Just write an email to <a href="mali:hello@usody.com">hello@usody.com</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div> <!-- End register modal -->
|
||||||
|
{% endblock body %}
|
|
@ -6,7 +6,7 @@ from sqlalchemy import or_
|
||||||
|
|
||||||
from ereuse_devicehub import __version__, messages
|
from ereuse_devicehub import __version__, messages
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.forms import LoginForm, PasswordForm
|
from ereuse_devicehub.forms import LoginForm, PasswordForm, UserNewRegisterForm
|
||||||
from ereuse_devicehub.resources.action.models import Trade
|
from ereuse_devicehub.resources.action.models import Trade
|
||||||
from ereuse_devicehub.resources.lot.models import Lot
|
from ereuse_devicehub.resources.lot.models import Lot
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
@ -108,7 +108,25 @@ class UserPasswordView(View):
|
||||||
return flask.redirect(flask.url_for('core.user-profile'))
|
return flask.redirect(flask.url_for('core.user-profile'))
|
||||||
|
|
||||||
|
|
||||||
|
class UserRegistrationView(View):
|
||||||
|
methods = ['GET', 'POST']
|
||||||
|
template_name = 'ereuse_devicehub/user_registration.html'
|
||||||
|
|
||||||
|
def dispatch_request(self):
|
||||||
|
form = UserNewRegisterForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
|
||||||
|
next_url = flask.request.args.get('next')
|
||||||
|
if not is_safe_url(flask.request, next_url):
|
||||||
|
return flask.abort(400)
|
||||||
|
|
||||||
|
return flask.redirect(next_url or flask.url_for('core.login'))
|
||||||
|
context = {'form': form, 'version': __version__}
|
||||||
|
return flask.render_template(self.template_name, **context)
|
||||||
|
|
||||||
|
|
||||||
core.add_url_rule('/login/', view_func=LoginView.as_view('login'))
|
core.add_url_rule('/login/', view_func=LoginView.as_view('login'))
|
||||||
core.add_url_rule('/logout/', view_func=LogoutView.as_view('logout'))
|
core.add_url_rule('/logout/', view_func=LogoutView.as_view('logout'))
|
||||||
core.add_url_rule('/profile/', view_func=UserProfileView.as_view('user-profile'))
|
core.add_url_rule('/profile/', view_func=UserProfileView.as_view('user-profile'))
|
||||||
|
core.add_url_rule('/new_register/', view_func=UserRegistrationView.as_view('user-registration'))
|
||||||
core.add_url_rule('/set_password/', view_func=UserPasswordView.as_view('set-password'))
|
core.add_url_rule('/set_password/', view_func=UserPasswordView.as_view('set-password'))
|
||||||
|
|
Reference in a new issue