<s> from datetime import datetime <EOL> from wtforms import Form , TextField , PasswordField , HiddenField , ValidationError <EOL> from wtforms import validators as v <EOL> from models import User , authenticate <EOL> class RegistrationForm ( Form ) : <EOL> name = TextField ( validators = [ v . DataRequired ( ) , v . Length ( max = <NUM_LIT> ) ] ) <EOL> email = TextField ( validators = [ v . DataRequired ( ) , v . Email ( ) , v . Length ( max = <NUM_LIT> ) , v . Email ( ) ] ) <EOL> password = PasswordField ( validators = [ v . DataRequired ( ) , v . Length ( max = <NUM_LIT> ) ] ) <EOL> next = HiddenField ( ) <EOL> def validate_email ( form , field ) : <EOL> email = field . data . lower ( ) . strip ( ) <EOL> if ( User . objects ( email = email ) . count ( ) ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def save ( self ) : <EOL> user = User . create_user ( self . name . data , self . email . data , self . password . data , email_verified = True ) <EOL> user . save ( ) <EOL> return user <EOL> class LoginForm ( Form ) : <EOL> email = TextField ( u"<STR_LIT>" , validators = [ v . DataRequired ( ) , v . Email ( ) ] ) <EOL> password = PasswordField ( validators = [ v . DataRequired ( ) ] ) <EOL> next = HiddenField ( ) <EOL> def validate_email ( self , field ) : <EOL> if ( not User . objects ( email = field . data ) . count ( ) ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def validate_password ( self , field ) : <EOL> self . user_cache = authenticate ( email = self . email . data , password = field . data ) <EOL> if self . user_cache is None : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> elif not self . user_cache . is_email_activated : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> class ResetPasswordForm ( Form ) : <EOL> email = TextField ( u"<STR_LIT>" , validators = [ v . DataRequired ( ) , v . Email ( ) ] ) <EOL> def validate_email ( self , field ) : <EOL> email = field . data . lower ( ) . strip ( ) <EOL> if ( User . objects . filter ( email = email ) . count ( ) == <NUM_LIT:0> ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> field . data = email <EOL> return True <EOL> class NewPasswordForm ( Form ) : <EOL> password1 = PasswordField ( "<STR_LIT>" , validators = [ v . DataRequired ( ) ] ) <EOL> password2 = PasswordField ( "<STR_LIT>" , validators = [ v . DataRequired ( ) ] ) <EOL> def validate_password2 ( self , field ) : <EOL> password1 = self . password1 . data <EOL> password2 = self . password2 . data <EOL> if ( password1 != password2 ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> class ChangePasswordForm ( Form ) : <EOL> password = PasswordField ( "<STR_LIT>" , validators = [ v . DataRequired ( ) ] ) <EOL> password1 = PasswordField ( "<STR_LIT>" , validators = [ v . DataRequired ( ) ] ) <EOL> password2 = PasswordField ( "<STR_LIT>" , validators = [ v . DataRequired ( ) ] ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ChangePasswordForm , self ) . __init__ ( * args , ** kwargs ) <EOL> def validate_password ( self , field ) : <EOL> from flask_login import current_user <EOL> user_cache = authenticate ( email = current_user . email , password = field . data ) <EOL> if ( not user_cache ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def validate_password2 ( self , field ) : <EOL> password1 = self . password1 . data <EOL> password2 = self . password2 . data <EOL> if ( password1 != password2 ) : <EOL> raise ValidationError ( "<STR_LIT>" ) </s>
