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

Feature to reactivate deactivated accounts #4391

Open
wants to merge 3 commits into
base: master
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
85 changes: 85 additions & 0 deletions apps/accounts/templates/account/account_activate_confirmed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Account Activation</title>
<link type="text/css" rel="stylesheet" href="{% static 'accounts/css/main.css' %}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.1/css/materialize.min.css">
</head>
<body>
<script type="text/javascript">
function link(){
var url = window.location.origin + "/auth/login";
if (url.indexOf("localhost")!== -1){
url = "http://localhost:8888/auth/login"
}
var element = document.getElementById('login-url');
element.setAttribute("href",url);
}
</script>

<!-- Loader init -->
<eval-loader></eval-loader>
<!-- Auth parent view -->
<section class="auth-container">
<!-- Graphic animated view -->
<div class="graphic-cont">
<img class="star-img star1" src="{% static 'accounts/images/star1.png' %}">
<img class="star-img star2" src="{% static 'accounts/images/star2.png' %}">
<div class="moon">
<img src="{% static 'accounts/images/moon.png' %}">
</div>
<div class="sun">
<img src="{% static 'accounts/images/sun.png' %}">
</div>
<div class="auth-cloud-cont">
<img src="{% static 'accounts/images/auth-cloud.png' %}">
</div>
<div class="ufo">
<img src="{% static 'accounts/images/spaceman.png' %}">
</div>
</div>
<!-- Rendering auth children here -->
<div class="auth-cont">
<div class="row">
<div class="col s12 m4 offset-m4 center">
<h5><strong><a ui-sref="home" class="dark-link"><img class="auth-logo"
src="{% static 'accounts/images/evalai-logo.png' %}"></a></strong></h5>
<p class="text-med-gray auth-home">Evaluating state of the art in AI</p>
</div>
</div>
<div class="row">
<div class="col s12 m4 offset-m4 text-highlight center w-300">
{% if error %}
<strong>
<p class="text-med-gray auth-home">{{ error }}</p>
</strong>
{% else %}
<strong>
<p class="text-med-gray auth-home">Your account has been activated successfully.</p>
</strong>
{% endif %}
</div>
</div>
<div class="row">
<div class="col s12 m4 offset-m4 text-highlight center w-300">
<a onclick="link()" id="login-url" href="#" class="waves-effect waves-dark btn ev-btn-dark blue-grey darken-4">Log In</a>
</div>
</div>
<div class="row">
<div class="reg-alert col s12 m6 offset-m3 align-left text-highlight w-300 social-auth-group">
<a href="https://github.com/Cloud-CV/EvalAI" class="light-link" target="_blank"><i class="fa fa-github"></i></a> &nbsp;&nbsp;&nbsp;<a href="https://twitter.com/eval_ai"
class="light-link" target="_blank"><i class="fa fa-twitter"></i></a> &nbsp;&nbsp;&nbsp; <a
href="https://cloudcv.org/" class="light-link fg-pass" target="_blank">www.cloudcv.org</a>
&nbsp;&nbsp;&nbsp; <a ui-sref="home" class="light-link fg-pass">Back to home</a>
</div>
</div>
</div>
<div class="clearfix"></div>
</section>
</body>
</html>
8 changes: 8 additions & 0 deletions apps/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

urlpatterns = [
url(r"^user/disable$", views.disable_user, name="disable_user"),
url(r"^user/generate_activation_link/(?P<user_email>[\w.@+-]+)/$",
views.generate_activation_link,
name="generate_activation_link"
),
url(r"^user/activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})$",
views.activate_user,
name="activate_user"
),
url(r"^user/get_auth_token$", views.get_auth_token, name="get_auth_token"),
url(
r"^user/refresh_auth_token$",
Expand Down
42 changes: 41 additions & 1 deletion apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,53 @@
from .serializers import JwtTokenSerializer

from .throttles import ResendEmailThrottle
from django.core.mail import EmailMessage

from django.shortcuts import render
from django.utils.encoding import force_bytes, force_text
from django.contrib.auth.tokens import default_token_generator
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode


@api_view(['GET'])
def generate_activation_link(request, user_email):
try:
user = User.objects.get(email=user_email)
except User.DoesNotExist:
return Response({'error': 'User with this email does not exist.'}, status=status.HTTP_404_NOT_FOUND)
if user.is_active:
return Response({'message': 'Account is already active.'}, status=status.HTTP_400_BAD_REQUEST)

token = default_token_generator.make_token(user)
uid = urlsafe_base64_encode(force_bytes(user.pk))
activation_link = f"https://eval.ai/api/accounts/user/activate/{uid}/{token}"
mail_subject = 'Activate your account.'
message = f"Dear {user.email},\n\nPlease click on the following link to activate your account:\n{activation_link}\n\nIf you did not request this, please ignore this email.\n\nBest regards,\nCloud CV Team"
email = EmailMessage(mail_subject, message, to=[user.email])
email.send()
return Response({'message': 'Activation link has been sent to your email.'}, status=status.HTTP_200_OK)


@api_view(['GET'])
def activate_user(request, uidb64, token):
try:
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
if default_token_generator.check_token(user, token):
user.is_active = True
user.save()
# Render the account_activate_confirmed.html template
return render(request, 'account/account_activate_confirmed.html', {'error': None})
else:
return render(request, 'account/account_activate_confirmed.html', {'error': 'Invalid activation link. Please Check the link again.'})
except Exception as e:
return render(request, 'account/account_activate_confirmed.html', {'error': str(e)})


@api_view(["POST"])
@permission_classes((permissions.IsAuthenticated,))
@authentication_classes((JWTAuthentication, ExpiringTokenAuthentication))
def disable_user(request):

user = request.user
user.is_active = False
user.save()
Expand Down
33 changes: 33 additions & 0 deletions frontend/src/js/controllers/authCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,39 @@
};
utilities.sendRequest(parameters, "header");
};

