Search code examples
playframework-2.0securesocial

How to Customize SecureSocial 3.0 Views?


I read this question

I have the same implementation. Not only it does not work, but in debug, I never even enter this code!

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)

}

and

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)
  }
}

I guess my only choice left is to copy paste controllers from secureSocial github code and change the templates called...

any idea ?


Solution

  • You need to tell the play framework to load your environment config. Usually this is done by creating a Module (assuming MyRuntimeEnvironment is defined in package called 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);
        }
    
    
    }
    

    The in your application.conf:

    play.modules.enabled += "modules.EnvironmentModule"
    

    This should bootstrap your customised environment configuration and load your custom templates.