3

I have a DAO method which returns an Future Option, it is like this:

def authenticate(username: String, password: String): Future[Option[User]] = {

    val query = db.run(Users.filter(x => x.email === username && password.isBcrypted(x.password.toString())).result).map(_.headOption)
    query
  }

The problem is, password.isBcrypted(x.password.toString()), where I am trying to get value of x.password, but it is Rep[String], I tried to find how to get the value from Rep[T] but couldnt come up with a solution.

Is there a good way for this?


Solution

val query = db.run(Users.filter(_.email === username).result.map(_.headOption.filter(user => password.isBcrypted(user.password)))).map(_.headOption)
Maverick
  • 2,738
  • 24
  • 91
  • 157

1 Answers1

4

You could check password after getting the result:

Users.filter(_.email === username).result.map(_.headOption.filter(user => password.isBcrypted(user.password)))
Paweł Jurczenko
  • 4,431
  • 2
  • 20
  • 24
  • 1
    Thanks, this works smoothly, but I still have a question as to what is Rep in slick? Is there any easier way to get value out of it? – Maverick Jul 10 '16 at 12:05
  • 1
    `Rep` is a way of representing a column in Slick. It is not something that is used to get values, but something that is used to write queries. – Paweł Jurczenko Jul 10 '16 at 12:50