本文整理汇总了Scala中play.filters.csrf.CSRF.Token类的典型用法代码示例。如果您正苦于以下问题:Scala Token类的具体用法?Scala Token怎么用?Scala Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Token类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: run
//设置package包名称以及导入依赖的类
package controllers
import java.io.File
import loader.{AppApplicationLoader, AppComponents}
import mqtt.MqttConnector
import play.api.test.Helpers._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.test.FakeRequest
import play.api.test.Helpers.{GET, contentAsString, route}
import play.core.{DefaultWebCommands, SourceMapper, WebCommands}
import play.filters.csrf.CSRF.Token
trait IntegrationTest {
var appComponents:BuiltInComponentsFromContext with WithoutMqttAppComponents = null
trait WithoutMqttAppComponents extends AppComponents {
override lazy val mqttConnector = new MqttConnector(null, null, actorSystem) {
override val reconnect = new Runnable {
override def run() = {}
}
}
}
class WithoutMqttApp extends AppApplicationLoader {
override def createApp(context: Context) = {
appComponents = new BuiltInComponentsFromContext(context) with WithoutMqttAppComponents
appComponents
}
}
implicit val app = new WithoutMqttApp()
.load(ApplicationLoader.Context(environment, sourceMapper, webCommands, configuration))
Play.start(app)
def getCsrfToken() = {
val request = FakeRequest(GET, "/data").withHeaders()
val page = route(app, request).get
val content = contentAsString(page)
val name = ("""<input type="hidden" id="csrf_token_name" value="([\w]+)">""".r).findFirstMatchIn(content).get.group(1)
val value = ("""<input type="hidden" id="csrf_token_value" value="([\w-]+)">""".r).findFirstMatchIn(content).get.group(1)
Token(name, value)
}
def sourceMapper: Option[SourceMapper] = None
def environment: Environment = Environment(new File("."), ClassLoader.getSystemClassLoader, Mode.Test)
def webCommands: WebCommands = new DefaultWebCommands
def configuration: Configuration = Configuration.load(Environment(new File("."), ClassLoader.getSystemClassLoader, Mode.Test))
}
开发者ID:vavravl1,项目名称:home_center,代码行数:53,代码来源:IntegrationTest.scala
注:本文中的play.filters.csrf.CSRF.Token类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论