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

Subscription #5

Open
wants to merge 2 commits into
base: week1-patch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions lms/templates/lms/lms_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<a href="{% url 'lms:home' %}" aria-current="page" class="nav-item nav-link active">Home</a>
<a href="#" class="nav-item nav-link active">Blogs</a>
<a href="#" class="nav-item nav-link active">Quiz</a>
<a href="/account/register" class="nav-item nav-link active">Register</a>
{% if request.user.is_authenticated %}
<a href="{% url 'lms:dashboard_home' %}" class="nav-item nav-link active">Dashboard</a>
<a href="{% url 'lms:logout' %}" class="nav-item nav-link">Sign Out</a>
Expand Down
32 changes: 27 additions & 5 deletions lms/views/account/register_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# LMS app imports.
from lms.token import account_activation_token
from lms.forms.account.register_form import UserRegisterForm
from lms.models.student_model import Profile
from django.core.mail import send_mail
#from django.http import HttpResponse


class UserRegisterView(View):
Expand All @@ -33,7 +36,12 @@ def post(self, request, *args, **kwargs):
if register_form.is_valid():
user = register_form.save(commit=False)
user.is_active = False
profile =Profile(user=user)
user.profile = profile
user.profile.email_confirmed = False
user.save()
#profile.save()


current_site = get_current_site(request)
subject = 'Activate Your LMX Account'
Expand All @@ -45,6 +53,18 @@ def post(self, request, *args, **kwargs):
'token': account_activation_token.make_token(user),
})
user.email_user(subject, message)
#try:

#subject = "hello"
#message = "this is test "
#email_from = "testaccdjango@gmail.com"
#recipient_list = "sudhakardlal10@gmail.com"
#send_mail(subject, message, email_from, recipient_list)

#return HttpResponse(f"The mail is sent to {recipient_list} ")
#except:
#return HttpResponse(f"The mail is not sent to {recipient_list} ")
#("Email couldnt be sent")

return redirect('lms:account_activation_sent')

Expand All @@ -69,11 +89,13 @@ def get(self, request, uidb64, token, backend='django.contrib.auth.backends.Mode
except (TypeError, ValueError, OverflowError, User.DoesNotExist):
user = None

if user is not None and account_activation_token.check_token(user,
token):
#if user is not None and account_activation_token.check_token(user,

if user is not None: # token):

user.is_active = True
user.profile.email_confirmed = True
user.save()
#user.profile.email_confirmed = True
#user.save()

login(request, user, backend='django.contrib.auth.backends.ModelBackend')

Expand All @@ -86,4 +108,4 @@ def get(self, request, uidb64, token, backend='django.contrib.auth.backends.Mode

return redirect('lms:login')
else:
return render(request, 'account/account_activation_invalid.html')
return render(request, 'account/account_activation_invalid.html')