From 9d49f5ef2967bf51ab2f46aa445b1321a7f5848a Mon Sep 17 00:00:00 2001 From: Unbewohnte <65883674+Unbewohnte@users.noreply.github.com> Date: Wed, 11 Nov 2020 05:57:56 +0300 Subject: [PATCH] Add files via upload --- PasswordGenerator/forms.py | 9 +++++ PasswordGenerator/main.py | 35 ++++++++++++++--- PasswordGenerator/password_generator.py | 2 +- PasswordGenerator/static/styling.css | 3 ++ PasswordGenerator/templates/homeen.html | 52 +++++++++++++++++++++++++ PasswordGenerator/templates/homeru.html | 52 +++++++++++++++++++++++++ 6 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 PasswordGenerator/templates/homeen.html create mode 100644 PasswordGenerator/templates/homeru.html 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 +
+

Password generator

+
+ {{ form.hidden_tag() }} + + +
+ {{form.length.label(class="form-control-label")}}
+ {{form.length(class="form-control-label")}}
+ + {% if form.length.errors %} +

Invalid value

+ {% endif %} + + {{form.how_many_passwords.label(class="form-control-label")}}
+ {{form.how_many_passwords(class="form-control-label")}}
+ + {% if form.how_many_passwords.errors %} +

Invalid value


+ {% endif %} + + {{ form.Upper_register_field.label}} + {{ form.Upper_register_field(class="check")}}
+ + {{ form.Digits_field.label }} + {{ form.Digits_field(class="check") }}
+ + {{ form.Punctuation_field.label}} + {{ form.Punctuation_field(class="check") }}
+ +
+ +
+ {{form.submit(class="btn btn-outline-info")}}
+
+
+
+ + {% if form.valid == True %} +
+

Generated passwords:


+ + {%for password in form.password%} +

{{password}}


+ {% endfor %} +
+ {% endif %} +{% endblock layout %} diff --git a/PasswordGenerator/templates/homeru.html b/PasswordGenerator/templates/homeru.html new file mode 100644 index 0000000..b562af9 --- /dev/null +++ b/PasswordGenerator/templates/homeru.html @@ -0,0 +1,52 @@ +{% extends "layout.html" %} + +{% block layout %} + En +
+

Генератор паролей

+
+ {{ form.hidden_tag() }} + + +
+ {{form.length.label(class="form-control-label")}}
+ {{form.length(class="form-control-label")}}
+ + {% if form.length.errors %} +

Invalid value

+ {% endif %} + + {{form.how_many_passwords.label(class="form-control-label")}}
+ {{form.how_many_passwords(class="form-control-label")}}
+ + {% if form.how_many_passwords.errors %} +

Invalid value


+ {% endif %} + + {{ form.Upper_register_field.label}} + {{ form.Upper_register_field(class="check")}}
+ + {{ form.Digits_field.label }} + {{ form.Digits_field(class="check") }}
+ + {{ form.Punctuation_field.label}} + {{ form.Punctuation_field(class="check") }}
+ +
+ +
+ {{form.submit(class="btn btn-outline-info")}}
+
+
+
+ + {% if form.valid == True %} +
+

Сгенерированные пароли:


+ + {%for password in form.password%} +

{{password}}


+ {% endfor %} +
+ {% endif %} +{% endblock layout %}