我正在开发一个Web应用程序,最终用户必须为其创建一个帐户.这部分非常简单:我将使用SHA-256对密码进行哈希处理,以便除了用户自己以外没有人知道密码.现在来了困难的部分.用户创建帐户后,他/她必须提供他/她的电子邮件服务器的密码.现在的问题是:我如何正确地保护这个密码(密码将存储在数据库中)?如果我使用TripleDES加密密码,任何开发人员或系统管理员都可以解密密码并查看密码.处理这种问题的常用方法是什么?非常感谢.
我试图理解Slick如何工作以及如何使用它...并在GitHub中查看他们的示例我最终在MultiDBCakeExample.scala中使用了这段代码:
trait PictureComponent { this: Profile => //requires a Profile to be mixed in...
import profile.simple._ //...to be able import profile.simple._
object Pictures extends Table[(String, Option[Int])]("PICTURES") {
...
def * = url ~ id
val autoInc = url returning id into { case (url, id) => Picture(url, id) }
def insert(picture: Picture)(implicit session: Session): Picture = {
autoInc.insert(picture.url)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想该*
方法在表中返回一行,同时autoInc
应该以某种方式提供自动递增实体ID的功能......但说实话,我在理解这段代码时遇到了一些麻烦.什么returning
指的是?什么autoInc
回报?
我查看了Slick文档但我无法找到有用的信息.任何帮助将非常感激 ;-)
我需要为Play应用程序配置一些URL,所以我将它们添加到application.conf
:
application.url="http://www.mydomain.com"
application.url.images="http://www.anotherdomain.com"
application.url.images.logo="${application.url.images}/logo.png"
...
Run Code Online (Sandbox Code Playgroud)
以下是我在视图中用于访问上述条目的代码:
@(title: String)
@import play.api.Play.current
<!DOCTYPE html>
<html>
...
<img src="@{ currrent.configuration.getString("application.url.images.logo") }" />
...
</html>
Run Code Online (Sandbox Code Playgroud)
嗯...我疯了,因为每当我运行应用程序时,我总是收到以下错误消息:
/home/j3d/Projects/test-app/conf/application.conf: 14-19: application.url.images.logo has type OBJECT rather than STRING
Run Code Online (Sandbox Code Playgroud)
任何的想法?我错过了什么吗?或者这是一个错误?
非常感谢你.
我需要一个正则表达式匹配数字列表和另一个匹配数字范围(表达式在这两种情况下都不会失败).范围应由数字,短划线和另一个数字(NN)组成,而列表应由逗号(N,N,N)分隔的数字组成.以下是一些例子.
范围:
'1-10' => OK
Whateverelse => NOK (e.g. '1-10 11-20')
Run Code Online (Sandbox Code Playgroud)
列表:
'1,2,3' => OK
Whateverelse => NOK
Run Code Online (Sandbox Code Playgroud)
这是我的两个正则表达式:
...但我有一些问题...例如:
在评估时'1-10'
,regex 2匹配1
......但它不应该匹配任何东西,因为字符串不包含列表.
然后,在评估时'1-10 11-14'
,正则表达式1匹配1-10
...但它不应该匹配任何东西,因为字符串包含的不仅仅是一个范围.
我错过了什么?谢谢.
下面是我尝试实现一个提供压缩/解压缩字符串功能的类:
object GZipHelper {
def deflate(txt: String): Try[String] = {
try {
val arrOutputStream = new ByteArrayOutputStream()
val zipOutputStream = new GZIPOutputStream(arrOutputStream)
zipOutputStream.write(txt.getBytes)
new Success(Base64.encodeBase64String(arrOutputStream.toByteArray))
} catch {
case _: e => new Failure(e)
}
}
def inflate(deflatedTxt: String): Try[String] = {
try {
val bytes = Base64.decodedBase64(deflatedTxt)
val zipInputStream = GZIPInputStream(new ByteArrayInputStream(bytes))
new success(IOUtils.toString(zipInputStream))
} catch {
case _: e => new Failure(e)
}
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的finally
那样,关闭GZIPOutputStream
和GZIPInputStream
丢失的块......我怎么能以"scala"的方式实现它呢?我怎么能改进代码?
给定以下scala序列...
val numbers = Seq[(String, JsValue)](("one", JsNumber(1)), ("two", JsNumber(2)), ("three", JsNumber(3)))
Run Code Online (Sandbox Code Playgroud)
...我需要将其转换为以下JSON:
{
"numbers": {
"one": 1,
"two": 2,
"three": 3
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过了...
val js = Json.obj("numbers" -> Json.obj(numbers))
Run Code Online (Sandbox Code Playgroud)
...但是它不起作用,并且出现以下错误:
found: Seq[(String, JsValue)]
required: (String, JsValueWrapper)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有一个带有几个模块的Play应用程序,每个模块都有自己的异常集.以下是三个例子:
模块common
:
package services.common
trait CommonErrors {
final case class NotFound(id: String) extends Exception(s"object $id not found")
final case class InvalidId(id: String) extends Exception(s"$id is an invalid id")
...
// `toJson` is just an extension method that converts an exception to JSON
def toResult(e: Exception): Result = e match {
case NotFound => Results.NotFound(e.toJson)
case InvalidId => Results.BadRequest(e.toJson)
case _ => Results.InternalError(e.toJson)
}
}
Run Code Online (Sandbox Code Playgroud)
模块auth
:
package services.auth
trait AuthErrors {
final case class UserNotFound(e: NotFound) extends …
Run Code Online (Sandbox Code Playgroud) 给出一个Order
对象列表......
case class Order(val id: String, val orderType: Option[String])
case class Transaction (val id: String, ...)
val orders = List(Order(1, Some("sell")), Order(2, None), ...)
Run Code Online (Sandbox Code Playgroud)
...我需要Future
为所有具有类型(即已orderType
定义)的订单创建一个s 序列:
val transactions: Seq[Future[Transaction]] = orders.filter(
_.orderType.isDefined).map { case order =>
trxService.findTransactions(order.id) // this returns a Future[Transaction]
}
)
Run Code Online (Sandbox Code Playgroud)
上面的代码首先调用filter
,它创建一个新List
的只包含orderType
设置为的订单Some
,然后从中创建一个Future
s 序列.有没有更有效的方法来实现这一目标?
下面是docker-compose.yml
我用来 dockerize 我的 MongoDB 实例的代码:
version: '3.3'
services:
mongo:
image: 'mongo:latest'
ports:
- '27017:27017'
volumes:
- 'data-storage:/data/db'
networks:
mynet:
volumes:
data-storage:
networks:
mynet:
Run Code Online (Sandbox Code Playgroud)
容器已正确创建,并且启动时没有任何问题。是否可以在容器第一次启动时创建一个 Mongo 集合并用一些文档填充它?
例如,我想运行一些这样的语句:
db.strategyitems.insert( { symbol: "chf", eval_period: 15, buy_booster: 8.0, sell_booster: 5.0, buy_lot: 0.2, sell_lot: 0.2 } )
db.strategyitems.insert( { symbol: "eur", eval_period: 15, buy_booster: 8.0, sell_booster: 5.0, buy_lot: 0.2, sell_lot: 0.2 } )
db.strategyitems.insert( { symbol: "usd", eval_period: 15, buy_booster: 8.0, sell_booster: 5.0, buy_lot: 0.2, sell_lot: 0.2 } )
Run Code Online (Sandbox Code Playgroud)
...
我有许多控制器,它们有很多处理事务的方法...并且我想将所有控制器的事务超时设置为 60:
@AllArgsConstructor
@Controller
public class MyController {
@Transactional(timeout = 60)
public void myMethod1(...) {
}
@Transactional(timeout = 60)
public void myMethod2(...) {
}
...
}
Run Code Online (Sandbox Code Playgroud)
如何将全局默认超时设置为 60,以便不再需要timeout = 60
为每个方法指定?
scala ×5
database ×1
docker ×1
encryption ×1
future ×1
json ×1
mongodb ×1
passwords ×1
regex ×1
slick ×1
spring-boot ×1
transactions ×1