diff --git a/PasswordGenerator/forms.py b/PasswordGenerator/forms.py index 460c2eb..b220c77 100644 --- a/PasswordGenerator/forms.py +++ b/PasswordGenerator/forms.py @@ -10,3 +10,12 @@ class PasswordGenerationForm(FlaskForm): Punctuation_field = BooleanField("Punctuation") submit = SubmitField('Generate !') valid = False + +class PasswordGenerationFormRu(FlaskForm): + length = IntegerField('Длина (1-100(Числа))', validators = [DataRequired(),NumberRange(min=1,max=100)],default=10) + how_many_passwords = IntegerField('Как много паролей (1-20)',validators=[DataRequired(),NumberRange(min=1,max=20)],default=1) + Upper_register_field = BooleanField("Верхний регистр") + Digits_field = BooleanField("Цифры") + Punctuation_field = BooleanField("Пунктуация") + submit = SubmitField('Сгенерировать !') + valid = False \ No newline at end of file diff --git a/PasswordGenerator/main.py b/PasswordGenerator/main.py index 0da8e2f..1fe53a3 100644 --- a/PasswordGenerator/main.py +++ b/PasswordGenerator/main.py @@ -1,5 +1,5 @@ -from flask import Flask,render_template, request -from forms import PasswordGenerationForm +from flask import Flask,render_template, request,redirect,url_for +from forms import PasswordGenerationForm,PasswordGenerationFormRu from password_generator import generate @@ -7,8 +7,14 @@ application = Flask(__name__) application.config['SECRET_KEY'] = '' #Generate your own -@application.route("/", methods= ['POST','GET']) -def mainpage(): + +@application.route("/",methods=['POST','GET']) +def redir(): + return redirect(url_for('enpage'),code=302) + + +@application.route("/en", methods= ['POST','GET']) +def enpage(): form = PasswordGenerationForm() if form.validate_on_submit(): form.valid = True @@ -21,7 +27,24 @@ def mainpage(): else: form.valid = False print('Something went wrong') - return render_template("home.html", form = form) + return render_template("homeen.html", form = form) + + +@application.route("/ru", methods= ['POST','GET']) +def rupage(): + form = PasswordGenerationFormRu() + if form.validate_on_submit(): + form.valid = True + Checkbox_values = [{'checkbox':'Upper_reg','value':request.form.get('Upper_register_field')}, + {'checkbox':'Digits','value':request.form.get('Digits_field')}, + {'checkbox':'Punctuation','value':request.form.get('Punctuation_field')}] + len = int(request.form['length']) + how_many = int(request.form['how_many_passwords']) + form.password = generate(len,how_many=how_many,flags=Checkbox_values) + else: + form.valid = False + print('Something went wrong') + return render_template("homeru.html", form = form) @application.errorhandler(404) def not_found(error): @@ -30,4 +53,4 @@ def not_found(error): # Run Flask as Python script without any foreign commands if __name__ == '__main__': - application.run(debug = True) + application.run(debug = False) diff --git a/PasswordGenerator/password_generator.py b/PasswordGenerator/password_generator.py index f570c16..ad8944a 100644 --- a/PasswordGenerator/password_generator.py +++ b/PasswordGenerator/password_generator.py @@ -13,7 +13,7 @@ digits_pun = list(string.ascii_lowercase*10 + string.digits*10 + string.punctuat upp_pun = list(string.ascii_lowercase*10 + string.ascii_uppercase*10 +string.punctuation*5) -#Yeah, bad code, but couldn`t come up with a better idea +#Yeah, spaghetti code, but couldn`t come up with a better idea def generate(LEN,flags=None,how_many=None): passwords = [] U,D,P = None,None,None diff --git a/PasswordGenerator/static/styling.css b/PasswordGenerator/static/styling.css index 73d34c7..781d156 100644 --- a/PasswordGenerator/static/styling.css +++ b/PasswordGenerator/static/styling.css @@ -28,3 +28,6 @@ body{ width: 20px; height:20px; } +.langch{ + color:blue; +} \ No newline at end of file diff --git a/PasswordGenerator/templates/homeen.html b/PasswordGenerator/templates/homeen.html new file mode 100644 index 0000000..261ad15 --- /dev/null +++ b/PasswordGenerator/templates/homeen.html @@ -0,0 +1,52 @@ +{% extends "layout.html" %} + +{% block layout %} + Ru +