Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
username = wtforms.TextField(validators=[validators.Required(message='Required')])
password = wtforms.PasswordField(validators=[validators.Required(message='Required')])
def validate(self):
if not super(LoginForm, self).validate():
return False
username, password = self.username.data, self.password.data
self.user = authenticate(username, password)
if self.user is None:
self.errors['__all__'] = ['Invalid login']
return self.user is not None
class EditUserForm(wtforms.Form):
username = wtforms.TextField()
password = wtforms.PasswordField(validators=[validators.Length(min=8, message='Too short')])
confirm = wtforms.PasswordField(validators=[validators.EqualTo('password', 'Password mismatch')])
first_name = wtforms.TextField()
last_name = wtforms.TextField()
email = wtforms.TextField()
@app.before_request
def check_csrf():
if 'csrf' not in request.cookies:
g.csrf = randstring()
else:
g.csrf = request.cookies['csrf']
if request.method not in ('HEAD', 'GET'):
dom_dorm = StringField('原宿舍号')
# 学历证明
school = SelectField('所在校区',choices=[('','请输入你所在的校区'),('龙子湖校区','龙子湖校区'),('北林校区','北林校区'),('英才校区','英才校区')])
campus = StringField('所在院系')
code = StringField('证书编号')
identity = StringField('身份证号码')
leng_school = SelectField('学制',choices=[('四年制','四年制'),('三年制','三年制'),('二年制','二年制')])
discipline = StringField('专业')
# new_dorm = StringField('原宿舍号')
Submit = SubmitField('提交')
class EditTeacher(FlaskForm):
old_password = PasswordField('Old Password')
new_password = PasswordField('New Password')
repeat_password = PasswordField('Repeat Password')
Submit = SubmitField('确认修改')
# 上传表单
class UploadForm(FlaskForm):
file = FileField('上传', validators=[FileRequired(), FileAllowed(['xls'])])
submit = SubmitField()
# pste is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pste. If not, see .
from flask_wtf import FlaskForm
from wtforms import PasswordField, SubmitField, validators
from wtforms.fields.html5 import EmailField
class RegistrationForm(FlaskForm):
email = EmailField('Email', [validators.Email()])
password = PasswordField('Password', [
validators.DataRequired(message='Password is required.'),
validators.EqualTo('confirm', message='Passwords must match.'),
validators.Length(message='Password must be at least 6 characters long.', min=6)
])
confirm = PasswordField('Confirm password')
submit = SubmitField('Register')
class LoginForm(FlaskForm):
email = EmailField('Email', validators=[validators.Email()])
password = PasswordField('Password', validators=[validators.DataRequired(message='Password is required.')])
submit = SubmitField('Sign in')
from config import TRACKER_PASSWORD_LENGTH_MAX
from config import TRACKER_PASSWORD_LENGTH_MIN
from tracker.model.enum import UserRole
from tracker.model.user import User
from tracker.model.user import username_regex
from .base import BaseForm
ERROR_USERNAME_EXISTS = 'Username already exists.'
ERROR_EMAIL_EXISTS = 'E-Mail already exists.'
class UserForm(BaseForm):
username = StringField(u'Username', validators=[DataRequired(), Length(max=User.NAME_LENGTH), Regexp(username_regex)])
email = EmailField(u'E-Mail', validators=[DataRequired(), Length(max=User.EMAIL_LENGTH), Email()])
password = PasswordField(u'Password', validators=[Optional(), Length(min=TRACKER_PASSWORD_LENGTH_MIN, max=TRACKER_PASSWORD_LENGTH_MAX)])
role = SelectField(u'Role', choices=[(e.name, e.label) for e in [*UserRole]], default=UserRole.reporter.name, validators=[DataRequired()])
active = BooleanField(u'Active', default=True)
random_password = BooleanField(u'Randomize password', default=False)
submit = SubmitField(u'submit')
def __init__(self, edit=False):
super().__init__()
self.edit = edit
def validate(self):
rv = BaseForm.validate(self)
if not rv:
return False
if self.username.data in self.password.data:
self.password.errors.append('Password must not contain the username.')
team_enable = BooleanField('允许组队')
upload_enable = BooleanField('开放上传')
hide = BooleanField('隐藏显示')
button = SubmitField('提交')
def getChoices():
return list((o.activity_name, o.activity_name) for o in Activities.query.all())
class ActChosen(Form):
act = SelectField('活动', choices=[])
button = SubmitField('提交')
class LoginAdmin(Form):
user = StringField('用户名', [validators.required()])
passwd = PasswordField('密码', [validators.required()])
button = SubmitField('提交')
status = IntegerField('Status')
class RegisterForm(Form):
name = StringField(
'Username',
validators=[DataRequired(), Length(min=6, max=25)]
)
email = StringField(
'Email',
validators=[DataRequired(), Length(min=6, max=40)]
)
password = PasswordField(
'Password',
validators=[DataRequired(), Length(min=6, max=40)])
confirm = PasswordField(
'Repeat Password',
validators=[DataRequired(), EqualTo('password', message='Passwords must match')]
)
class LoginForm(Form):
name = StringField(
'Username',
validators=[DataRequired()]
)
password = PasswordField(
'Password',
validators=[DataRequired()]
)
'an existing account')
],
'password': [
Required(),
Length(min=6, max=50),
EqualTo('confirm', message='Passwords must match'),
Regexp(r'[A-Za-z0-9@#$%^&+=]',
message='Password contains invalid characters')
]
}
class RegisterForm(Form):
email = TextField('Email', validators['email'])
password = PasswordField('Password', validators['password'], )
confirm = PasswordField('Confirm Password')
from wtforms.validators import DataRequired
from wtforms.validators import Length
from config import TRACKER_PASSWORD_LENGTH_MAX
from config import TRACKER_PASSWORD_LENGTH_MIN
from tracker.user import hash_password
from .base import BaseForm
ERROR_PASSWORD_CONTAINS_USERNAME = 'Password must not contain the username.'
ERROR_PASSWORD_REPEAT_MISMATCHES = 'Repeated password mismatches.'
ERROR_PASSWORD_INCORRECT = 'Current password incorrect.'
class UserPasswordForm(BaseForm):
password = PasswordField(u'New Password', validators=[DataRequired(), Length(min=TRACKER_PASSWORD_LENGTH_MIN, max=TRACKER_PASSWORD_LENGTH_MAX)])
password_repeat = PasswordField(u'Repeat Password', validators=[DataRequired(), Length(min=TRACKER_PASSWORD_LENGTH_MIN, max=TRACKER_PASSWORD_LENGTH_MAX)])
password_current = PasswordField(u'Current Password', validators=[DataRequired(), Length(min=TRACKER_PASSWORD_LENGTH_MIN, max=TRACKER_PASSWORD_LENGTH_MAX)])
submit = SubmitField(u'submit')
def __init__(self, edit=False):
super().__init__()
def validate(self):
rv = BaseForm.validate(self)
if not rv:
return False
if current_user.name in self.password.data:
self.password.errors.append(ERROR_PASSWORD_CONTAINS_USERNAME)
return False
def login(self):
login_form = wtforms.form.BaseForm(())
login_form['username'] = wtforms.TextField("Username")
login_form['password'] = wtforms.PasswordField("Password")
login_form['username'].data = ''
if request.method == 'POST':
login_form.process(request.form)
if login_form.validate():
# login and validate the user...
login = login_form['username'].data
password = login_form['password'].data
try:
u = self.do_user_login(login, password)
login_user(u)
flash("Logged in successfully.")
return redirect(request.args.get("next") or "/")
except:
flash("Username or password incorrect, try again.")
email = TextField('Your email', validators=[Required()])
#################################
# PASSWORD FORM FOR RESET PAGE #
#################################
class PasswordForm(Form):
password = PasswordField('New password', [
validators.Required(),
validators.EqualTo(
'confirm',
message="Passwords must match")
])
confirm = PasswordField('Confirm new password', validators=[Required()])
###################################
# PASSWORD FORM FOR USER SETTINGS #
###################################
class PasswordFormSettings(Form):
current_password = PasswordField('Current password',
validators=[Required()])
new_password = PasswordField('New password',
[validators.Required(),
validators.EqualTo(
'confirm',
message="Passwords must match")