diff --git a/ereuse_devicehub/forms.py b/ereuse_devicehub/forms.py index 0f4cefbe..022ea08e 100644 --- a/ereuse_devicehub/forms.py +++ b/ereuse_devicehub/forms.py @@ -101,3 +101,50 @@ class PasswordForm(FlaskForm): if commit: db.session.commit() 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 + diff --git a/ereuse_devicehub/templates/ereuse_devicehub/user_login.html b/ereuse_devicehub/templates/ereuse_devicehub/user_login.html index f6423759..da621992 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/user_login.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/user_login.html @@ -60,7 +60,7 @@
-

Don't have account? Create an account

+

Don't have account? Create an account

diff --git a/ereuse_devicehub/templates/ereuse_devicehub/user_registration.html b/ereuse_devicehub/templates/ereuse_devicehub/user_registration.html new file mode 100644 index 00000000..549ea9a8 --- /dev/null +++ b/ereuse_devicehub/templates/ereuse_devicehub/user_registration.html @@ -0,0 +1,94 @@ +{% extends "ereuse_devicehub/base.html" %} + +{% block page_title %}Login{% endblock %} + +{% block body %} +
+
+ +
+
+
+
+ +
+ +
+ +
+ +
+ +
+
Register as a new User
+

Enter an Email & password for to do a new register.

+ {% if form.form_errors %} +

+ {% for error in form.form_errors %} + {{ error }}
+ {% endfor %} +

+ {% endif %} +
+ +
+ {{ form.csrf_token }} + +
+ + +
Please enter your email.
+
+ +
+ + +
Please enter a password!
+
+ +
+ + +
Please enter a password again!
+
+ +
+ +
+
+

Don't have account? Create an account

+
+
+ +
+
+ +
+ Designed by BootstrapMade +
+ +
+
+
+ +
+ +
+
+ + + +{% endblock body %} diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index dc426d8e..b1b18c3f 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -6,7 +6,7 @@ from sqlalchemy import or_ from ereuse_devicehub import __version__, messages 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.lot.models import Lot from ereuse_devicehub.resources.user.models import User @@ -108,7 +108,25 @@ class UserPasswordView(View): 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('/logout/', view_func=LogoutView.as_view('logout')) 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'))