Skip to content

Commit de6b9b8

Browse files
committed
Add Oauth
1 parent da6e881 commit de6b9b8

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

_layouts/default.html

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<meta name="title" content="Coderic">
1717
<meta name="description"
1818
content="Corporation Oriented to the Development of Engineering of Resources Information Commercial">
19+
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
1920
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
2021
<script src="https://cdn.auth0.com/js/auth0/9.28.0/auth0.min.js"></script>
2122
<script type="text/javascript">
@@ -27,14 +28,38 @@
2728
scope: 'read:current_user',
2829
responseType: 'token id_token'
2930
});
31+
32+
3033
function login() {
3134
webAuth.authorize();
3235
}
33-
function logout() {
34-
webAuth.logout({
36+
37+
$(document).ready(function() {
38+
39+
$(".login-btn").click(() => {
40+
webAuth.authorize();
41+
return false;
42+
});
43+
$(".logout-btn").click(() => webAuth.logout({
3544
returnTo: 'https://' +window.location.hostname + '/'
36-
});
37-
}
45+
}));
46+
47+
webAuth.checkSession(
48+
{
49+
audience: `https://coderic.eu.auth0.com/api/v2/`,
50+
scope: 'read:current_user'
51+
},
52+
function(err, result) {
53+
if (err || !result || !result.accessToken) {
54+
$(".guest").show();
55+
$(".authenticated").hide();
56+
} else {
57+
$(".guest").hide();
58+
$(".authenticated").show();
59+
}
60+
}
61+
);
62+
});
3863
</script>
3964
<link rel="stylesheet" href="{{ '/assets/css/main.css' | relative_url }}">
4065
{% for localized_page in localized_pages %}

_layouts/layout_en.html

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,26 @@
5050
</a>
5151
</li>
5252
</ol>
53-
<!--ol class="inline-flex md:space-x-2 rtl:space-x-reverse">
53+
<ol class="inline-flex md:space-x-2 rtl:space-x-reverse guest">
5454
<li>
55-
<a href="/profile" class="inline-flex items-center text-sm font-medium hover:text-orange-600"
56-
title="Profile">
55+
<a class="btn-login inline-flex items-center text-sm font-medium hover:text-orange-600"
56+
title="Log in">
57+
<svg class="w-3.5 h-3.5 ms-2 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"
58+
fill="currentColor">
59+
<defs />
60+
<title>login</title>
61+
<path
62+
d="M26,30H14a2,2,0,0,1-2-2V25h2v3H26V4H14V7H12V4a2,2,0,0,1,2-2H26a2,2,0,0,1,2,2V28A2,2,0,0,1,26,30Z" />
63+
<polygon points="14.59 20.59 18.17 17 4 17 4 15 18.17 15 14.59 11.41 16 10 22 16 16 22 14.59 20.59" />
64+
<rect id="_Transparent_Rectangle_" data-name="&lt;Transparent Rectangle&gt;" class="cls-1" width="32"
65+
height="32" style="fill:none" />
66+
</svg> <span class="hidden sm:inline-block">Sign in</span>
67+
</a>
68+
</li>
69+
</ol>
70+
<ol class="inline-flex md:space-x-2 rtl:space-x-reverse authenticated">
71+
<li>
72+
<a href="/profile" class="inline-flex items-center text-sm font-medium hover:text-orange-600" title="Profile">
5773
<svg class="w-3.5 h-3.5 ms-2 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"
5874
fill="currentColor">
5975
<defs></defs>
@@ -83,8 +99,7 @@
8399
</a>
84100
</li>
85101
<li>
86-
<button type="submit" (click)="logout()"
87-
class="inline-flex items-center text-sm font-medium hover:text-orange-600">
102+
<button type="submit" class="inline-flex logout-btn items-center text-sm font-medium hover:text-orange-600">
88103
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
89104
stroke="currentColor" class="w-3.5 h-3.5 ms-2 mr-2">
90105
<path stroke-linecap="round" stroke-linejoin="round"
@@ -93,7 +108,7 @@
93108
<span class="hidden sm:inline-block" i18n>Sign out</span>
94109
</button>
95110
</li>
96-
</ol-->
111+
</ol>
97112
</nav>
98113
</div>
99114
<header class="flex justify-between border-t-4 border-b-8 border-orange-500">
@@ -130,15 +145,15 @@
130145
background: linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(229, 229, 229, 0.50) 150%);">
131146
<div class="flex items-center justify-center h-full text-right">
132147
<div class="flex justify-end w-full gap-3 px-6 text-black md:px-6">
133-
148+
134149
</div>
135150
</div>
136151
</div>
137152
</div>
138153
</header>
139154
<main>
140155
{% if page.navigation %}
141-
{% include {{ page.navigation }} %}
156+
{% include {{ page.navigation }} %}
142157
{% endif %}
143158
{{ content }}
144159
</main>
@@ -174,11 +189,13 @@
174189
i18n>Privacy</a>
175190
</li>
176191
<li>
177-
<a href="https://coderic.org/legal" class="inline-flex items-center text-sm font-medium hover:text-white" i18n>Legal</a>
192+
<a href="https://coderic.org/legal" class="inline-flex items-center text-sm font-medium hover:text-white"
193+
i18n>Legal</a>
178194
</li>
179195
<li>·</li>
180196
<li>
181-
<a href="https://coderic.org/tos" class="text-sm font-medium ms-1 hover:text-white" i18n>Terms and Conditions</a>
197+
<a href="https://coderic.org/tos" class="text-sm font-medium ms-1 hover:text-white" i18n>Terms and
198+
Conditions</a>
182199
</li>
183200
</ol>
184201
</nav>
@@ -190,4 +207,4 @@
190207
</p>
191208
</div>
192209
</footer>
193-
</div>
210+
</div>

0 commit comments

Comments
 (0)