auth issue fix
This commit is contained in:
parent
3d146e87e7
commit
dc70b84446
75
app.py
75
app.py
@ -21,6 +21,9 @@ from flask_wtf.file import FileAllowed
|
|||||||
from flask_wtf.csrf import validate_csrf
|
from flask_wtf.csrf import validate_csrf
|
||||||
from wtforms import StringField, PasswordField, SubmitField, FileField,BooleanField, RadioField, SelectField, TextAreaField
|
from wtforms import StringField, PasswordField, SubmitField, FileField,BooleanField, RadioField, SelectField, TextAreaField
|
||||||
from wtforms.validators import DataRequired, Length, EqualTo, ValidationError, Regexp
|
from wtforms.validators import DataRequired, Length, EqualTo, ValidationError, Regexp
|
||||||
|
from wtforms import StringField, PasswordField, SubmitField
|
||||||
|
from wtforms.validators import DataRequired, EqualTo, Regexp
|
||||||
|
from flask_wtf import FlaskForm, RecaptchaField
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
csrf = CSRFProtect(app)
|
csrf = CSRFProtect(app)
|
||||||
@ -775,47 +778,6 @@ def user_pubs(pub_type, username):
|
|||||||
search_query=search_query
|
search_query=search_query
|
||||||
)
|
)
|
||||||
|
|
||||||
from wtforms import StringField, PasswordField, SubmitField
|
|
||||||
from wtforms.validators import DataRequired, EqualTo, Regexp
|
|
||||||
from flask_wtf import FlaskForm, RecaptchaField
|
|
||||||
|
|
||||||
class RegistrationForm(FlaskForm):
|
|
||||||
username = StringField(
|
|
||||||
'Username',
|
|
||||||
validators=[
|
|
||||||
DataRequired(),
|
|
||||||
Length(min=3, max=20),
|
|
||||||
Regexp(r'^[a-zA-Z0-9_]+$', message="Username can contain only letters, numbers, and underscores.")
|
|
||||||
]
|
|
||||||
)
|
|
||||||
password = PasswordField('Password', validators=[DataRequired(), Length(min=6)])
|
|
||||||
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')])
|
|
||||||
recaptcha = RecaptchaField()
|
|
||||||
submit = SubmitField('Register')
|
|
||||||
|
|
||||||
def validate_username(self, username):
|
|
||||||
user = User.query.filter_by(username=username.data).first()
|
|
||||||
if user:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not re.match(r'^[a-zA-Z0-9_]+$', username.data):
|
|
||||||
return
|
|
||||||
|
|
||||||
def validate_username(self, username):
|
|
||||||
username.data = username.data.lower()
|
|
||||||
user = User.query.filter_by(username=username.data).first()
|
|
||||||
if user:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not re.match(r'^[a-z0-9]+$', username.data):
|
|
||||||
return
|
|
||||||
|
|
||||||
def validate_ip(self):
|
|
||||||
ip_address = get_client_ip()
|
|
||||||
user_with_ip = User.query.filter_by(ip_address=ip_address).first()
|
|
||||||
if user_with_ip:
|
|
||||||
return
|
|
||||||
|
|
||||||
class LoginForm(FlaskForm):
|
class LoginForm(FlaskForm):
|
||||||
username = StringField('Username', validators=[DataRequired()])
|
username = StringField('Username', validators=[DataRequired()])
|
||||||
password = PasswordField('Password', validators=[DataRequired()])
|
password = PasswordField('Password', validators=[DataRequired()])
|
||||||
@ -831,6 +793,35 @@ def get_client_ip():
|
|||||||
|
|
||||||
return ip_address
|
return ip_address
|
||||||
|
|
||||||
|
class RegistrationForm(FlaskForm):
|
||||||
|
username = StringField(
|
||||||
|
'Username',
|
||||||
|
validators=[
|
||||||
|
DataRequired(),
|
||||||
|
Length(min=3, max=20),
|
||||||
|
Regexp(r'^[a-zA-Z0-9_]+$', message="Username can contain only letters, numbers, and underscores.")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
password = PasswordField('Password', validators=[DataRequired(), Length(min=6)])
|
||||||
|
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')])
|
||||||
|
recaptcha = RecaptchaField()
|
||||||
|
submit = SubmitField('Register')
|
||||||
|
|
||||||
|
def validate_username(self, username):
|
||||||
|
username.data = username.data.lower()
|
||||||
|
user = User.query.filter_by(username=username.data).first()
|
||||||
|
if user:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not re.match(r'^[a-z0-9]+$', username.data):
|
||||||
|
return
|
||||||
|
|
||||||
|
def validate_ip(self):
|
||||||
|
ip_address = get_client_ip()
|
||||||
|
user_with_ip = User.query.filter_by(ip_address=ip_address).first()
|
||||||
|
if user_with_ip:
|
||||||
|
return
|
||||||
|
|
||||||
@app.route('/register', methods=['GET', 'POST'])
|
@app.route('/register', methods=['GET', 'POST'])
|
||||||
def register():
|
def register():
|
||||||
form = RegistrationForm()
|
form = RegistrationForm()
|
||||||
@ -1605,4 +1596,4 @@ def buy_item(item_id):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
app.run(debug=False)
|
app.run(debug=True)
|
Loading…
x
Reference in New Issue
Block a user