如何自定义 SecureSocial 3.0 视图?
How to Customize SecureSocial 3.0 Views?
我读了这个
我有相同的实现。它不仅不起作用,而且在调试中,我什至从未输入过这段代码!
object MyRuntimeEnvironment extends RuntimeEnvironment.Default[BasicUser] {
override val userService: UserService[BasicUser] = new SlickUserService
override lazy val authenticatorService: AuthenticatorService[BasicUser] = new AuthenticatorService[BasicUser](
new CookieAuthenticatorBuilder[BasicUser](new SlickAuthenticatorStore, idGenerator),
new HttpHeaderAuthenticatorBuilder[BasicUser](new SlickAuthenticatorStore, idGenerator)
)
override lazy val viewTemplates: ViewTemplates = new CustomTemplatesController(this)
}
和
class CustomTemplatesController(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 = {
//securesocial.views.html.login(form, msg)(request, lang, env)
views.html.custom_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)
}
}
我想我剩下的唯一选择是从 secureSocial github 代码复制粘贴控制器并更改名为...
的模板
有什么想法吗?
您需要告诉播放框架加载您的环境配置。通常这是通过创建一个模块来完成的(假设 MyRuntimeEnvironment 在名为 Service 的包中定义):
package modules;
import com.google.inject.AbstractModule;
import securesocial.core.RuntimeEnvironment;
import service.MyRuntimeEnvironment;
public class EnvironmentModule extends AbstractModule{
@Override
protected void configure() {
MyRuntimeEnvironment environment = new MyRuntimeEnvironment();
bind(RuntimeEnvironment.class).toInstance(environment);
}
}
你的 application.conf:
play.modules.enabled += "modules.EnvironmentModule"
这应该bootstrap您的自定义环境配置并加载您的自定义模板。
我读了这个
我有相同的实现。它不仅不起作用,而且在调试中,我什至从未输入过这段代码!
object MyRuntimeEnvironment extends RuntimeEnvironment.Default[BasicUser] {
override val userService: UserService[BasicUser] = new SlickUserService
override lazy val authenticatorService: AuthenticatorService[BasicUser] = new AuthenticatorService[BasicUser](
new CookieAuthenticatorBuilder[BasicUser](new SlickAuthenticatorStore, idGenerator),
new HttpHeaderAuthenticatorBuilder[BasicUser](new SlickAuthenticatorStore, idGenerator)
)
override lazy val viewTemplates: ViewTemplates = new CustomTemplatesController(this)
}
和
class CustomTemplatesController(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 = {
//securesocial.views.html.login(form, msg)(request, lang, env)
views.html.custom_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)
}
}
我想我剩下的唯一选择是从 secureSocial github 代码复制粘贴控制器并更改名为...
的模板有什么想法吗?
您需要告诉播放框架加载您的环境配置。通常这是通过创建一个模块来完成的(假设 MyRuntimeEnvironment 在名为 Service 的包中定义):
package modules;
import com.google.inject.AbstractModule;
import securesocial.core.RuntimeEnvironment;
import service.MyRuntimeEnvironment;
public class EnvironmentModule extends AbstractModule{
@Override
protected void configure() {
MyRuntimeEnvironment environment = new MyRuntimeEnvironment();
bind(RuntimeEnvironment.class).toInstance(environment);
}
}
你的 application.conf:
play.modules.enabled += "modules.EnvironmentModule"
这应该bootstrap您的自定义环境配置并加载您的自定义模板。