Add registration form, view, template

This commit is contained in:
Stephan Porada 2019-07-08 14:06:35 +02:00
parent 999e51bcc5
commit d1d5e5f114
5 changed files with 64 additions and 31 deletions

View File

@ -14,7 +14,25 @@ class LoginForm(FlaskForm):
class RegistrationForm(FlaskForm): class RegistrationForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Length(1, 64), Email()]) email = StringField('Email', validators=[DataRequired(), Length(1, 64),
Email()])
username = StringField('Username', validators=[
DataRequired(), Length(1, 64),
Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0,
'Usernames must have only letters, numbers, dots or '
'underscores')])
password = PasswordField('Password', validators=[
DataRequired(), EqualTo('password2', message='Passwords must match.')])
password2 = PasswordField('Confirm password', validators=[DataRequired()])
submit = SubmitField('Register')
def validate_email(self, field):
if User.query.filter_by(email=field.data.lower()).first():
raise ValidationError('Email already registered.')
def validate_username(self, field):
if User.query.filter_by(username=field.data).first():
raise ValidationError('Username already in use.')
class PasswordResetRequestForm(FlaskForm): class PasswordResetRequestForm(FlaskForm):

View File

@ -10,9 +10,9 @@
<div class="card-content"> <div class="card-content">
<p>Sign in into an exisiting account or register a new one!</p> <p>Sign in into an exisiting account or register a new one!</p>
<br> <br>
<div class="card-action"> <div class="card-action">
<a class="btn" href="{{url_for('auth.register')}}">Register</a> <a class="btn" href="{{url_for('auth.register')}}">Register</a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -2,33 +2,47 @@
{% block page_content %} {% block page_content %}
<div class="col s12"> <div class="col s12">
<div class="row"> <div class="card large">
<div class="card medium"> <div class="card-content">
<div class="card-content"> <span class="card-title">Register</span>
<span class="card-title">Register</span> <form method="POST">
<form> {{ form.hidden_tag() }}
<div class="input-field col s6"> <div class="input-field">
<input id="first-name" type="text" class="validate"> <i class="material-icons prefix">account_circle</i>
<label for="first-name">First Name</label> {{ form.username(class='validate') }}
</div> {{ form.username.label }}
<div class="input-field col s6"> {% for error in form.username.errors %}
<input id="last-name" type="text" class="validate"> <span class="helper-text" style="color:red;">{{ error }}</span>
<label for="last-name">Last Name</label> {% endfor %}
</div> </div>
<div class="row"> <div class="input-field">
<div class="input-field col s12"> <i class="material-icons prefix">vpn_key</i>
<input id="password" type="password" class="validate"> {{ form.password(class='validate') }}
<label for="password">Password</label> {{ form.password.label }}
</div> {% for error in form.password.errors %}
</div> <span class="helper-text" style="color:red;">{{ error }}</span>
<div class="row"> {% endfor %}
<div class="input-field col s12"> </div>
<input id="email" type="email" class="validate"> <div class="input-field">
<label for="email">Email</label> <i class="material-icons prefix">vpn_key</i>
</div> {{ form.password2(class='validate') }}
</div> {{ form.password2.label }}
</form> {% for error in form.password2.errors %}
</div> <span class="helper-text" style="color:red;">{{ error }}</span>
{% endfor %}
</div>
<div class="input-field ">
<i class="material-icons prefix">email</i>
{{ form.email(class='validate', type='email') }}
{{ form.email.label }}
{% for error in form.email.errors %}
<span class="helper-text" style="color:red;">{{ error }}</span>
{% endfor %}
</div>
<div class="card-action">
{{ form.submit(class='btn right') }}
</div>
</form>
</div> </div>
</div> </div>
</div> </div>

View File

@ -25,6 +25,7 @@
<li><a href="{{ url_for('auth.logout') }}"><i class="material-icons">chevron_left</i>Log out</a></li> <li><a href="{{ url_for('auth.logout') }}"><i class="material-icons">chevron_left</i>Log out</a></li>
{% else %} {% else %}
<li><a href="{{ url_for('auth.login') }}"><i class="material-icons">chevron_right</i>Log in</a></li> <li><a href="{{ url_for('auth.login') }}"><i class="material-icons">chevron_right</i>Log in</a></li>
<li><a href="{{ url_for('auth.register') }}"><i class="material-icons">chevron_right</i>Register</a></li>
{% endif %} {% endif %}
</ul> </ul>
<div id="nav-settings-dropdown" class="dropdown-content grey-text text-darken-4"> <div id="nav-settings-dropdown" class="dropdown-content grey-text text-darken-4">

Binary file not shown.