Skip to content

fixed activation link not expiring #95

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
wants to merge 16 commits into
base: new-signup-workflow
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
2 changes: 1 addition & 1 deletion AlumniConnect/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def wrapper(request,*args, **kwargs):
user = request.user
if not (user.is_authenticated):
return HttpResponseRedirect('/') # case when user is not logged in
elif (not user.profile.verify) and ( user.is_authenticated == True):
elif (not user.profile.verify) and ( user.is_authenticated == True) and (request.path != '/complete_profile/'):
return HttpResponseRedirect('/complete_profile/') # case when user is logged in but haven't completed profile as after completing profile only user will be able to login
else:
return function(request,*args,**kwargs)
Expand Down
4 changes: 3 additions & 1 deletion AlumniConnect/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
path('register/', views.register, name='register'),
path('newregister/', views.new_register, name='new_register'),
re_path(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', views.activate, name='activate'),
path('activate/resend', views.resend_activation, name='resendactivate'),
path('confirm/', TemplateView.as_view(template_name='AlumniConnect/confirm_email.html'), name = 'confirm'),
path('success/', TemplateView.as_view(template_name='AlumniConnect/account_success.html'), name = 'success'),
re_path('^', include('django.contrib.auth.urls')),
Expand All @@ -60,7 +61,8 @@
path('chapter/', include('applications.chapter.urls')),
path('adminportal/', include('applications.adminportal.urls')),
path('jobs/', include('applications.job_posting.urls')),
re_path(r'favicon.ico', favicon_view)
re_path(r'favicon.ico', favicon_view),
path('constitution/', views.constitution, name='constitution'),
#path('', views.index, name='home'),
]

Expand Down
89 changes: 85 additions & 4 deletions AlumniConnect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def signup(request):
form = SignupForm()
return render(request, "AlumniConnect/signup.html", {'form': form})


@custom_login_required
def complete_profile(request):

user = request.user
Expand All @@ -173,7 +173,14 @@ def complete_profile(request):
# admin does not have any profile
return redirect('home')


try:
# if profile is already completed then redirect to home
if profile.verify or profile.reg_no:
return redirect('home')
except:
pass


#creating context for form
batches = list(Batch.objects.all().order_by('batch'))
context = {'edit': False, 'programmes': Constants.PROG_CHOICES,'branches': Constants.BRANCH, 'batches': batches, 'admission_years': Constants.YEAR_OF_ADDMISSION,'user_roll_no':user.username,'user_email':user.email}
Expand Down Expand Up @@ -252,7 +259,9 @@ def reg_no_gen(degree_, spec_, year):
def convert_int(number, decimals):
return str(number).zfill(decimals)


"""
This function needs to be depricated in new signup workflow.
"""
def new_register(request):
if request.method == 'POST':
form = NewRegister(request.POST, request.FILES)
Expand Down Expand Up @@ -316,9 +325,17 @@ def activate(request, uidb64, token):
print(uid)
u = User.objects.get(pk=uid)
print(u)
profile = Profile.objects.get(user=u)
except(TypeError, ValueError, OverflowError):
u = None
if u is not None and account_activation_token.check_token(u, token):
profile = None

# do not log in users with complete profiles
if profile and (profile.verify or profile.reg_no):
messages.warning(request, 'Please log in through password.')
return redirect('/')

if u and account_activation_token.check_token(u, token):
u.is_active = True
u.save()
login(request, u)
Expand All @@ -329,6 +346,67 @@ def activate(request, uidb64, token):
return HttpResponse('Activation link is invalid!')
return redirect('/')

'''
Incase the user does not complete their profile while the link
is active they can generate a new link by providing the old link.
'''
def resend_activation(request):
# checking if user is already logged in
if request.user and request.user.is_authenticated:
return redirect('home')

