如何添加场阶的注册形式SecureSocial(How to add extra field in

2019-10-18 18:02发布

我如何添加字段注册形式与我自己的validation.Shall要重写从安全,社会代码的所有视图,控制器。

我尝试添加自己的自定义登录表单follows.Is它正确的方法呢?

views.custom.SecuFocusTemplatesPlugin

val contactForm = Form(
      mapping(      
        "firstname" -> nonEmptyText(minLength=2, maxLength=64),
        "lastname" -> nonEmptyText(minLength=2, maxLength=64),
        "jobtitle" -> nonEmptyText(minLength=2, maxLength=64),
        "phone" -> nonEmptyText(minLength=2, maxLength=20),      
        "email" -> (email verifying nonEmpty),

        "password" -> tuple(
            "main" -> nonEmptyText(minLength = 6),
            "confirm" -> nonEmptyText(minLength = 6)
        ).verifying(
            // Add an additional constraint: both passwords must match
            "Passwords don't match", ps => ps._1 == ps._2
          ).transform[String]({case (p, _) => p}, {p => p -> p}),

        "companyname" -> nonEmptyText(minLength=2, maxLength=64),
        "employeescount" -> number
      )

      (Contact.apply)(Contact.unapply)
  )

 /**
   * Returns the html for the login page
   * @param request
   * @tparam A
   * @return
   */
  override def getLoginPage[A](implicit request: Request[A], form: Form[(String, String)],
                               msg: Option[String] = None): Html =
  {
    views.html.login(contactForm, msg)
    //securesocial.views.html.login(form, msg)
  }

login.scala.html

@(loginForm: Form[Contact], errorMsg: Option[String] = None)(implicit request: RequestHeader)


@import helper._
@import securesocial.core.Registry
@import securesocial.core.AuthenticationMethod._
@import securesocial.core.providers.UsernamePasswordProvider.UsernamePassword
@import securesocial.views._



@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( Registry.providers.all.values.filter( _.id != UsernamePassword) ) { externalProviders =>

        @if( externalProviders.size > 0 ) {
            <div class="clearfix">
                <p>@Messages("securesocial.login.instructions")</p>
                <p>
                    @for(p <- externalProviders) {
                        @provider(p.id)
                    }
                </p>
            </div>
        }

        @Registry.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>
                }

               @provider("userpass", Some(loginForm))
            </div>
        }
    }
}

Answer 1:

SecureSocial不允许你注册指定自定义字段在写这篇文章的。 你有2种选择:

  1. 你现在可以做的是,当用户登录(注册成功后)重定向他到一个页面,在那里他可以完成所需的信息。 我理解这可能不是在所有情况理想,但它是最简单的方法。

  2. 写你自己的登记控制器来处理页面自定义流程。 你必须看到内置的登记控制器,并使用它作为指导。



文章来源: How to add extra field in SignUp form of scala SecureSocial