Skip to content

Commit

Permalink
Merge pull request #5 from greyli/enhancements
Browse files Browse the repository at this point in the history
Simplify registeration flow
  • Loading branch information
greyli authored Sep 9, 2024
2 parents 1a3ff9e + 45ba82d commit a2a72f5
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 51 deletions.
3 changes: 2 additions & 1 deletion moments/blueprints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def register():
user = User(name=name, email=email, username=username, password=password)
db.session.add(user)
db.session.commit()
login_user(user)
token = generate_token(user=user, operation=Operations.CONFIRM)
send_confirmation_email(user=user, token=token)
flash('Confirm email sent, check your inbox.', 'info')
return redirect(url_for('.login'))
return redirect(url_for('main.index'))
return render_template('auth/register.html', form=form)


Expand Down
4 changes: 1 addition & 3 deletions moments/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from moments.core.extensions import db
from moments.models import Role
from moments.lorem import fake_admin, fake_collect, fake_comment, fake_follow, fake_photo, fake_tag, fake_user


def register_commands(app):
Expand Down Expand Up @@ -34,9 +35,6 @@ def init_app_command():
@click.option('--comment', default=100, help='Quantity of comments, default is 100.')
def lorem_command(user, follow, photo, tag, collect, comment):
"""Generate fake data."""

from moments.lorem import fake_admin, fake_collect, fake_comment, fake_follow, fake_photo, fake_tag, fake_user

db.drop_all()
db.create_all()

Expand Down
6 changes: 3 additions & 3 deletions moments/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def decorated_function(*args, **kwargs):
if not current_user.confirmed:
resend_url = url_for('auth.resend_confirmation_email')
message = Markup(
'Please confirm your account first.'
'Not receive the email?'
f'<a class="alert-link" href="{resend_url}">Resend Confirm Email</a>'
'Please confirm your account first. '
'Didn\'t receive the email? '
f'<a class="alert-link" href="{resend_url}">Resend Confirmation Email</a>'
)
flash(message, 'warning')
return redirect(url_for('main.index'))
Expand Down
22 changes: 11 additions & 11 deletions moments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
from moments.core.extensions import db, whooshee


# enbale foreign key support for SQLite
@event.listens_for(engine.Engine, 'connect')
def set_sqlite_pragma(dbapi_connection, connection_record):
import sqlite3

if isinstance(dbapi_connection, sqlite3.Connection):
cursor = dbapi_connection.cursor()
cursor.execute('PRAGMA foreign_keys=ON')
cursor.close()


role_permission = db.Table(
'role_permission',
Column('role_id', ForeignKey('role.id', ondelete='CASCADE'), primary_key=True),
Expand Down Expand Up @@ -374,6 +363,17 @@ def __repr__(self):
return f'Notification {self.id}: {self.message}'


# enbale foreign key support for SQLite
@event.listens_for(engine.Engine, 'connect')
def set_sqlite_pragma(dbapi_connection, connection_record):
import sqlite3

if isinstance(dbapi_connection, sqlite3.Connection):
cursor = dbapi_connection.cursor()
cursor.execute('PRAGMA foreign_keys=ON')
cursor.close()


@event.listens_for(User, 'after_delete', named=True)
def delete_avatars(**kwargs):
target = kwargs['target']
Expand Down
28 changes: 7 additions & 21 deletions moments/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ document.addEventListener('DOMContentLoaded', () => {
.then(data => {
elem.textContent = data.count;
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function updateCollectorsCount(id) {
Expand All @@ -95,9 +93,7 @@ document.addEventListener('DOMContentLoaded', () => {
.then(data => {
elem.textContent = data.count;
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function updateNotificationsCount() {
Expand All @@ -115,9 +111,7 @@ document.addEventListener('DOMContentLoaded', () => {
elem.textContent = data.count;
}
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function follow(event) {
Expand All @@ -136,9 +130,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateFollowersCount(id);
toast(data.message);
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function unfollow(event) {
Expand All @@ -157,9 +149,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateFollowersCount(id);
toast(data.message);
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function collect(event) {
Expand All @@ -181,9 +171,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateCollectorsCount(id);
toast(data.message);
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function uncollect(event) {
Expand All @@ -205,9 +193,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateCollectorsCount(id);
toast(data.message);
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

dayjs.extend(window.dayjs_plugin_relativeTime)
Expand Down
23 changes: 17 additions & 6 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencies = [
"flask-avatars>=0.2.3",
"pyjwt>=2.8.0",
"email-validator>=2.1.0.post1",
"selenium>=4.18.1",
]
requires-python = ">=3.8"
readme = "README.md"
Expand All @@ -39,8 +38,7 @@ dev = [
"watchdog>=4.0.0",
"ruff>=0.4.10",
"pre-commit>=3.5.0",
]
test = [
"selenium>=4.24.0",
"pytest>=8.1.1",
]

Expand Down
9 changes: 6 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ ruff==0.4.10 \
--hash=sha256:d8f71885bce242da344989cae08e263de29752f094233f932d4f5cfb4ef36a81 \
--hash=sha256:dd1fcee327c20addac7916ca4e2653fbbf2e8388d8a6477ce5b4e986b68ae6c0 \
--hash=sha256:ffe3cd2f89cb54561c62e5fa20e8f182c0a444934bf430515a4b422f1ab7b7ca
selenium==4.18.1 \
--hash=sha256:a11f67afa8bfac6b77e148c987b33f6b14eb1cae4d352722a75de1f26e3f0ae2 \
--hash=sha256:b24a3cdd2d47c29832e81345bfcde0c12bb608738013e53c781b211b418df241
selenium==4.24.0 \
--hash=sha256:42c23f60753d5415b261b236cecbd69bd4eb5271e1563915f546b443cb6b71c6 \
--hash=sha256:88281e5b5b90fe231868905d5ea745b9ee5e30db280b33498cc73fb0fa06d571
six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
Expand Down Expand Up @@ -387,6 +387,9 @@ watchdog==4.0.0 \
--hash=sha256:e3e7065cbdabe6183ab82199d7a4f6b3ba0a438c5a512a68559846ccb76a78ec \
--hash=sha256:f970663fa4f7e80401a7b0cbeec00fa801bf0287d93d48368fc3e6fa32716245 \
--hash=sha256:f9b2fdca47dc855516b2d66eef3c39f2672cbf7e7a42e7e67ad2cbfcd6ba107d
websocket-client==1.8.0 \
--hash=sha256:17b44cc997f5c498e809b22cdf2d9c7a9e71c02c8cc2b6c56e7c2d1239bfa526 \
--hash=sha256:3239df9f44da632f96012472805d40a23281a991027ce11d2f45a6f24ac4c3da
Werkzeug==3.0.1 \
--hash=sha256:507e811ecea72b18a404947aded4b3390e1db8f826b494d76550ef45bb3b1dcc \
--hash=sha256:90a285dc0e42ad56b34e696398b8122ee4c681833fb35b8334a095d82c56da10
Expand Down

0 comments on commit a2a72f5

Please sign in to comment.