All Downloads are FREE. Search and download functionalities are using the official Maven repository.

im.actor.server.persist.UserPasswordRepo.scala Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package im.actor.server.persist

import com.google.protobuf.ByteString
import im.actor.server.db.ActorPostgresDriver.api._
import im.actor.server.model.UserPassword

final class UserPasswordTable(tag: Tag) extends Table[UserPassword](tag, "user_passwords") {
  def userId = column[Int]("user_id", O.PrimaryKey)

  def hash = column[ByteString]("hash")

  def salt = column[ByteString]("salt")

  def * = (userId, hash, salt) <> ((UserPassword.apply _).tupled, UserPassword.unapply)
}

object UserPasswordRepo {
  val userPasswords = TableQuery[UserPasswordTable]

  val byUserId = Compiled { (userId: Rep[Int]) ⇒
    userPasswords filter (_.userId === userId) take 1
  }

  def createOrReplace(userId: Int, hash: Array[Byte], salt: Array[Byte]) =
    userPasswords.insertOrUpdate(UserPassword(userId, ByteString.copyFrom(hash), ByteString.copyFrom(salt)))

  def find(userId: Int) = byUserId(userId).result.headOption
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy