diff --git a/app/controllers/LoginController.scala b/app/controllers/LoginController.scala index b80bf920..93706bc0 100644 --- a/app/controllers/LoginController.scala +++ b/app/controllers/LoginController.scala @@ -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) + } } } } @@ -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( diff --git a/app/helper/PasswordHasher.scala b/app/helper/PasswordHasher.scala index 56be4ce9..24478119 100644 --- a/app/helper/PasswordHasher.scala +++ b/app/helper/PasswordHasher.scala @@ -1,6 +1,6 @@ package helper -import de.mkammerer.argon2.{Argon2, Argon2Factory} +import de.mkammerer.argon2.Argon2Factory import scala.util.Try object PasswordHasher { diff --git a/app/services/PasswordService.scala b/app/services/PasswordService.scala index c5a67314..e4d368ff 100644 --- a/app/services/PasswordService.scala +++ b/app/services/PasswordService.scala @@ -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() ( @@ -111,7 +110,7 @@ class PasswordService @Inject() ( ipAddress = ipAddress, used = false, ) - SQL""" + val _ = SQL""" INSERT INTO password_recovery_token ( token, user_id, @@ -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 @@ -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" @@ -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 @@ -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 @@ -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() diff --git a/app/services/SqlHelpers.scala b/app/services/SqlHelpers.scala index 7a1c39fd..934b719c 100644 --- a/app/services/SqlHelpers.scala +++ b/app/services/SqlHelpers.scala @@ -1,6 +1,5 @@ package services -import anorm._ import cats.syntax.all._ import java.sql.Connection import models.{Error, EventType} diff --git a/app/views/password.scala b/app/views/password.scala index 44e0f88c..e93e5db0 100644 --- a/app/views/password.scala +++ b/app/views/password.scala @@ -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 { @@ -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." ) )