if request.method == 'POST':
form = AuthenticationForm(request,data = request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
user = User.objects.get(username = username)
profile = Profile.objects.get(user = user)

# if user is admin no need to check other thing
if user.is_staff:
messages.success(request, "Invalid user, admin can login directly")
return redirect('/login')

# if user already verified, login the user
if profile.verify:
login(request,user)
messages.success(request, "Your account is already verified!")
return redirect('home')

# make new activation link
if user and profile:
# re-sending mail for activation
current_site = get_current_site(request)
from_email = settings.DEFAULT_FROM_EMAIL
to = [user.email]
subject = "[noreply] SAC Account Activation"
html_message = render_to_string('AlumniConnect/account_activation_email.html', {
'user':user,
'domain':current_site,
'uid':urlsafe_base64_encode(force_bytes(user.pk)),
'token':account_activation_token.make_token(user)
})
plain_message = strip_tags(html_message)
send_mail(
subject = subject,
message = plain_message,
from_email = from_email,
recipient_list=to,
html_message = html_message,
fail_silently=False,
)
messages.success(request, "Mail sent successfully.")
return render(request,"AlumniConnect/confirm_email.html")

else:
messages.error(request, 'Something went wrong.')
return redirect('/')

else:
return render(request,'AlumniConnect/resend_activation_link.html',{'form':form})

form = AuthenticationForm()
return render(request,'AlumniConnect/resend_activation_link.html',{'form':form})

@custom_login_required
def change_password(request):
Expand All @@ -344,3 +422,6 @@ def change_password(request):
else:
form = PasswordChangeForm(request.user)
return render(request, 'AlumniConnect/change_password.html', {'form': form})

def constitution(request):
return render(request, 'AlumniConnect/constitution.html')
2 changes: 1 addition & 1 deletion applications/members/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
urlpatterns = [
re_path(r'^(?P<year>[0-9]{4})/', include(extrapatterns)),
# old link
path('sacbody/', views.sacbody, name="sacbody"),
# path('sacbody/', views.sacbody, name="sacbody"),
# new link
path('alumnibody/', views.alumnibody, name="alumnibody"),
path('search/', views.search, name='search'),
Expand Down
81 changes: 52 additions & 29 deletions applications/members/views.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import json
from importlib.metadata import requires
import json

from django.shortcuts import render, redirect
from django.db.models import Count, Q
from django.db.models import Count
from django.http import JsonResponse
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from applications.alumniprofile.models import Profile
from AlumniConnect.decorators import custom_login_required
from django.contrib import messages


# Create your views here.

def index(request):
counts = Profile.objects.filter(verify=True).values('batch').order_by('-batch').annotate(count=Count('batch'))
# print(len(counts))
total = 0

for batch, count in counts.values_list('batch', 'count'):
total += count
return render(request, "members/index.html", {'data': counts.values_list('batch', 'count'), 'total': total})

data = counts.values_list('batch', 'count')

context = {
'data': data,
'total': total,
}

return render(request, "members/index.html",context)


def batch(request, year):

programmes = Profile.objects.values_list('programme', flat=True).distinct()
data = {}
for row in programmes:
Expand All @@ -30,65 +41,77 @@ def batch(request, year):
for item in result:
data[row][item['branch']] = item['count']

# print(data) #prints {'B.Des': {'CSE': 1}, 'B.Tech': {'CSE': 1, 'ME': 1}}
return render(request, "members/year.html", {'data': data, 'year': year})


def branch(request, programme, year, branch):
# todo: change mail_sent to verify
alumni = Profile.objects.filter(programme=programme, batch=year, branch=branch, verify=True)
# print(alumni)
return render(request, "members/branch.html", {'data': alumni, 'batch': year, 'branch': branch})

def sacbody(request):
return redirect('members:alumnibody')
# def sacbody(request):
# return redirect('members:alumnibody')

def alumnibody(request):
return render(request, "members/alumnibody.html")


@custom_login_required
def search(request):
key = request.GET['search']
profiles = Profile.objects.filter(name__icontains=key) | Profile.objects.filter(
roll_no__icontains=key) | Profile.objects.filter(reg_no__icontains=key)
if len(request.GET) > 1:
if request.GET['batch'] != '':
batch = request.GET['batch']
print(batch)
profiles = Profile.objects.all()
if len(request.POST) > 1:
if request.POST['search'] != '':
key = request.POST['search']
profiles = profiles.filter(name__icontains=key) | Profile.objects.filter(
roll_no__icontains=key) | Profile.objects.filter(reg_no__icontains=key)

if request.POST['batch'] != '':
batch = request.POST['batch']
profiles = profiles.filter(batch=batch)
print(profiles)
if request.GET['city'] != '':
city = request.GET['city']

if request.POST['city'] != '':
city = request.POST['city']
profiles = profiles.filter(city__icontains=city)
if request.GET['programme'] != 'Programme':
programme = request.GET['programme']

if request.POST['programme'] != '':
programme = request.POST['programme']
profiles = profiles.filter(programme__icontains=programme)
if request.GET['branch'] != '':
branch = request.GET['branch']

if request.POST['branch'] != '':
branch = request.POST['branch']
profiles = profiles.filter(branch__icontains=branch)
if request.GET['org'] != '':
org = request.GET['org']

if request.POST['org'] != '':
org = request.POST['org']
profiles1 = profiles.filter(current_organisation__icontains=org)
profiles2 = profiles.filter(current_university__icontains=org)
profiles = profiles1 | profiles2

profiles = profiles.order_by('name')

context = {'profiles': profiles,
'keyy': key,
'keyy': 1,
'zero': len(profiles),
'request': request.GET
'request': request.POST
}
return render(request, "members/index.html", context)

if len(profiles):
messages.success(request,"Total "+str(len(profiles))+" Alumni Found")
else:
messages.error(request, "No Result Found ")



return render(request, "members/index.html", context)

def autoSearch(request):
if request.is_ajax():
# print(request.POST['term'], request.GET['te'])
key = request.GET['term']
search_qs = Profile.objects.filter(name__icontains=key) | Profile.objects.filter(
roll_no__icontains=key) | Profile.objects.filter(reg_no__icontains=key)
data = []
for r in search_qs:
print(r.name)
data.append(r.name)
else:
data = 'fail'
Expand All @@ -105,5 +128,5 @@ def mapSearch(request):
'keyy': key,
'zero': len(profiles),
'map': True
}
}
return render(request, "members/index.html", context)
Binary file not shown.
Binary file not shown.
Binary file added static/AlumniConnect/img/people/Chirag.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/AlumniConnect/img/people/Mihir.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/AlumniConnect/img/people/srijan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions templates/AlumniConnect/constitution.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends 'globals/base.html' %}
{% load static %}

