diff --git a/src/main/scala/app/IndexController.scala b/src/main/scala/app/IndexController.scala index 1959463..54d5b93 100644 --- a/src/main/scala/app/IndexController.scala +++ b/src/main/scala/app/IndexController.scala @@ -59,7 +59,7 @@ session.setAttribute(Keys.Session.LoginAccount, account) updateLastLoginDate(account.userName) - if(AccountUtil.hasLdapDummyMailAddress(account)) { + if(LDAPUtil.hasLdapDummyMailAddress(account)) { redirect("/" + account.userName + "/_edit") } diff --git a/src/main/scala/util/AccountUtil.scala b/src/main/scala/util/AccountUtil.scala deleted file mode 100644 index e6da429..0000000 --- a/src/main/scala/util/AccountUtil.scala +++ /dev/null @@ -1,18 +0,0 @@ -package util - -import model.Account - -/** - * Utility for account model. - */ -object AccountUtil { - private val LDAP_DUMMY_MAL = "@ldap-devnull" - - def hasLdapDummyMailAddress(account: Account): Boolean = { - account.mailAddress.endsWith(LDAP_DUMMY_MAL) - } - - def getLdapDummyMailAddress(userName: String): String = { - userName + LDAP_DUMMY_MAL - } -} diff --git a/src/main/scala/util/LDAPUtil.scala b/src/main/scala/util/LDAPUtil.scala index 621fbd5..00dd50b 100644 --- a/src/main/scala/util/LDAPUtil.scala +++ b/src/main/scala/util/LDAPUtil.scala @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory import service.SystemSettingsService.Ldap import scala.annotation.tailrec +import model.Account /** * Utility for LDAP authentication. @@ -16,6 +17,26 @@ private val LDAP_VERSION: Int = LDAPConnection.LDAP_V3 private val logger = LoggerFactory.getLogger(getClass().getName()) + private val LDAP_DUMMY_MAL = "@ldap-devnull" + + /** + * Returns true if mail address ends with "@ldap-devnull" + */ + def hasLdapDummyMailAddress(account: Account): Boolean = { + account.mailAddress.endsWith(LDAP_DUMMY_MAL) + } + + /** + * Creates dummy address (userName@ldap-devnull) for LDAP login. + * + * If mail address is not managed in LDAP server, GitBucket stores this dummy address in first LDAP login. + * GitBucket does not send any mails to this dummy address. And these users must input their mail address + * at the first step after LDAP authentication. + */ + def getLdapDummyMailAddress(userName: String): String = { + userName + LDAP_DUMMY_MAL + } + /** * Try authentication by LDAP using given configuration. * Returns Right(LDAPUserInfo) if authentication is successful, otherwise Left(errorMessage). @@ -53,7 +74,7 @@ fullName = ldapSettings.fullNameAttribute.flatMap { fullNameAttribute => findFullName(conn, userDN, ldapSettings.userNameAttribute, userName, fullNameAttribute) }.getOrElse(userName), - mailAddress = AccountUtil.getLdapDummyMailAddress(userName))) + mailAddress = getLdapDummyMailAddress(userName))) } else { findMailAddress(conn, userDN, ldapSettings.userNameAttribute, userName, ldapSettings.mailAttribute.get) match { case Some(mailAddress) => Right(LDAPUserInfo( diff --git a/src/main/scala/util/Notifier.scala b/src/main/scala/util/Notifier.scala index e218800..6ecc3f6 100644 --- a/src/main/scala/util/Notifier.scala +++ b/src/main/scala/util/Notifier.scala @@ -28,7 +28,7 @@ ) .distinct .withFilter ( _ != context.loginAccount.get.userName ) // the operation in person is excluded - .foreach ( getAccountByUserName(_) filterNot (_.isGroupAccount) filterNot (AccountUtil.hasLdapDummyMailAddress(_)) foreach (x => notify(x.mailAddress)) ) + .foreach ( getAccountByUserName(_) filterNot (_.isGroupAccount) filterNot (LDAPUtil.hasLdapDummyMailAddress(_)) foreach (x => notify(x.mailAddress)) ) } diff --git a/src/main/twirl/account/edit.scala.html b/src/main/twirl/account/edit.scala.html index a441f09..599c453 100644 --- a/src/main/twirl/account/edit.scala.html +++ b/src/main/twirl/account/edit.scala.html @@ -1,7 +1,7 @@ @(account: model.Account, info: Option[Any])(implicit context: app.Context) @import context._ @import view.helpers._ -@import util.AccountUtil +@import util.LDAPUtil @html.main("Edit your profile"){