<commit_before>package services

import _root_.java.sql.{Timestamp, Date}
import anorm.SqlParser._
import anorm._
import org.joda.time.format.{DateTimeFormat, DateTimeFormatter}
import play.api.db.DB
import securesocial.core._
import securesocial.core.PasswordInfo
import anorm.~
import securesocial.core.providers.MailToken
import org.joda.time.DateTime
import play.api.Play.current
import models.{UserUsage, UserLevel, User}
import securesocial.core.services.{SaveMode, UserService}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}


class PigionUserService extends UserService[User] {

  implicit def tuple2OAuth1Info(tuple: (Option[String], Option[String])): Option[OAuth1Info] =
    tuple match {
      case (Some(token), Some(secret)) => Some(OAuth1Info(token, secret))
      case _ => None
    }

  implicit def tuple2OAuth2Info(tuple: (Option[String], Option[String], Option[Int], Option[String])) =
    tuple match {
      case (Some(token), tokenType, expiresIn, refreshToken) =>
        Some(OAuth2Info(token, tokenType, expiresIn, refreshToken))
      case _ => None
    }

  implicit def tuple2PasswordInfo(tuple: (Option[String], Option[String], Option[String])): Option[PasswordInfo] =
    tuple match {
      case (Some(hasher), Some(password), salt) =>
        Some(PasswordInfo(hasher, password, salt))
      case _ => None
    }

  val user: RowParser[User] = {
    get[Long]("seqId") ~
      get[String]("userId") ~
      get[String]("providerId") ~
      get[Option[String]]("firstName") ~
      get[Option[String]]("lastName") ~
      get[Option[String]]("fullName") ~
      get[Option[String]]("email") ~
      get[Option[String]]("avatarUrl") ~
      get[String]("authenticationMethod") ~
      get[Option[String]]("oAuth1Token") ~
      get[Option[String]]("oAuth1Secret") ~
      get[Option[String]]("oAuth2AccessToken") ~
      get[Option[String]]("oAuth2TokenType") ~
      get[Option[Int]]("oAuth2ExpiresIn") ~
      get[Option[String]]("oAuth2RefreshToken") ~
      get[Option[String]]("passwordHasher") ~
      get[Option[String]]("password") ~
      get[Option[String]]("passwordSalt") ~
      get[Long]("userLevelSeqId") ~
      get[Long]("maxActiveUploads")~
      get[Long]("maxActiveUploadBytes") map {
      case seqId ~ userId ~ providerId ~ firstName ~ lastName ~ fullName ~ email ~ avatarUrl ~
        authenticationMethod ~ oAuth1Token ~ oAuth1Secret ~ oAuth2AccessToken ~ oAuth2TokenType ~
        oAuth2ExpiresIn ~ oAuth2RefreshToken ~ passwordHasher ~ password ~ passwordSalt ~
        userLevelSeqId ~ maxActiveDownloads ~ maxActiveUploadBytes =>
        User(seqId, BasicProfile(providerId, userId, firstName, lastName, fullName, email, avatarUrl, AuthenticationMethod(authenticationMethod),
          Option(OAuth1Info(oAuth1Token.getOrElse(""), oAuth1Secret.getOrElse(""))), Option(OAuth2Info(oAuth2AccessToken.getOrElse(""), oAuth2TokenType, oAuth2ExpiresIn, oAuth2RefreshToken)),
          Option(PasswordInfo(passwordHasher.getOrElse(""), password.getOrElse(""), passwordSalt))), UserLevel(userLevelSeqId, maxActiveDownloads, maxActiveUploadBytes))
    }
  }

  val userUsage: RowParser[UserUsage] = {
    get[Option[Long]]("currentActiveUploads") ~
    get[Option[Long]]("currentActiveUploadBytes") map {
      case currentActiveUploads ~ currentActiveUploadBytes =>
        UserUsage(currentActiveUploads, currentActiveUploadBytes)
    }
  }

