Fakultas Ilmu Komputer UI

Commit 9eb16994 authored by Yaumi Alfadha's avatar Yaumi Alfadha
Browse files

Merge branch '1706023031-66' into 'master'

[#66] Change Password

See merge request !47
parents 2d43f764 74ca6eef
Pipeline #58931 passed with stages
in 15 minutes
<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">
<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">
<!-- Sidebar - Brand -->
<a class="sidebar-brand d-flex align-items-center justify-content-center" href="{% url 'daftar_katalog' %}">
<div class="sidebar-brand-icon rotate-n-15"></div>
......@@ -18,4 +18,8 @@
<a class="nav-link" href="/sunting/">
<span>Sunting Profil</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/change-password/">
<span>Change Password</span></a>
</li>
</ul>
\ No newline at end of file
{% extends 'app/base_profile.html' %}
{% block title %}Change Password{% endblock%}
{% block content %}
<h1> Change Password </h1>
<br/><br/>
<div class = "from-group">
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button class="btn btn-secondary"> Change Password</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'app/base_profile.html' %}
{% block title %}Change Password{% endblock%}
{% block content %}
<h1> Password was Changed Successfully!</h1>
<br/><br/>
{% endblock %}
\ No newline at end of file
......@@ -56,6 +56,8 @@ from .views import (
KatalogPerKontributorView,
UploadMateriView,
UploadMateriExcelView,
PasswordChangeViews,
password_success,
)
from app.forms import SuntingProfilForm, year_choices
from app.utils.fileManagementUtil import get_random_filename, remove_image_exifdata
......@@ -2355,3 +2357,45 @@ class YearChoicesTest(TestCase):
choices = year_choices()
self.assertEqual((2000, 2000), choices[0])
class ChangePasswordTest(TestCase):
def setUp(self):
self.client = Client()
self.kontributor = User.objects.create_contributor(email="kontributor@gov.id", password="kontributor")
self.admin = User.objects.create_admin(email="admin@gov.id", password="admin")
self.url = "/change-password/"
self.view = PasswordChangeViews
self.template_name = "change-password.html"
def test_change_password_view(self):
found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.as_view().__name__)
def test_change_password_template(self):
# Login
self.client.login(email="kontributor@gov.id", password="kontributor")
# Test
response = self.client.get(self.url)
self.assertTemplateUsed(response, self.template_name)
# Logout
self.client.logout()
def test_change_password_url(self):
# Login
self.client.login(email="kontributor@gov.id", password="kontributor")
# Test
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
# Logout
self.client.logout()
def test_change_password_access(self):
# Kontributor
# Login
self.client.login(email="kontributor@gov.id", password="kontributor")
# Test
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
# Logout
self.client.logout()
\ No newline at end of file
......@@ -5,8 +5,8 @@ from app.views import (DashboardKontributorView, ProfilKontributorView,
SuksesLoginAdminView, SuksesLoginKontributorView, DownloadHistoryView,
SuntingProfilView, UploadMateriHTML, UploadMateriView, UploadMateriExcelView,
ProfilAdminView, PostsView, SuntingProfilAdminView,
ReqMateriView, KatalogPerKontributorView)
ReqMateriView, KatalogPerKontributorView, PasswordChangeViews, password_success)
from django.contrib.auth import views as auth_views
urlpatterns = [
path("", views.DaftarKatalog.as_view(), name="daftar_katalog"),
path("materi/<int:pk>/", views.DetailMateri.as_view(), name="detail-materi"),
......@@ -37,4 +37,6 @@ urlpatterns = [
name="katalog-per-kontributor"),
path("materi/rate/", views.add_rating_materi, name="rate-materi"),
path("materi/<int:pk>/save-to-gdrive/", views.save_to_gdrive, name="save-to-gdrive"),
path("change-password/", PasswordChangeViews.as_view(template_name='change-password.html')),
path("password_success/", views.password_success, name="password_success"),
]
......@@ -29,6 +29,10 @@ from authentication.models import User
from .services import DafterKatalogService, DetailMateriService, LikeDislikeService, MateriFieldValidationHelperService, \
DownloadViewMateriHelperService, UploadMateriService, EditProfileService, RevisiMateriService, \
DownloadHistoryService, GoogleDriveUploadService
from django.contrib.auth.views import PasswordChangeForm
from django.urls import reverse_lazy
from django.contrib.auth.views import PasswordChangeView
from django.shortcuts import render
def permission_denied(request, exception, template_name="error_403.html"):
......@@ -696,3 +700,11 @@ def save_to_gdrive(request, pk):
raise Http404("File tidak dapat ditemukan.")
return HttpResponseRedirect(reverse('detail-materi', kwargs={'pk': pk}))
class PasswordChangeViews(PasswordChangeView):
from_class = PasswordChangeForm
success_url = reverse_lazy('password_success')
def password_success(request):
return render(request, 'password_success.html', {})
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment