SecureSocial的SignUp形式添加额外字段

SecureSocial的SignUp形式添加额外字段

本文介绍了如何以Scala SecureSocial的SignUp形式添加额外字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过我自己的验证在SignUp表单中添加额外字段.我是否要重写所有视图,请从安全社交代码中复制控制器.

How to add extra field in SignUp form with my own validation.Shall I want to rewrite all views ,controllers from secure-social code.

我尝试如下添加我的自定义登录表单.这是正确的方法吗?

I try to add my custom login form as follows.Is it correct way to do?

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

推荐答案

在撰写本文时,SecureSocial不允许您指定用于注册的自定义字段.您有2个选择:

SecureSocial does not allow you to specify custom fields for registration as of this writing. You have 2 options:

  1. 您现在可以做的是,当用户登录(成功注册后)时,将其重定向到可以完成所需信息的页面.我了解这并非在所有情况下都理想,但这是最简单的方法.

  1. What you could do now is when the user logs in (after successful registration) redirect him to a page where he can complete the required information. I understand this might not be ideal in all cases but it's the easiest approach.

编写您自己的注册控制器,以处理您的自定义页面流程.您必须查看内置的Registration控制器并将其用作指南.

Write your own registration controller that handles your custom flow of pages. You'd have to see the built in Registration controller and use it as a guide.

这篇关于如何以Scala SecureSocial的SignUp形式添加额外字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:24