This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new 76aea0b  feat(oauth): add log in and log out to the welcome page.
76aea0b is described below

commit 76aea0bfbeda6683cccc0796813ac228786588e3
Author: Robert Munteanu <[email protected]>
AuthorDate: Fri Oct 11 17:27:33 2024 +0200

    feat(oauth): add log in and log out to the welcome page.
---
 .../apache/sling/samples/oauth_demo/UserModel.java | 32 ++++++++++++++++++++++
 .../oauth-demo/components/welcome/welcome.html     | 12 ++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git 
a/oauth/core/src/main/java/org/apache/sling/samples/oauth_demo/UserModel.java 
b/oauth/core/src/main/java/org/apache/sling/samples/oauth_demo/UserModel.java
new file mode 100644
index 0000000..64f94e8
--- /dev/null
+++ 
b/oauth/core/src/main/java/org/apache/sling/samples/oauth_demo/UserModel.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.samples.oauth_demo;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.injectorspecific.SlingObject;
+
+@Model(adaptables=SlingHttpServletRequest.class)
+public class UserModel {
+
+    @SlingObject
+    private SlingHttpServletRequest request;
+
+    public boolean isLoggedIn() {
+        return request.getAuthType() != null;
+    }
+}
\ No newline at end of file
diff --git 
a/oauth/ui.apps/src/main/content/jcr_root/apps/oauth-demo/components/welcome/welcome.html
 
b/oauth/ui.apps/src/main/content/jcr_root/apps/oauth-demo/components/welcome/welcome.html
index df5f709..70b4083 100644
--- 
a/oauth/ui.apps/src/main/content/jcr_root/apps/oauth-demo/components/welcome/welcome.html
+++ 
b/oauth/ui.apps/src/main/content/jcr_root/apps/oauth-demo/components/welcome/welcome.html
@@ -8,8 +8,16 @@
 <body>
     <main>
         <h1>Sling OAuth Demo</h1>
-        <p>Access the <a class="underline" 
href="oauth-demo/videos.html">YouTube videos</a> page.</p>
-        <p>Access the <a class="underline" 
href="oauth-demo/repositories.html">GitHub repositories</a> page.</p>
+        <sly data-sly-use.user="org.apache.sling.samples.oauth_demo.UserModel">
+            <div data-sly-test="${user.loggedIn}">
+                <p>Access the <a class="underline" 
href="oauth-demo/videos.html">YouTube videos</a> page.</p>
+                <p>Access the <a class="underline" 
href="oauth-demo/repositories.html">GitHub repositories</a> page.</p>
+                <p>If you prefer, you can <a 
href="/system/sling/logout.html?resource=${resource.path}.html" 
class="underline">log out</a>.</p>
+            </div>
+            <div data-sly-test="${!user.loggedIn}">
+                <p>Please <a 
href="/system/sling/login.html?resource=${resource.path}.html" 
class="underline">log in</a> to access the demo pages.</p>
+            </div>
+        </sly>
     </main>
 </body>
 </html>
\ No newline at end of file

Reply via email to