{% block title %}
Alumni Constitution
{% endblock %}

{% block css %}
<style>
.constitution{
text-align:center;
}
.constitutionContainer{
width:800px;
height:800px;
}
@media (max-width: 768px) {
.constitutionContainer {
width: 90%;
height: 400px;
}
}
</style>
{% endblock %}

{% block body %}

{% include 'globals/navbar.html' %}

<div class="p-0 m-0 masthead-bg w-100 h-100 parallax" style="min-height:300px !important; height:300px !important; background-position-y: 300px;"></div>

<header class="masthead text-center text-white d-flex" style="height:0px; min-height:300px;">
<div class="container my-auto" style="margin-bottom:50px !important;">
<div class="row">
<div class="col-lg-8 mx-auto align-middle">
<h1 class="text-uppercase mt-4 font-open-sans">
<strong>ALUMNI CONSTITUTION</strong>
</h1>
</div>
</div>
</div>
</header>
<section id="constitution" class="constitution text-center p-3">
<iframe src="{% static 'AlumniConnect/assets/alumni_constitution.pdf' %}" class="constitutionContainer">
</iframe>
</section>
{% endblock %}

{% include 'globals/footer.html' %}
7 changes: 5 additions & 2 deletions templates/AlumniConnect/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="text-uppercase mt-4">
<div class="alert alert-primary m-4 text-center" role="alert" >
Please Sign In to Continue! Don't have an Account?
<h5 class="pt-2 m-0">
<a class="d-inline-block" href="{% url 'new_register' %}">
<a class="d-inline-block" href="{% url 'signup' %}">
<span class="badge badge-pill badge-primary p-2">Register! &nbsp;<i class="fas fa-external-link-alt"></i></span>
</a>
</h5>
Expand Down Expand Up @@ -64,7 +64,10 @@ <h2>SIGN IN</h2>
<input id="signin-password" type="password" name="password" class="form-control" placeholder="Password"
aria-label="Password" aria-describedby="button-addon2" required>
</div>
<p class="alert font-open-sans m-3 p-2"><a href="{% url 'password_reset' %}">Forgot Password? </a></p>
<div class="row justify-content-center align-items-space-between">
<p class="alert font-open-sans m-1 p-2"><a href="{% url 'password_reset' %}">Forgot Password? </a></p>
<p class="alert font-open-sans m-1 p-2"><a href="{% url 'resendactivate' %}">Resend Activation Link? </a></p>
</div>
<button class="btn btn-primary px-5 py-2" type="submit" value="login" name="submit">Sign In</button>
</form>
</div>
Expand Down
Loading