Skip to content
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

feat: Add registration page #286

Merged
merged 31 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2cf26ed
feat: Add registration page
orronai Sep 9, 2021
3913a5e
feat: Add registration page
orronai Sep 10, 2021
d206c6a
Fixed sourcey-ai issues
orronai Sep 10, 2021
6ad4d4d
fixed resend email confirmation
orronai Sep 10, 2021
5acbda2
Merge branch 'master' of https://github.com/PythonFreeCourse/lms into…
orronai Sep 11, 2021
6b137af
Added translations
orronai Sep 11, 2021
3798a2d
Removed unused module
orronai Sep 11, 2021
1377e9a
Changed versions of requirements
orronai Sep 11, 2021
93da860
Changed versions of requirements
orronai Sep 11, 2021
ec52300
Changed versions of requirements
orronai Sep 11, 2021
4e47d57
Changed versions of requirements
orronai Sep 11, 2021
8d08863
Changed versions of requirements
orronai Sep 11, 2021
366b53f
Changed versions of requirements
orronai Sep 11, 2021
1443bad
Removed versions change
orronai Sep 11, 2021
1d00a27
Fixed tests
orronai Sep 11, 2021
036bdf5
Fixed a test
orronai Sep 11, 2021
b426102
Fixed test and updated client fixture
orronai Sep 11, 2021
c2ffa37
Added tests for coverage
orronai Sep 11, 2021
a9c22c9
Merge branch 'master' into add-signup-page
orronai Sep 11, 2021
b8dff02
- Changed role name from not_confirmed into unverified
orronai Sep 11, 2021
2da74c3
Fixed conflict
orronai Sep 11, 2021
fda1558
Added a test for signature expired
orronai Sep 11, 2021
6ad81a2
Removed unnecessary condition
orronai Sep 11, 2021
eb717f1
Added role attribute
orronai Sep 11, 2021
7e87dad
- Fixed babel translations
orronai Sep 12, 2021
19ecb65
Fixed a test to check bad signature token
orronai Sep 12, 2021
71fbb2f
Fixed a test
orronai Sep 12, 2021
d4bd32a
Moved out the HASHED_PASSWORD in order to be global variable, and add…
orronai Sep 12, 2021
436fc9f
Added a configuration of registration open, and a test
orronai Sep 12, 2021
d34d19d
Added flask limits and fixed some messages
orronai Sep 14, 2021
f44f1a2
Removed formats from strings
orronai Sep 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lms/lmsdb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

class RoleOptions(enum.Enum):
BANNED = 'Banned'
UNVERIFIED = 'Unverified'
STUDENT = 'Student'
STAFF = 'Staff'
VIEWER = 'Viewer'
Expand Down Expand Up @@ -67,6 +68,7 @@ class Role(BaseModel):
(RoleOptions.STAFF.value, RoleOptions.STAFF.value),
(RoleOptions.VIEWER.value, RoleOptions.VIEWER.value),
(RoleOptions.STUDENT.value, RoleOptions.STUDENT.value),
(RoleOptions.UNVERIFIED.value, RoleOptions.UNVERIFIED.value),
(RoleOptions.BANNED.value, RoleOptions.BANNED.value),
))

Expand All @@ -77,6 +79,10 @@ def __str__(self):
def get_banned_role(cls) -> 'Role':
return cls.get(Role.name == RoleOptions.BANNED.value)

@classmethod
def get_unverified_role(cls) -> 'Role':
return cls.get(Role.name == RoleOptions.UNVERIFIED.value)

@classmethod
def get_student_role(cls) -> 'Role':
return cls.get(Role.name == RoleOptions.STUDENT.value)
Expand All @@ -100,6 +106,10 @@ def by_name(cls, name) -> 'Role':
def is_banned(self) -> bool:
return self.name == RoleOptions.BANNED.value

@property
def is_unverified(self) -> bool:
return self.name == RoleOptions.UNVERIFIED.value

