Skip to content

Commit b1524ba

Browse files
Eric Somercnet
andauthored
Custom Admin Login (#159)
- Custom admin login page --------- Co-authored-by: Omer Cohen <omer@descope.com>
1 parent 435072a commit b1524ba

File tree

10 files changed

+297
-46
lines changed

10 files changed

+297
-46
lines changed

.vscode/settings.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22
"python.linting.flake8Enabled": true,
33
"python.linting.enabled": true,
44
"python.formatting.provider": "black",
5-
"[django-html]": {
6-
"editor.formatOnSave": true,
7-
"editor.defaultFormatter": "junstyle.vscode-django-support"
8-
},
95
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% load descope %} {% load static %}
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
5+
<head>
6+
<meta charset="utf-8" />
7+
<title>Django Admin</title>
8+
</head>
9+
10+
<body>
11+
<div class="flex-col">
12+
{% if user.is_authenticated %}
13+
<p class="errornote">
14+
You are authenticated as {{ user.email }}, but are not authorized to
15+
access this page. Would you like to login to a different account?
16+
</p>
17+
{% else %}
18+
{% descope_flow "sign-up-or-in" "/admin" %}
19+
{% endif %}
20+
</div>
21+
</body>
22+
23+
</html>

example_app/static/css/style.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
2+
3+
4+
body, html {
5+
margin: 0;
6+
padding: 0;
7+
}
8+
h1, p {
9+
font-weight: 600;
10+
}
11+
h1 {
12+
font-family: 'Press Start 2P', cursive;
13+
background-color: rgb(24, 24, 24);
14+
padding: 3vh 4vh;
15+
color: rgb(0, 255, 204);
16+
margin-top: 3vh;
17+
}
18+
.debug-btn {
19+
margin-top: 3vh;
20+
font-family: 'Press Start 2P', cursive;
21+
color: black;
22+
}
23+
.flex-col {
24+
display: flex;
25+
flex-direction: column;
26+
align-items: center;
27+
justify-content: center;
28+
text-align: center;
29+
height: 100%;
30+
width: 100%;
31+
}
32+
.logo {
33+
width: 8vw;
34+
height: auto;
35+
}
36+
.logo-container {
37+
margin-top: 5vh;
38+
padding: 3vh;
39+
border-radius: 50%;
40+
background-color: rgb(24, 24, 24);
41+
width: fit-content;
42+
}
43+
.logout {
44+
color: rgb(241, 72, 29);
45+
}
46+
.logo-container, h1 {
47+
box-shadow: 0px 0px 5px rgb(125, 125, 125), 0px 0px 10px rgb(31, 31, 31);
48+
}

example_app/static/images/logo.png

25.8 KB
Loading
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{% load descope %}
2+
{% load static %}
3+
24
<!DOCTYPE html>
35
<html lang="en">
46
<head>
@@ -7,15 +9,22 @@
79
<title>Descope Django</title>
810
<meta name="description" content="Descope Example" />
911
<meta name="author" content="Descope" />
12+
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}"/>
1013
</head>
1114

1215
<body>
13-
{% if user.is_authenticated %}
14-
<h1>Welcome {{ user.email }} you are logged in!</h1>
15-
<p><a href="{% url 'debug' %}">Detailed user information</a></p>
16-
<p><a href="{% url 'logout' %}">Log Out</a></p>
17-
{% else %}
18-
{% descope_flow "sign-up-or-in" "/" %}
19-
{% endif %}
16+
<div class="flex-col">
17+
<div class="logo-container flex-col">
18+
<img src="{% static '/images/logo.png' %}" alt="logo" class="logo">
19+
</div>
20+
<h1 class="title">Django Sample App</h1>
21+
{% if user.is_authenticated %}
22+
<a class="debug-btn" href={% url 'debug' %}>Debug &#8594;</a>
23+
<a class="debug-btn" href={% url 'admin:index' %}>Admin &#8594;</a>
24+
<a class="debug-btn logout" href="{% url 'logout' %}">Logout &#8594;</a>
25+
{% else %}
26+
{% descope_flow "sign-up-or-in" "/admin" %}
27+
{% endif %}
28+
</div>
2029
</body>
2130
</html>

example_app/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
from django_descope import descope_client
99
from django_descope.models import DescopeUser
10+
from django.shortcuts import render
11+
12+
from django.urls import path
13+
1014

1115
logger = logging.getLogger(__name__)
1216

0 commit comments

Comments
 (0)