Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified Classes and Forms #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .idea/UnilabPythonDevelopment.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 41 additions & 97 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 28 additions & 9 deletions Chapter12_User/Nina_Darsavelidze/FlaskLogin/myproject/forms.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
from flask_wtf import FlaskForm
from wtforms import StringField, IntegerField, SubmitField, PasswordField
from wtforms.fields.html5 import EmailField
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Email, EqualTo
from wtforms import ValidationError
from myproject.models import User


class UserRegistration(FlaskForm):
name = StringField('Name: ')
surname = StringField('Surname: ')
username = StringField('Username: ')
email = EmailField('Email: ')
password = PasswordField('Password: ')
name = StringField('Name: ', validators=[DataRequired()])
surname = StringField('Surname: ', validators=[DataRequired()])
username = StringField('Username: ', validators=[DataRequired(), Email()])
email = StringField('Email: ', validators=[DataRequired()])
password = PasswordField('Password',
validators=[DataRequired(), EqualTo('pass_confirm', message='Passwords Must Match!')])
pass_confirm = PasswordField('Confirm password', validators=[DataRequired()])
submit = SubmitField('Register!')

def validate_email(self, email):
if User.query.filter_by(email=self.email.data).first():
raise ValidationError('This email is already used by another user!')

def validate_username(self, username):
if User.query.filter_by(username=self.username.data).first():
raise ValidationError('This username is already used!')


class LoginForm(FlaskForm):
username = StringField('Username: ')
password = PasswordField('Password: ')
username = StringField('Username: ', validators=[DataRequired()])
password = StringField('Password: ', validators=[DataRequired()])
submit = SubmitField('Login')

def validate_password(self, password):
if not self.check_password:
raise ValidationError('Password is incorrect!')

Loading