Skip to content

Commit

Permalink
fix warns
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic committed Oct 7, 2024
1 parent 5b353f2 commit 4b72732
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
21 changes: 10 additions & 11 deletions app/controllers/LoginController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ class LoginController @Inject() (
SeeOther(routes.LoginController.passwordPage.url)
)
)
LoginAction.readUserRights(user).map { userRights =>
val loginToken =
LoginToken
.forUserId(user.id, config.tokenExpirationInMinutes, request.remoteAddress)
// userSession = none since there are no session around
val requestWithUserData =
new RequestWithUserData(user, userRights, none, request)
magicLinkAuth(loginToken, user.email, requestWithUserData.some)
}
else
LoginAction.readUserRights(user).map { userRights =>
val loginToken =
LoginToken
.forUserId(user.id, config.tokenExpirationInMinutes, request.remoteAddress)
// userSession = none since there are no session around
val requestWithUserData =
new RequestWithUserData(user, userRights, none, request)
magicLinkAuth(loginToken, user.email, requestWithUserData.some)
}
}
}
}
Expand Down Expand Up @@ -284,8 +285,6 @@ class LoginController @Inject() (
// Note: we remove the password on purpose here
val form =
PasswordCredentials.form.fill(PasswordCredentials(credentials.email, ""))
val message =
"Connexion impossible : mot de passe invalide, compte inexistant ou désactivé"
Future.successful(
addingPasswordEmailToSession(credentials.email.some)(
BadRequest(
Expand Down
2 changes: 1 addition & 1 deletion app/helper/PasswordHasher.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package helper

import de.mkammerer.argon2.{Argon2, Argon2Factory}
import de.mkammerer.argon2.Argon2Factory
import scala.util.Try

object PasswordHasher {
Expand Down
11 changes: 4 additions & 7 deletions app/services/PasswordService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import modules.AppConfig
import play.api.db.Database
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.util.Try

@Singleton
class PasswordService @Inject() (
Expand Down Expand Up @@ -111,7 +110,7 @@ class PasswordService @Inject() (
ipAddress = ipAddress,
used = false,
)
SQL"""
val _ = SQL"""
INSERT INTO password_recovery_token (
token,
user_id,
Expand Down Expand Up @@ -171,7 +170,6 @@ class PasswordService @Inject() (
EventType.PasswordTokenError,
"Impossible de vérifier le token de changement de mot de passe",
) { implicit connection =>
import anorm.SqlParser._
SQL(
s"""SELECT $passwordRecoveryTokenFieldsInSelect,
host(ip_address)::TEXT AS ip_address
Expand All @@ -190,7 +188,6 @@ class PasswordService @Inject() (
EventType.PasswordTokenError,
"Impossible de changer le mot de passe",
) { implicit connection =>
import anorm.SqlParser._
val userInfos = SQL(
s"""SELECT "user".id, "user".email
FROM password_recovery_token, "user"
Expand All @@ -201,7 +198,7 @@ class PasswordService @Inject() (
AND NOT "user".disabled"""
)
.on("token" -> token.take(100))
.as((get[UUID]("id") ~ get[String]("email")).singleOpt)
.as((SqlParser.get[UUID]("id") ~ SqlParser.get[String]("email")).singleOpt)
userInfos match {
case Some(userId ~ userEmail) =>
PasswordHasher
Expand All @@ -218,7 +215,7 @@ class PasswordService @Inject() (
.asLeft,
hash => {
val now = Instant.now()
SQL"""INSERT INTO password (
val _ = SQL"""INSERT INTO password (
user_id,
password_hash,
last_update
Expand All @@ -230,7 +227,7 @@ class PasswordService @Inject() (
ON CONFLICT (user_id)
DO UPDATE SET password_hash = ${hash}, last_update = ${now}
""".executeUpdate()
SQL"""UPDATE password_recovery_token
val _ = SQL"""UPDATE password_recovery_token
SET used = true
WHERE token = ${token}
""".executeUpdate()
Expand Down
1 change: 0 additions & 1 deletion app/services/SqlHelpers.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package services

import anorm._
import cats.syntax.all._
import java.sql.Connection
import models.{Error, EventType}
Expand Down
9 changes: 3 additions & 6 deletions app/views/password.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package views

import cats.syntax.all._
import constants.Constants
import controllers.routes.{Assets, HomeController, LoginController}
import controllers.routes.{HomeController, LoginController}
import helpers.forms.CSRFInput
import models.forms.{PasswordChange, PasswordCredentials, PasswordRecovery}
import org.webjars.play.WebJarsUtil
import play.api.data.Form
import play.api.i18n.MessagesProvider
import play.api.mvc.{Flash, RequestHeader}
import play.api.mvc.RequestHeader
import scalatags.Text.all._
import scalatags.Text.tags2

object password {

Expand All @@ -28,7 +25,7 @@ object password {
p(cls := "fr-hr-or")("ou"),
div(
a(
href := "/",
href := HomeController.index.url,
"Revenir à la page d’accueil pour se connecter avec un lien à usage unique."
)
)
Expand Down

0 comments on commit 4b72732

Please sign in to comment.