-
Notifications
You must be signed in to change notification settings - Fork 12
33 reset user password #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bizmarcin
wants to merge
21
commits into
master
Choose a base branch
from
33_reset_user_password
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
acb7e00
copy changes from malsolec:32-add-email-address-to-db-and-display-in-…
bizmarcin a37328e
fix input data to tests
bizmarcin 2d74b45
add password recovery form template
bizmarcin bdcc86e
add reference between views login and pass_rec
bizmarcin a2622ef
chenge butons class in pass rec
bizmarcin 2a1056b
Merge branch '32_add_address_email_to_db_and_registration_display_val…
bizmarcin 973a417
check login&mail, message works in wrong way
bizmarcin 1826c5e
prepare method to check login and email, notification works in right way
bizmarcin ed734f5
add table pass_rec, prepare email content
bizmarcin 3b6b554
prepare view
bizmarcin 0f7160a
add recovery sha GET
bizmarcin 2bc84f4
Merge branch 'master' into 33_reset_user_password
bizmarcin d2545ec
prepare check and redirection to change password template
bizmarcin 2f36c5e
prepare flash messages
bizmarcin 7f497d4
change mechanism works fine, send email - still to do
bizmarcin 89626dc
add verification file email_test.txt
bizmarcin e4c3af1
test with SendGrid api
bizmarcin 3dc1335
add send mail mechanism
bizmarcin 5375cc6
Merge branch 'master' into 33_reset_user_password
bizmarcin 2d2eb71
add sendgrid to requirements.txt
bizmarcin b98cbd3
Merge branch '33_reset_user_password' of https://github.com/tgbdc7/ze…
bizmarcin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,4 @@ db.sqlite | |
| node_modules/ | ||
| .coverage | ||
| tests/TODO.txt | ||
| email_test.txt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ werkzeug | |
| Flask | ||
| pytest | ||
| lxml | ||
| sendgrid | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # using SendGrid's Python Library | ||
| # https://github.com/sendgrid/sendgrid-python | ||
|
|
||
| import os | ||
| from sendgrid import SendGridAPIClient | ||
| from sendgrid.helpers.mail import Mail | ||
|
|
||
| def is_pass_rec_email(mail,sha): | ||
| message = Mail( | ||
| from_email='zeton@zeton.com', #fix me in this place should be registred sender mail | ||
| to_emails=mail, | ||
| subject='Sending with Twilio SendGrid is Fun', | ||
| html_content=f'<strong>Poniżej znajdziesz link do resetu hasła:</strong><br>http://127.0.0.1:5000/pass_rec/{sha}') #fix me destination domain | ||
| try: | ||
| sg = SendGridAPIClient('SG. ...') #fix me in this place should be registred api key | ||
|
|
||
| response = sg.send(message) | ||
| print(response.status_code) | ||
| print(response.body) | ||
| print(response.headers) | ||
| except Exception as e: | ||
| print(str(e)) | ||
| return False | ||
|
|
||
| return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| import datetime | ||
| from flask import session, g | ||
|
|
||
| from zeton.data_access.bans import check_bans_status | ||
| from zeton.data_access.points import get_child_points | ||
|
|
||
| from zeton.db import get_db | ||
|
|
||
|
|
||
|
|
@@ -103,6 +102,56 @@ def get_user_id(username): | |
| return row['id'] | ||
| return False | ||
|
|
||
| def get_user_name_pass_recovery_sha(sha): | ||
| query = f"select * from pass_rec where expire > '{datetime.datetime.now()}' and sha='{sha}'" | ||
| result = get_db().execute(query) | ||
| row = result.fetchone() | ||
| if row!=None: | ||
| return row['username'] | ||
| else: | ||
| return None | ||
|
|
||
| def pass_rec(username, email, sha, expire): | ||
| query = f"select * from pass_rec where expire > '{datetime.datetime.now()}' and username='{username}'" | ||
| result = get_db().execute(query) | ||
| rows = result.fetchall() | ||
| rows_count = rows.__len__() | ||
| if rows_count > 0: | ||
| check_old = False | ||
| else: | ||
| check_old = True | ||
| if check_old: | ||
| query = "INSERT INTO 'pass_rec' " \ | ||
| "(username, email, sha, expire) " \ | ||
| f"VALUES ('{username}', '{email}', '{sha}', '{expire}') " | ||
|
|
||
| get_db().execute(query) | ||
| get_db().commit() | ||
| return "Sprawdz skrzynkę pocztową w celu odzyskania hasła" | ||
| else: | ||
| return "Poprzedni link jeszcze nie wygasł, sprawdź stare maile i spam" | ||
|
|
||
| def check_pass_rec(username, sha): | ||
| query = f"select * from pass_rec where expire > '{datetime.datetime.now()}' and username='{username}'" | ||
| result = get_db().execute(query) | ||
| rows = result.fetchone() | ||
| rows_count = rows.__len__() | ||
| if rows_count == 1: | ||
| check = True | ||
| else: | ||
| check = False | ||
| return check | ||
|
|
||
| def get_email_address(email): | ||
| query = """ | ||
| SELECT email FROM users | ||
| WHERE email = ? | ||
| """ | ||
| result = get_db().execute(query, (email,)) | ||
| row = result.fetchone() | ||
| if row: | ||
| return row['email'] | ||
| return False | ||
|
|
||
| def get_email_address(email): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zduplikowana funkcja |
||
| query = """ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| {% extends "base/base.html" %} | ||
| {% block head %} | ||
| {{ super() }} | ||
| {% block password %} | ||
| <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> | ||
| {% endblock password %} | ||
| {% endblock head %} | ||
|
|
||
| {% block content %} | ||
| <div class="col col-sm-5"> | ||
| <form action="/pass_rec" method="POST"> | ||
|
|
||
| <h2>Odzyskiwanie hasła użytkownika</h2> | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brakuje flashowania z errorem, kiedy podany email jest błędny. |
||
| {% block add_person %}{% endblock add_person %} | ||
| <div class="form-group"> | ||
| <label>Nazwa użytkownika:</label> | ||
| <input class="form-control" type="text" name="username" placeholder="Nazwa użytkownika" required> | ||
| </div> | ||
| <div class="form-group"> | ||
| <label>Adres email:</label> | ||
| <input class="form-control" type="email" name="email" placeholder="Adres email" required> | ||
| </div> | ||
| <div class="form-group button"> | ||
| <a href="/" class="button-add">Powrót</a> | ||
| <button type="submit" class="button-switch">Odzyskaj hasło</button> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| {% endblock content %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| {% extends "base/base.html" %} | ||
| {% block content %} | ||
|
|
||
| <div class="col col-sm-6"> | ||
|
|
||
| <div class="text-center"> | ||
| <h2>{{ user_data.firstname }}</h2> | ||
|
|
||
| {% if messages %} | ||
| <div class="alert alert-dark">{{ messages[0] }}</div> | ||
| {% endif %} | ||
| <form action="/api/settings/set_new_password/{{ user_data.id }}/{{ sha }}" method="post"> | ||
| <div class="form-group"> | ||
| <label for="inputPassword2">Wpisz nowe hasło </label> | ||
| <br> | ||
| <input type="password" class="form-control" name="new_password" id="inputPassword2" | ||
| placeholder="Nowe hasło"> | ||
| </div> | ||
| <div class="form-group"> | ||
| <label for="inputPassword3">Powtórz nowe hasło </label> | ||
| <br> | ||
| <input type="password" class="form-control" name="repeat_new_password" id="inputPassword3" | ||
| placeholder="Powtórz nowe hasło"> | ||
| </div> | ||
| <br> | ||
| <div class="form-group button"> | ||
| <button type="submit" class="btn btn-info">Prześlij</button> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
|
|
||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proponuję zmienić komunikat na polski