// Function to activate account
vm.activateAccount = function(activateForm) {
if(activateForm){
vm.startLoader("Activating Your Account");
var parameters = {};
parameters.url = 'accounts/user/generate_activation_link/'+vm.getUser.email; // API URL
parameters.method = 'GET';
console.log(vm.getUser.email);
parameters.callback = {
onSuccess: function(response) {
console.log(response);
if (response.status === 200) {
$rootScope.notify("success",response.data.message);
}
vm.stopLoader();
},
onError: function(response) {
console.log(response);
if (response.status === 400) {
$rootScope.notify("error",response.data.message);
}
else{
$rootScope.notify("error",response.data.error);
}
vm.stopLoader();
}
};
utilities.sendRequest(parameters, "no-header");
}else {
vm.stopLoader();
}
};

// Function to login
vm.userLogin = function(loginFormValid) {
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/js/route-config/route-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
authpage: true
};

var accountActivate = {
name: "auth.account-activate",
parent: "auth",
url: "/account-activate",
templateUrl: baseUrl+ "/web/auth/account-activate.html",
title: 'Account Activate',
authpage: true
};

var reset_password = {
name: "auth.reset-password",
parent: "auth",
Expand Down Expand Up @@ -605,6 +614,7 @@
$stateProvider.state(auth);
$stateProvider.state(login);
$stateProvider.state(signup);
$stateProvider.state(accountActivate);
$stateProvider.state(verify_email);
$stateProvider.state(reset_password);
$stateProvider.state(reset_password_confirm);
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/views/web/auth/account-activate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="col s12 m6 offset-m3 left">
<ul class="left">
<li class="ev-horiz-list"><a ui-sref="auth.login" class="dark-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Log In</a></li>
<li class="ev-horiz-list"><a ui-sref="auth.signup" class="light-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Sign Up</a></li>
<li class="ev-horiz-list"><a ui-sref="auth.account-activate" class="light-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Account Activate</a></li>
</ul>
</div>
<div class="col s12 m6 offset-m3">
<form name="activateForm" ng-submit="auth.activateAccount(activateForm.$valid)" id="activate-account" novalidate>
<div class="input-field align-left">
<input type="email" id="email" class="dark-autofill" name="email" ng-model="auth.getUser.email" required>
<span class="form-icon form-icon-dark"><i class="fa fa-envelope"></i></span>
<label for="email">Email*</label>
<div class="wrn-msg text-highlight" ng-messages="resetpassForm.email.$error" ng-if="resetpassForm.email.$touched || resetpassForm.$submitted">
<p ng-message="email">Please enter valid email address.</p>
<p ng-message="required">Email address is required.</p>
</div>
</div>
<div class="row">
<br>
<div class="col s6 align-left rm-gut">
<button class="waves-effect waves-dark btn ev-btn-dark grad-btn grad-btn-dark w-300" type="submit">Activate Account</button>
</div>
</div>
<div ng-if="auth.isFormError" class="wrn-msg text-highlight align-left">{{auth.FormError}}</div>
<div>
<p class="text-light-gray">
<span class="text-med-black">Start with a new account </span><a class="highlight-link" ui-sref="auth.signup" ng-click="auth.resetForm()"> Sign Up</a>
</p>
</div>
</form>
</div>
1 change: 1 addition & 0 deletions frontend/src/views/web/auth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<ul class="left">
<li class="ev-horiz-list"><a ui-sref="auth.login" class="dark-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Log In</a></li>
<li class="ev-horiz-list"><a ui-sref="auth.signup" class="light-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Sign Up</a></li>
<li class="ev-horiz-list"><a ui-sref="auth.account-activate" class="light-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Account Activate</a></li>
<!-- <li class="ev-horiz-list"><a ui-sref="auth.reset-password" class="light-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Forgot Password</a></li> -->
</ul>
</div>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/views/web/auth/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<ul class="left">
<li class="ev-horiz-list"><a ui-sref="auth.login" class="light-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Log In</a></li>
<li class="ev-horiz-list"><a ui-sref="auth.signup" class="dark-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Sign Up</a></li>
<li class="ev-horiz-list"><a ui-sref="auth.account-activate" class="light-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Account Activate</a></li>

<!-- <li class="ev-horiz-list"><a ui-sref="auth.reset-password" class="light-link" ui-sref-active="active-auth" ng-click="auth.resetForm()">Forgot Password</a></li> -->
</ul>
</div>
Expand Down