auth issue fix
This commit is contained in:
parent
3d146e87e7
commit
dc70b84446
45
app.py
45
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,9 +778,20 @@ def user_pubs(pub_type, username):
|
|||||||
search_query=search_query
|
search_query=search_query
|
||||||
)
|
)
|
||||||
|
|
||||||
from wtforms import StringField, PasswordField, SubmitField
|
class LoginForm(FlaskForm):
|
||||||
from wtforms.validators import DataRequired, EqualTo, Regexp
|
username = StringField('Username', validators=[DataRequired()])
|
||||||
from flask_wtf import FlaskForm, RecaptchaField
|
password = PasswordField('Password', validators=[DataRequired()])
|
||||||
|
recaptcha = RecaptchaField()
|
||||||
|
submit = SubmitField('Login')
|
||||||
|
|
||||||
|
def get_client_ip():
|
||||||
|
if 'X-Forwarded-For' in request.headers:
|
||||||
|
forwarded_for = request.headers['X-Forwarded-For']
|
||||||
|
ip_address = forwarded_for.split(',')[0]
|
||||||
|
else:
|
||||||
|
ip_address = request.remote_addr
|
||||||
|
|
||||||
|
return ip_address
|
||||||
|
|
||||||
class RegistrationForm(FlaskForm):
|
class RegistrationForm(FlaskForm):
|
||||||
username = StringField(
|
username = StringField(
|
||||||
@ -793,14 +807,6 @@ class RegistrationForm(FlaskForm):
|
|||||||
recaptcha = RecaptchaField()
|
recaptcha = RecaptchaField()
|
||||||
submit = SubmitField('Register')
|
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):
|
def validate_username(self, username):
|
||||||
username.data = username.data.lower()
|
username.data = username.data.lower()
|
||||||
user = User.query.filter_by(username=username.data).first()
|
user = User.query.filter_by(username=username.data).first()
|
||||||
@ -816,21 +822,6 @@ class RegistrationForm(FlaskForm):
|
|||||||
if user_with_ip:
|
if user_with_ip:
|
||||||
return
|
return
|
||||||
|
|
||||||
class LoginForm(FlaskForm):
|
|
||||||
username = StringField('Username', validators=[DataRequired()])
|
|
||||||
password = PasswordField('Password', validators=[DataRequired()])
|
|
||||||
recaptcha = RecaptchaField()
|
|
||||||
submit = SubmitField('Login')
|
|
||||||
|
|
||||||
def get_client_ip():
|
|
||||||
if 'X-Forwarded-For' in request.headers:
|
|
||||||
forwarded_for = request.headers['X-Forwarded-For']
|
|
||||||
ip_address = forwarded_for.split(',')[0]
|
|
||||||
else:
|
|
||||||
ip_address = request.remote_addr
|
|
||||||
|
|
||||||
return ip_address
|
|
||||||
|
|
||||||
@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