~jan0sch/smederee

Showing details for patch 5239d46b8e0412118239fc3d3f960891c05fe868.
2022-10-01 (Sat), 9:27 AM - Jens Grassel - 5239d46b8e0412118239fc3d3f960891c05fe868

Verification: Prohibit repo creation for unverified account

If an account is not verified (verifiedEmail) then an error message is shown
instead of the create repository form. Also the parse route for the form
checks the flag an quits with an error (raiseError).
Summary of changes
1 files added
  • modules/hub/src/main/twirl/de/smederee/hub/views/errors/unverifiedAccount.scala.html
2 files modified with 19 lines added and 5 lines removed
  • modules/hub/src/main/resources/messages_en.properties with 3 added and 1 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 16 added and 4 removed lines
diff -rN -u old-smederee/modules/hub/src/main/resources/messages_en.properties new-smederee/modules/hub/src/main/resources/messages_en.properties
--- old-smederee/modules/hub/src/main/resources/messages_en.properties	2025-02-02 03:48:35.869296804 +0000
+++ new-smederee/modules/hub/src/main/resources/messages_en.properties	2025-02-02 03:48:35.869296804 +0000
@@ -10,7 +10,8 @@
 # 2. Grouping continues downward if it makes sense, e.g.
 #    error.forbidden.title, error.forbidden.message.
 #
-errors.forbidden.title = 403 - Forbidden
+errors.account.not-verified=Sorry, but your account has not been verified and is therefore not allowed to perform the desired action. Please verify your account.
+errors.forbidden.title=403 - Forbidden
 
 # Forms
 form.create-repo.button.submit=Create repository
@@ -45,6 +46,7 @@
 # Global / generic translations
 global.contact=Contact
 global.copyright=© 2022 Wegtam GmbH
+global.error=Error
 global.imprint=Imprint/Impressum
 global.login=Login
 global.logout=Logout
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-02-02 03:48:35.869296804 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-02-02 03:48:35.873296811 +0000
@@ -702,6 +702,11 @@
       ar.req.decodeStrict[F, UrlForm] { urlForm =>
         for {
           csrf <- Sync[F].delay(ar.req.getCsrfToken)
+          _ <- Sync[F].raiseUnless(user.verifiedEmail)(
+            new Error(
+              "An unverified account is not allowed to create a repository!"
+            ) // FIXME Proper error handling!
+          )
           formData <- Sync[F].delay {
             urlForm.values.map { t =>
               val (key, values) = t
@@ -806,10 +811,17 @@
     case ar @ GET -> Root / "repo" / "create" as user =>
       for {
         csrf <- Sync[F].delay(ar.req.getCsrfToken)
-        resp <- Ok(
-          views.html
-            .createRepository()(createRepoPath, csrf, "Smederee - Create a new repository".some, user)()
-        )
+        resp <- user.verifiedEmail match {
+          case false =>
+            Forbidden(
+              views.html.errors.unverifiedAccount()(csrf, "Smederee - Account not verified!".some, user)
+            )
+          case true =>
+            Ok(
+              views.html
+                .createRepository()(createRepoPath, csrf, "Smederee - Create a new repository".some, user)()
+            )
+        }
       } yield resp
   }
 
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/errors/unverifiedAccount.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/errors/unverifiedAccount.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/errors/unverifiedAccount.scala.html	1970-01-01 00:00:00.000000000 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/errors/unverifiedAccount.scala.html	2025-02-02 03:48:35.873296811 +0000
@@ -0,0 +1,18 @@
+@(baseUri: Uri = Uri(path = Uri.Path.Root), lang: LanguageCode = LanguageCode("en"))(csrf: Option[CsrfToken] = None, title: Option[String] = None, user: Account)
+@main(baseUri, lang)()(csrf, title, user.some) {
+@defining(lang.toLocale) { implicit locale =>
+  <div class="content">
+    <div class="pure-g">
+      <div class="pure-u-1-1 pure-u-md-1-1">
+        <div class="l-box">
+          <p class="alert alert-error">
+            <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
+            <span class="sr-only">@Messages("global.error"):</span>
+            @Messages("errors.account.not-verified")
+          </p>
+        </div>
+      </div>
+    </div>
+  </div>
+}
+}