SecureSocial 3.0-M3自定义登录查看与游戏2.3.9(SecureSocial 3.

2019-10-23 07:18发布

我想使用最新版本的SecureSocial 3.0-M3,以建立一个自定义登录视图和我struggeling与此几天。

正如在secureSocial谷歌集团fotis建议,我创建了扩展ViewTemplates并覆盖所需的方法MyViewTemplates类:

package controllers
import play.api.mvc.{RequestHeader, Request}
import play.twirl.api.Html

import securesocial.core.{BasicProfile, RuntimeEnvironment}
import play.api.data.Form
import play.api.i18n.Lang
import play.api.mvc.Controller
import play.twirl.api._
import securesocial.controllers.ChangeInfo
import securesocial.controllers.RegistrationInfo
import securesocial.controllers.ViewTemplates
import securesocial.core.RuntimeEnvironment
import play.api.mvc.Action
import play.api.Logger
import views.html.index

/**
 * If no license is here then you can whatever you like!
 * and of course I am not liable
 *
 * Created by fotis on 21/08/14.
 */
class MyViewTemplates(env:RuntimeEnvironment[_]) extends ViewTemplates{

  implicit val implicitEnv = env

  override def getLoginPage(form: Form[(String, String)],msg: Option[String] = None)(implicit request: RequestHeader, lang: Lang): Html = {
    Logger.debug("Redirecting to custom view")
    views.html.login(form, msg)(request, lang, env)

  }

  override def getSignUpPage(form: Form[RegistrationInfo], token: String)(implicit request: RequestHeader, lang: Lang): Html = {
    securesocial.views.html.Registration.signUp(form, token)(request, lang, env)
  }

  override def getStartSignUpPage(form: Form[String])(implicit request: RequestHeader, lang: Lang): Html = {
    securesocial.views.html.Registration.startSignUp(form)(request, lang, env)
  }

  override def getStartResetPasswordPage(form: Form[String])(implicit request: RequestHeader, lang: Lang): Html = {
    securesocial.views.html.Registration.startResetPassword(form)(request, lang, env)
  }

  override def getResetPasswordPage(form: Form[(String, String)], token: String)(implicit request: RequestHeader, lang: Lang): Html = {
    securesocial.views.html.Registration.resetPasswordPage(form, token)(request, lang, env)
  }

  override def getPasswordChangePage(form: Form[ChangeInfo])(implicit request: RequestHeader, lang: Lang): Html = {
    securesocial.views.html.passwordChange(form)(request, lang, env)
  }

  override def getNotAuthorizedPage(implicit request: RequestHeader, lang: Lang): Html = {
    securesocial.views.html.notAuthorized()(request, lang, env)
  }


}

我添加了一个登录页面:

@(loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)(implicit request: play.api.mvc.RequestHeader, lang: Lang, env:securesocial.core.RuntimeEnvironment[_])
@import securesocial.core.providers.UsernamePasswordProvider.UsernamePassword
@main(Messages("securesocial.login.title")) {
    <div class="page-header">
        <h1>@Messages("securesocial.login.title")</h1>
    </div>

    @errorMsg.map { msg =>
        <div class="alert alert-error">
            @Messages(msg)
        </div>
    }

    @request.flash.get("success").map { msg =>
        <div class="alert alert-info">
            @msg
        </div>
    }

    @request.flash.get("error").map { msg =>
        <div class="alert alert-error">
            @msg
        </div>
    }


    @defining( env.providers.values.filter( _.id != UsernamePassword) ) { externalProviders =>


        @env.providers.get(UsernamePassword).map { up =>
            <div class="clearfix">
                @if( externalProviders.size > 0 ) {
                    <p>@Messages("securesocial.login.useEmailAndPassword")</p>
                } else {
                    <p>@Messages("securesocial.login.useEmailAndPasswordOnly")</p>
                }

                @securesocial.views.html.provider("userpass", Some(loginForm))
            </div>
        }
    }
}

但这个页面不会被调用。 它总是显示的默认SecurSocial登录页面。

我在想什么? 有没有人有这个版本SecureSocial和定制登录查看完整的代码示例?

非常感谢您的帮助!

Answer 1:

我不得不重写viewTemplates在定制RuntimeEnvironment:

override lazy val viewTemplates: ViewTemplates = MyViewTemplates


文章来源: SecureSocial 3.0-M3 Custom Login view with play 2.3.9