Add avatars and attempt to fix user session saving
authorTheSaminator <TheSaminator@users.noreply.github.com>
Tue, 8 Feb 2022 22:59:36 +0000 (17:59 -0500)
committerTheSaminator <TheSaminator@users.noreply.github.com>
Tue, 8 Feb 2022 22:59:36 +0000 (17:59 -0500)
plan/oauth-logo.png
plan/oauth-logo.svg [new file with mode: 0644]
src/jvmMain/kotlin/starshipfights/auth/providers.kt
src/jvmMain/kotlin/starshipfights/data/auth/user_sessions.kt
src/jvmMain/kotlin/starshipfights/info/views_user.kt

index f0940b424ec1cfa3960fbd404963c45863e1c935..0a6186c5d41ac0e52ad733f921de63c90e2ad1b6 100644 (file)
Binary files a/plan/oauth-logo.png and b/plan/oauth-logo.png differ
diff --git a/plan/oauth-logo.svg b/plan/oauth-logo.svg
new file mode 100644 (file)
index 0000000..f364dc7
--- /dev/null
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="100mm"
+   height="100mm"
+   viewBox="0 0 99.999998 100"
+   version="1.1"
+   id="svg8"
+   inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
+   sodipodi:docname="oauth-logo.svg"
+   inkscape:export-filename="D:\gamestuff\starship-fights\plan\oauth-logo.png"
+   inkscape:export-xdpi="203.2"
+   inkscape:export-ydpi="203.2">
+  <defs
+     id="defs2" />
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="0.98994949"
+     inkscape:cx="184.26894"
+     inkscape:cy="202.23053"
+     inkscape:document-units="mm"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     inkscape:snap-smooth-nodes="true"
+     inkscape:snap-midpoints="true"
+     inkscape:snap-bbox="true"
+     inkscape:snap-bbox-midpoints="true"
+     inkscape:snap-nodes="true"
+     fit-margin-top="18"
+     fit-margin-left="2"
+     fit-margin-right="2"
+     fit-margin-bottom="18"
+     inkscape:window-width="1920"
+     inkscape:window-height="1017"
+     inkscape:window-x="-8"
+     inkscape:window-y="-8"
+     inkscape:window-maximized="1" />
+  <metadata
+     id="metadata5">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(-10,-191)">
+    <g
+       id="g1489"
+       transform="translate(12,-23.999999)">
+      <path
+         inkscape:connector-curvature="0"
+         d="m 32.000004,233.99998 15.50003,15.50004 7.750002,7.75 7.750006,7.75001 -7.750015,7.74999 -7.750013,7.75001 -15.500022,15.50001 -15.500027,-15.50001 -7.7500028,-7.75001 -7.75000361,-7.74999 7.75001111,-7.75001 7.7500123,-7.75003 z"
+         style="fill:#888888;fill-opacity:1;stroke:#444444;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal"
+         id="rect815-2" />
+      <path
+         inkscape:connector-curvature="0"
+         id="path819-7"
+         d="m 32.000004,233.99998 -15.500022,46.50005 15.500022,15.50001 15.500022,-15.50001 z"
+         style="fill:#ffcc33;fill-opacity:1;stroke:#444444;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+      <path
+         transform="scale(0.26458333)"
+         sodipodi:nodetypes="cccccccc"
+         inkscape:connector-curvature="0"
+         id="path865"
+         d="m 150.23633,913.70117 58.58203,58.58203 h 110.55228 0.50586 v -0.0273 c 21.71245,-0.40818 39.17108,-26.50038 39.17969,-58.55469 h -39.68555 z"
+         style="fill:#cccccc;fill-opacity:1;stroke:#444444;stroke-width:7.55905533;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="ccccccccc"
+         inkscape:connector-curvature="0"
+         id="path865-9"
+         d="m 55.250082,257.25007 7.749914,7.74991 -7.749969,7.75004 18.883822,-0.008 h 0.13384 v -0.007 c 5.74476,-0.10802 10.36402,-7.01159 10.3663,-15.49262 h -10.50014 z"
+         style="fill:#cccccc;fill-opacity:1;stroke:#444444;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+      <path
+         sodipodi:nodetypes="cccccccc"
+         inkscape:connector-curvature="0"
+         id="path865-4"
+         d="m 55.250027,272.75002 -15.500012,15.50002 23.883704,-0.008 h 0.13384 v -0.007 c 5.74475,-0.10802 10.36401,-7.01159 10.36629,-15.49262 h -10.50013 z"
+         style="fill:#cccccc;fill-opacity:1;stroke:#444444;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+    </g>
+    <g
+       style="stroke-width:0.03307291"
+       transform="matrix(0.5,0,0,0.5,-56.48242,254.59962)"
+       id="g1664">
+      <path
+         inkscape:connector-curvature="0"
+         style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#993333;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.24804692;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
+         d="m 165.96484,-62.199219 -1.33929,3.75 -8.92857,25 -5.80357,16.25 h 25 l -1.78571,5 h -25 l -7.14286,20.0000002 h 28.75 16.25 l 16.07143,-45.0000002 h -16.25 -8.75 l 1.78571,-5 h 25 l 7.14286,-20 h -28.75 z m 50,0 -1.33929,3.75 -4.46428,12.5 -19.19643,53.7500002 h 20 l 8.92857,-25.0000002 h 12.5 l 7.14286,-20 h -12.5 l 1.78571,-5 h 25 l 7.14286,-20 z m -45.17857,7.5 h 8.75 21.25 l -1.78572,5 h -25 l -7.14285,20 h 16.25 8.75 L 181.14341,0.30078125 h -8.75 -21.25 l 1.78572,-5.00000005 h 25 l 7.14285,-20.0000002 h -25 l 3.125,-8.75 z m 50,0 h 30 l -1.78572,5 h -25 l -7.14285,20 h 12.5 l -1.78572,5 h -12.5 l -8.92857,25.00000025 h -5 L 217.66127,-45.949219 Z"
+         id="rect1519-0" />
+      <path
+         inkscape:connector-curvature="0"
+         style="fill:#ff5555;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.24804692;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
+         d="m 168.37481,-58.448486 -8.92857,25 -4.46429,12.5 h 25 l -4.46428,12.4999997 h -25 l -4.46429,12.5 h 25 12.5 l 13.39286,-37.4999997 h -12.5 -12.5 l 4.46428,-12.5 h 25 l 4.46429,-12.5 h -25 z m 50,0 -4.46429,12.5 -17.85714,49.9999997 h 12.5 l 8.92857,-24.9999997 h 12.5 l 4.46429,-12.5 h -12.5 l 4.46428,-12.5 h 25 l 4.46429,-12.5 z"
+         id="rect1519" />
+    </g>
+  </g>
+</svg>
index a37944f99e0b16ca02e98f6bf5e48e73e781c23d..e050fb8e50fc4c541b361a5a5c489b5b3d34208f 100644 (file)
@@ -234,6 +234,7 @@ object TestAuthProvider : AuthProvider {
                                                                discordId = credentials.name,
                                                                discordName = "",
                                                                discordDiscriminator = "0000",
+                                                               discordAvatar = null,
                                                                profileName = "Test User"
                                                        ).also {
                                                                User.put(it)
@@ -387,14 +388,17 @@ class ProductionAuthProvider(val discordLogin: DiscordLogin) : AuthProvider {
                                        val discordId = (userInfo["id"] as? JsonPrimitive)?.content ?: redirect("/login")
                                        val discordUsername = (userInfo["username"] as? JsonPrimitive)?.content ?: redirect("/login")
                                        val discordDiscriminator = (userInfo["discriminator"] as? JsonPrimitive)?.content ?: redirect("/login")
+                                       val discordAvatar = (userInfo["avatar"] as? JsonPrimitive)?.content
                                        
                                        val user = User.locate(User::discordId eq discordId)?.copy(
                                                discordName = discordUsername,
-                                               discordDiscriminator = discordDiscriminator
+                                               discordDiscriminator = discordDiscriminator,
+                                               discordAvatar = discordAvatar
                                        ) ?: User(
                                                discordId = discordId,
                                                discordName = discordUsername,
                                                discordDiscriminator = discordDiscriminator,
+                                               discordAvatar = discordAvatar,
                                                profileName = discordUsername
                                        )
                                        
@@ -405,10 +409,8 @@ class ProductionAuthProvider(val discordLogin: DiscordLogin) : AuthProvider {
                                                expirationMillis = System.currentTimeMillis() + 86_400_000
                                        )
                                        
-                                       launch {
-                                               User.put(user)
-                                               UserSession.put(userSession)
-                                       }
+                                       launch { User.put(user) }
+                                       launch { UserSession.put(userSession) }
                                        
                                        call.sessions.set(userSession.id)
                                        redirect("/me")
index b5b9b19c030289df099341f94ee7f17118b5ec50..019e1e3ab7e1f334dfaca9378d2736b626d978ed 100644 (file)
@@ -15,9 +15,15 @@ data class User(
        val discordId: String,
        val discordName: String,
        val discordDiscriminator: String,
+       val discordAvatar: String?,
        val profileName: String,
        val status: UserStatus = UserStatus.AVAILABLE,
 ) : DataDocument<User> {
+       val discordAvatarUrl: String
+               get() = discordAvatar?.let {
+                       "https://cdn.discordapp.com/avatars/$discordId/$it." + (if (it.startsWith("a_")) "gif" else "png") + "?size=256"
+               } ?: "https://cdn.discordapp.com/embed/avatars/${discordDiscriminator.last().digitToInt() % 5}.png"
+       
        companion object Table : DocumentTable<User> by DocumentTable.create({
                unique(User::discordId)
        })
index 6c6df5ab9cef800582bcd65df47c43eb5abc4092..02716bfa026dafe4bee8e40a149598a47f0a86fc 100644 (file)
@@ -31,31 +31,28 @@ suspend fun ApplicationCall.userPage(): HTML.() -> Unit {
        val admirals = Admiral.select(Admiral::owningUser eq user.id).toList()
        
        return page(
-               user.profileName, standardNavBar(), if (isCurrentUser)
-                       PageNavSidebar(
-                               listOf(
-                                       NavLink("/admiral/new", "New Admiral"),
-                               )
-                       )
-               else null
-       ) {
-               section {
-                       h1 { +user.profileName }
+               user.profileName, standardNavBar(), CustomSidebar {
+                       img(src = user.discordAvatarUrl)
                        p {
+                               style = "text-align:center"
                                +user.discordName
                                +"#"
                                +user.discordDiscriminator
                        }
-                       
-                       if (isCurrentUser)
+                       if (user.discordId == CurrentConfiguration.discordClient?.ownerId)
                                p {
-                                       +"This user is you!"
+                                       style = "text-align:center"
+                                       +"Site Owner"
                                }
-                       
-                       if (user.discordId == CurrentConfiguration.discordClient?.ownerId)
+                       if (isCurrentUser)
                                p {
-                                       +"This user is the owner of the site!"
+                                       style = "text-align:center"
+                                       a(href = "/admiral/new") { +"Create New Admiral" }
                                }
+               }
+       ) {
+               section {
+                       h1 { +user.profileName }
                        
                        if (admirals.isNotEmpty()) {
                                p {