  val mailToken: RowParser[MailToken] = {
    get[String]("uuid") ~
      get[String]("email") ~<commit_msg>modifying the user row parser to optionally get the user level information in case we are just setting up<commit_after>package services

import _root_.java.sql.{Timestamp, Date}
import anorm.SqlParser._
import anorm._
import org.joda.time.format.{DateTimeFormat, DateTimeFormatter}
import play.api.db.DB
import securesocial.core._
import securesocial.core.PasswordInfo
import anorm.~
import securesocial.core.providers.MailToken
import org.joda.time.DateTime
import play.api.Play.current
import models.{UserUsage, UserLevel, User}
import securesocial.core.services.{SaveMode, UserService}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}


class PigionUserService extends UserService[User] {

  implicit def tuple2OAuth1Info(tuple: (Option[String], Option[String])): Option[OAuth1Info] =
    tuple match {
      case (Some(token), Some(secret)) => Some(OAuth1Info(token, secret))
      case _ => None
    }

  implicit def tuple2OAuth2Info(tuple: (Option[String], Option[String], Option[Int], Option[String])) =
    tuple match {
      case (Some(token), tokenType, expiresIn, refreshToken) =>
        Some(OAuth2Info(token, tokenType, expiresIn, refreshToken))
      case _ => None
    }

  implicit def tuple2PasswordInfo(tuple: (Option[String], Option[String], Option[String])): Option[PasswordInfo] =
    tuple match {
      case (Some(hasher), Some(password), salt) =>
        Some(PasswordInfo(hasher, password, salt))
      case _ => None
    }

  val user: RowParser[User] = {
    get[Long]("seqId") ~
      get[String]("userId") ~
      get[String]("providerId") ~
      get[Option[String]]("firstName") ~
      get[Option[String]]("lastName") ~
      get[Option[String]]("fullName") ~
      get[Option[String]]("email") ~
      get[Option[String]]("avatarUrl") ~
      get[String]("authenticationMethod") ~
      get[Option[String]]("oAuth1Token") ~
      get[Option[String]]("oAuth1Secret") ~
      get[Option[String]]("oAuth2AccessToken") ~
      get[Option[String]]("oAuth2TokenType") ~
      get[Option[Int]]("oAuth2ExpiresIn") ~
      get[Option[String]]("oAuth2RefreshToken") ~
      get[Option[String]]("passwordHasher") ~
      get[Option[String]]("password") ~
      get[Option[String]]("passwordSalt") ~
      get[Option[Long]]("userLevelSeqId") ~
      get[Option[Long]]("maxActiveUploads")~
      get[Option[Long]]("maxActiveUploadBytes") map {
      case seqId ~ userId ~ providerId ~ firstName ~ lastName ~ fullName ~ email ~ avatarUrl ~
        authenticationMethod ~ oAuth1Token ~ oAuth1Secret ~ oAuth2AccessToken ~ oAuth2TokenType ~
        oAuth2ExpiresIn ~ oAuth2RefreshToken ~ passwordHasher ~ password ~ passwordSalt ~
        userLevelSeqId ~ maxActiveDownloads ~ maxActiveUploadBytes =>
        User(seqId, BasicProfile(providerId, userId, firstName, lastName, fullName, email, avatarUrl, AuthenticationMethod(authenticationMethod),
          Option(OAuth1Info(oAuth1Token.getOrElse(""), oAuth1Secret.getOrElse(""))), Option(OAuth2Info(oAuth2AccessToken.getOrElse(""), oAuth2TokenType, oAuth2ExpiresIn, oAuth2RefreshToken)),
          Option(PasswordInfo(passwordHasher.getOrElse(""), password.getOrElse(""), passwordSalt))), UserLevel(userLevelSeqId.getOrElse(-1), maxActiveDownloads.getOrElse(-1), maxActiveUploadBytes.getOrElse(-1)))
    }
  }

  val userUsage: RowParser[UserUsage] = {
    get[Option[Long]]("currentActiveUploads") ~
    get[Option[Long]]("currentActiveUploadBytes") map {
      case currentActiveUploads ~ currentActiveUploadBytes =>
        UserUsage(currentActiveUploads, currentActiveUploadBytes)
    }
  }

  val mailToken: RowParser[MailToken] = {
    get[String]("uuid") ~
      get[String]("email") ~
{'fraction_non_alphanumeric': 0.13660293710169022, 'fraction_numerical': 0.008174009420892215, 'mean_word_length': 4.724821570182395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5432674', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2232, 'n_words': 376}