<commit_before>package pl.softwaremill.bootstrap.dao

import com.mongodb.casbah.WriteConcern
import pl.softwaremill.bootstrap.domain.User
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.MongoDB
import com.mongodb.casbah.commons.{Logging, MongoDBObject}
import com.novus.salat.dao.SalatDAO
import com.novus.salat.global._
import com.mongodb.casbah.query.Imports.ConcreteDBObjectOk
import com.weiglewilczek.slf4s

class MongoUserDAO(implicit val mongo: MongoDB) extends SalatDAO[User, ObjectId](mongo("users")) with UserDAO {

  def loadAll = {
    find(MongoDBObject()).toList
  }

  def countItems(): Long = {
    super.count()
  }

  protected def internalAddUser(user: User) {
    insert(user, WriteConcern.Safe)
  }

  def remove(userId: String) {
    remove(MongoDBObject("_id" -> new ObjectId(userId)), WriteConcern.Safe)
  }

  def load(userId: String): Option[User] = {
    findOne(MongoDBObject("_id" -> new ObjectId(userId)))
  }

  def findByEmail(email: String) = {
    findOne(MongoDBObject("email" -> email.toLowerCase))
  }

  def findByLowerCasedLogin(login: String) = {
    findOne(MongoDBObject("loginLowerCased" -> login.toLowerCase))
  }

  def findByLoginOrEmail(loginOrEmail: String) = {
    findOne($or(MongoDBObject("loginLowerCased" -> loginOrEmail.toLowerCase), MongoDBObject("email" -> loginOrEmail.toLowerCase)))
  }

  def findByToken(token: String) = {
    findOne(MongoDBObject("token" -> token))
  }

  def findByLoginAndEncryptedPassword(login: String, encryptedPassword: String) = {
    findOne(MongoDBObject("loginLowerCased" -> login.toLowerCase, "password" -> encryptedPassword))
  }

  def changePassword(userId: String, password: String) {
    new slf4s.Logging {
      val userOpt = load(userId)
      userOpt.foreach(user => {
        update(MongoDBObject("login" -> user.login), user.copy(password = password), false, false, defaultWriteConcern)
      })
    }
  }
}<commit_msg>#28 Modified UserDAO and implementations<commit_after>package pl.softwaremill.bootstrap.dao

import com.mongodb.casbah.WriteConcern
import pl.softwaremill.bootstrap.domain.User
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.MongoDB
import com.mongodb.casbah.commons.{Logging, MongoDBObject}
import com.novus.salat.dao.SalatDAO
import com.novus.salat.global._
import com.mongodb.casbah.query.Imports.ConcreteDBObjectOk
import com.weiglewilczek.slf4s

class MongoUserDAO(implicit val mongo: MongoDB) extends SalatDAO[User, ObjectId](mongo("users")) with UserDAO {

  def loadAll = {
    find(MongoDBObject()).toList
  }

  def countItems(): Long = {
    super.count()
  }

  protected def internalAddUser(user: User) {
    insert(user, WriteConcern.Safe)
  }

  def remove(userId: String) {
    remove(MongoDBObject("_id" -> new ObjectId(userId)), WriteConcern.Safe)
  }

  def load(userId: String): Option[User] = {
    findOne(MongoDBObject("_id" -> new ObjectId(userId)))
  }

  def findByEmail(email: String) = {
    findOne(MongoDBObject("email" -> email.toLowerCase))
  }

  def findByLowerCasedLogin(login: String) = {
    findOne(MongoDBObject("loginLowerCased" -> login.toLowerCase))
  }

  def findByLoginOrEmail(loginOrEmail: String) = {
    findOne($or(MongoDBObject("loginLowerCased" -> loginOrEmail.toLowerCase), MongoDBObject("email" -> loginOrEmail.toLowerCase)))
  }

  def findByToken(token: String) = {
    findOne(MongoDBObject("token" -> token))
  }

  def findByLoginAndEncryptedPassword(login: String, encryptedPassword: String) = {
    findOne(MongoDBObject("loginLowerCased" -> login.toLowerCase, "password" -> encryptedPassword))
  }

  def changePassword(userId: String, password: String) {
    new slf4s.Logging {
      val userOpt = load(userId)
      userOpt.foreach(user => {
        update(MongoDBObject("_id" -> user._id), user.copy(password = password), false, false, defaultWriteConcern)
      })
    }
  }
}
{'fraction_non_alphanumeric': 0.12728207765492414, 'fraction_numerical': 0.0015428130624839291, 'mean_word_length': 4.597122302158273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '261497', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1323, 'n_words': 218}