I'm attempting to verify a given username and password but my query
just returns
all values in the database rather than filtering.
Here's the output when I run the code below:
> Authenticating: (user2, pass2)
> ******** QL Results **********
> User(user1,pass1,true,true)
> User(user2,pass2,false,true)
> QL: SELECT "t1"."name","t1"."password","t1"."isAdmin","t1"."isPrivileged" FROM "WebUsers" "t1","WebUsers" "t2" WHERE (("t2"."name"='user2') and ("t2"."password"='pass2'))
> ********************************
> ******** All Filtered **********
> allFilt matched: user2,pass2
> ********************************
And here's my source code:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++
case class User(name: String, password: String, isAdmin: Boolean,
isPrivileged: Boolean)
object User extends Table[(String, String, Boolean, Boolean)]
("WebUsers") {
lazy val database = Database.forDataSource(DB.getDataSource())
def name = column[String]("name", O NotNull, O PrimaryKey, O DBType
"varchar(64)")
def password = column[String]("password", O NotNull, O DBType
"varchar(64)")
def isAdmin = column[Boolean]("isAdmin", O NotNull)
def isPrivileged = column[Boolean]("isPrivileged", O NotNull)
def * = name ~ password ~ isAdmin ~ isPrivileged
def mapped = * <> ((x1, x2, x3, x4) ⇒ User(x1, x2, x3, x4),
User.unapply)
def authenticate(providedName: String, providedPassword: String) =
database withSession {
implicit db: Session ⇒
{
println("Authenticating: (" + providedName + ", " +
providedPassword + ")")
val ql = for (u ← this if
u.name.is(providedName) &&
u.password.is(providedPassword)) yield mapped
println("******** QL Results **********")
ql.list foreach println
println("QL: " + ql.selectStatement)
println("********************************")
val allFiltered = all.filter(user ⇒
user.name equals
providedName)
println("******** All Filtered **********")
allFiltered.foreach(x ⇒ println("allFilt matched: " +
x.name +
"," + x.password))
println("********************************")
allFiltered match {
case List() ⇒ Option.empty
case head :: tail ⇒ Some(head)
}
}
}
def all = database withSession {
implicit db: Session ⇒
{
(for (u ← this) yield mapped).list
}
}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++