@property
def is_student(self) -> bool:
return self.name == RoleOptions.STUDENT.value
Expand Down Expand Up @@ -407,8 +417,7 @@ def set_state(self, new_state: SolutionState, **kwargs) -> bool:
**{Solution.state.name: new_state.name},
**kwargs,
).where(requested_solution)
updated = changes.execute() == 1
return updated
return changes.execute() == 1

def ordered_versions(self) -> Iterable['Solution']:
return Solution.select().where(
Expand Down
3 changes: 3 additions & 0 deletions lms/lmsweb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from flask_babel import Babel # type: ignore
from flask_limiter import Limiter # type: ignore
from flask_limiter.util import get_remote_address # type: ignore
from flask_mail import Mail # type: ignore
from flask_wtf.csrf import CSRFProtect # type: ignore

from lms.utils import config_migrator, debug
Expand Down Expand Up @@ -41,6 +42,8 @@
# Localizing configurations
babel = Babel(webapp)

webmail = Mail(webapp)


# Must import files after app's creation
from lms.lmsdb import models # NOQA: F401, E402, I202
Expand Down
14 changes: 14 additions & 0 deletions lms/lmsweb/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ SECRET_KEY = ''
MAILGUN_API_KEY = os.getenv('MAILGUN_API_KEY')
MAILGUN_DOMAIN = os.getenv('MAILGUN_DOMAIN', 'mail.pythonic.guru')
SERVER_ADDRESS = os.getenv('SERVER_ADDRESS', '127.0.0.1:5000')
SITE_NAME = 'Learning Python'

# REGISTRATION CONFIGURATIONS
REGISTRATION_OPEN = True
CONFIRMATION_TIME = 3600

# MAIL CONFIGURATION
MAIL_SERVER = 'smtp.gmail.com'
MAIL_PORT = 465
MAIL_USE_SSL = True
MAIL_USE_TLS = False
MAIL_USERNAME = 'username@gmail.com'
MAIL_PASSWORD = 'password'
MAIL_DEFAULT_SENDER = 'username@gmail.com'

# ADMIN PANEL
FLASK_ADMIN_FLUID_LAYOUT = True
Expand Down
34 changes: 34 additions & 0 deletions lms/lmsweb/forms/register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from flask_babel import gettext as _ # type: ignore
from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField
from wtforms.validators import Email, EqualTo, InputRequired, Length

from lms.lmsweb.tools.validators import (
UniqueEmailRequired, UniqueUsernameRequired,
)


class RegisterForm(FlaskForm):
email = StringField(
'Email', validators=[
InputRequired(), Email(message=_('אימייל לא תקין')),
UniqueEmailRequired,
],
)
username = StringField(
'Username', validators=[
InputRequired(), UniqueUsernameRequired, Length(min=4, max=20),
],
)
fullname = StringField(
'Full Name', validators=[InputRequired(), Length(min=3, max=60)],
)
password = PasswordField(
'Password', validators=[InputRequired(), Length(min=8)], id='password',
)
confirm = PasswordField(
'Password Confirmation', validators=[
InputRequired(),
EqualTo('password', message=_('הסיסמאות שהוקלדו אינן זהות')),
],
)
21 changes: 21 additions & 0 deletions lms/lmsweb/tools/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from flask_babel import gettext as _ # type: ignore
from wtforms.fields.core import StringField
from wtforms.validators import ValidationError

from lms.lmsdb.models import User


def UniqueUsernameRequired(
_form: 'RegisterForm', field: StringField, # type: ignore # NOQA: F821
) -> None:
username_exists = User.get_or_none(User.username == field.data)
if username_exists:
raise ValidationError(_('שם המשתמש כבר נמצא בשימוש'))


def UniqueEmailRequired(
_form: 'RegisterForm', field: StringField, # type: ignore # NOQA: F821
) -> None:
email_exists = User.get_or_none(User.mail_address == field.data)
if email_exists:
raise ValidationError(_('האימייל כבר נמצא בשימוש'))
orronai marked this conversation as resolved.
Show resolved Hide resolved
121 changes: 100 additions & 21 deletions lms/lmsweb/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lmsweb-1.0\n"
"Report-Msgid-Bugs-To: bugs@mesicka.com\n"
"POT-Creation-Date: 2020-10-09 11:20+0300\n"
"POT-Creation-Date: 2021-09-12 15:10+0300\n"
"PO-Revision-Date: 2020-09-16 18:29+0300\n"
"Last-Translator: Or Ronai\n"
"Language: en\n"
Expand All @@ -16,9 +16,9 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.8.0\n"
"Generated-By: Babel 2.9.1\n"

#: lmsdb/models.py:632
#: lmsdb/models.py:698
msgid "כישלון חמור"
msgstr "Fatal error"

Expand All @@ -45,26 +45,79 @@ msgstr "The automatic checker couldn't run your code."
msgid "אחי, בדקת את הקוד שלך?"
msgstr "Bro, did you check your code?"

#: lmsweb/views.py:122
msgid "לא ניתן להירשם כעת"
msgstr "Can not register now"

#: lmsweb/views.py:139
msgid "ההרשמה בוצעה בהצלחה"
msgstr "Registration successfully"

#: lmsweb/views.py:161
msgid "קישור האימות פג תוקף, קישור חדש נשלח אל תיבת המייל שלך"
msgstr "The confirmation link is expired, new link has been sent to your email"

#: lmsweb/views.py:174
#, fuzzy
msgid "המשתמש שלך אומת בהצלחה, כעת אתה יכול להתחבר למערכת"
msgstr "Your user has been successfully confirmed, you can now login"

#: lmsweb/forms/register.py:14
msgid "אימייל לא תקין"
msgstr "Invalid email"

#: lmsweb/forms/register.py:32
msgid "הסיסמאות שהוקלדו אינן זהות"
msgstr "The passwords are not identical"

#: lmsweb/tools/registration.py:105
msgid "מערכת הגשת התרגילים"
msgstr "Exercuse submission system"

#: models/solutions.py:46
#: lmsweb/tools/validators.py:13
msgid "שם המשתמש כבר נמצא בשימוש"
msgstr "The username already in use"

#: lmsweb/tools/validators.py:21
msgid "האימייל כבר נמצא בשימוש"
msgstr "The email already in use"

#: models/register.py:20
#, python-format
msgid "מייל אימות - %(site_name)s"
msgstr "Confirmation mail - %(site_name)s"

#: models/register.py:25
#, fuzzy, python-format
msgid "שלום %(fullname)s,\nלינק האימות שלך למערכת הוא: %(link)s"
msgstr "Hello %(fullname)s,\n Your confirmation link is: %(link)s"

#: models/solutions.py:50
#, python-format
msgid "%(solver)s הגיב לך על בדיקת תרגיל \"%(subject)s\"."
msgstr "%(solver)s has replied for your \"%(subject)s\" check."

#: models/solutions.py:53
#: models/solutions.py:57
#, python-format
msgid "%(checker)s הגיב לך על תרגיל \"%(subject)s\"."
msgstr "%(checker)s replied for \"%(subject)s\"."

#: models/solutions.py:65
#: models/solutions.py:69
#, python-format
msgid "הפתרון שלך לתרגיל \"%(subject)s\" נבדק."
msgstr "Your solution for the \"%(subject)s\" exercise has been checked."

#: templates/banned.html:8 templates/login.html:7
#: models/users.py:25
#, fuzzy
msgid "שם המשתמש או הסיסמה שהוזנו לא תקינים"
msgstr "Invalid username or password"

#: models/users.py:27
#, fuzzy
msgid "עליך לאשר את מייל האימות"
msgstr "You have to confirm your registration with the link sent to your email"

#: templates/banned.html:8 templates/login.html:7 templates/signup.html:8
msgid "תמונת הפרופיל של קורס פייתון"
msgstr "Profile picture of the Python Course"

Expand All @@ -84,7 +137,7 @@ msgstr "Exercise submission system for the Python Course"
msgid "תרגילים"
msgstr "Exercises"

#: templates/exercises.html:21
#: templates/exercises.html:21 templates/view.html:101
msgid "הערות על התרגיל"
msgstr "Comments for the solution"

Expand All @@ -108,26 +161,30 @@ msgstr "All Exercises"
msgid "התחברות"
msgstr "Login"

#: templates/login.html:10
#: templates/login.html:10 templates/signup.html:11
msgid "ברוכים הבאים למערכת התרגילים!"
msgstr "Welcome to the exercise system!"

#: templates/login.html:11
msgid "הזינו את שם המשתמש והסיסמה שלכם:"
msgstr "Insert your username and password:"

#: templates/login.html:15 templates/login.html:17
#: templates/login.html:22 templates/login.html:24 templates/signup.html:16
msgid "שם משתמש"
msgstr "Username"

#: templates/login.html:21 templates/login.html:23
#: templates/login.html:28 templates/login.html:30 templates/signup.html:18
msgid "סיסמה"
msgstr "Password"

#: templates/login.html:28
#: templates/login.html:35
msgid "התחבר"
msgstr "Login"

#: templates/login.html:39 templates/signup.html:22
msgid "הירשם"
msgstr "Register"

#: templates/navbar.html:8
msgid "הלוגו של פרויקט לומדים פייתון: נחש צהוב על רקע עיגול בצבע תכלת, ומתחתיו כתוב - לומדים פייתון."
msgstr "The logo of the Learning Python project: yellow snake on light blue circle background and behind of it written - Learning Python"
Expand Down Expand Up @@ -164,6 +221,32 @@ msgstr "Check Exercises"
msgid "התנתקות"
msgstr "Logout"

#: templates/signup.html:9
#, fuzzy
msgid "הרשמה"
msgstr "Registration"

#: templates/signup.html:12
msgid "הזינו אימייל וסיסמה לצורך רישום למערכת:"
msgstr "Insert your email and password for registration:"

#: templates/signup.html:15
msgid "כתובת אימייל"
msgstr "Email Address"

#: templates/signup.html:17
msgid "שם מלא"
msgstr "Full Name"

#: templates/signup.html:19
#, fuzzy
msgid "אימות סיסמה"
msgstr "Password Confirmation"

#: templates/signup.html:25
msgid "חזרה לדף ההתחברות"
msgstr "Back to login page"

#: templates/status.html:7
msgid "חמ\"ל תרגילים"
msgstr "Exercises operations room"
Expand Down Expand Up @@ -256,23 +339,23 @@ msgstr "Submitted"
msgid "לא הוגש"
msgstr "Not submitted"

#: templates/user.html:43
#: templates/user.html:44
msgid "פתקיות:"
msgstr "Notes:"

#: templates/user.html:60 templates/user.html:62
#: templates/user.html:49 templates/user.html:51
msgid "פתקית חדשה"
msgstr "New Note"

#: templates/user.html:66
#: templates/user.html:55
msgid "תרגיל משויך:"
msgstr "Exercise:"

#: templates/user.html:75
#: templates/user.html:64
msgid "רמת פרטיות:"
msgstr "Privacy Level:"

#: templates/user.html:81
#: templates/user.html:70
msgid "הוסף פתקית"
msgstr "Add Note"

Expand Down Expand Up @@ -332,10 +415,6 @@ msgstr "Error:"
msgid "שגיאת סגל:"
msgstr "Staff Error:"

#: templates/view.html:101
msgid "הערות על התרגיל"
msgstr "Comments for the exercise"

#: templates/view.html:109
msgid "הערות כלליות"
msgstr "General comments"
Expand Down
Loading