<commit_before>package com.cellarhq.services

import static com.cellarhq.generated.Tables.*

import com.cellarhq.auth.PasswordService
import com.cellarhq.auth.Role
import com.cellarhq.domain.OAuthClient
import com.cellarhq.domain.Cellar
import com.cellarhq.domain.EmailAccount
import com.cellarhq.domain.OAuthAccount
import com.cellarhq.domain.Photo
import com.cellarhq.generated.tables.records.AccountEmailRecord
import com.cellarhq.generated.tables.records.AccountOauthRecord
import com.cellarhq.generated.tables.records.CellarRecord
import com.cellarhq.generated.tables.records.CellarRoleRecord
import com.cellarhq.generated.tables.records.PasswordChangeRequestRecord
import com.cellarhq.generated.tables.records.PhotoRecord
import com.cellarhq.services.photo.PhotoService
import com.cellarhq.services.photo.writer.PhotoWriteFailedException
import com.cellarhq.services.photo.model.ResizeCommand
import com.cellarhq.util.LogUtil
import com.google.inject.Inject
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.jooq.DSLContext
import org.jooq.Record
import org.jooq.impl.DSL
import ratpack.exec.ExecControl
import ratpack.form.UploadedFile

import javax.sql.DataSource
import java.sql.Timestamp
import java.time.LocalDateTime

@Slf4j
@CompileStatic
class AccountService extends BaseJooqService {

    private final PhotoService photoService
    private final PasswordService passwordService

    @Inject
    AccountService(DataSource dataSource,
                   ExecControl execControl,
                   PhotoService photoService,
                   PasswordService passwordService) {
        super(dataSource, execControl)
        this.photoService = photoService
        this.passwordService = passwordService
    }

    OAuthAccount findByCredentials(String username, OAuthClient client = OAuthClient.TWITTER) {
        (OAuthAccount) jooq { DSLContext create ->
            Record result = create.select()
                    .from(ACCOUNT_OAUTH)
                    .join(CELLAR).onKey()
                    .where(ACCOUNT_OAUTH.CLIENT.eq(client.toString()))
                        .and(ACCOUNT_OAUTH.USERNAME.eq(username))
                    .fetchOne()

            if (result) {
                OAuthAccount oAuthAccount = result.into(OAuthAccount)
                oAuthAccount.cellar = result.into(Cellar)
                return oAuthAccount
            }
            return null
        }
    }

    EmailAccount findByEmail(String email) {
        (EmailAccount) jooq { DSLContext create ->
            create.select()
                .from(ACCOUNT_EMAIL)
                .where(ACCOUNT_EMAIL.EMAIL.eq(email))
                .fetchOneInto(EmailAccount)
        }
    }

    EmailAccount findByEmailWithCellar(String email) {
        (EmailAccount) jooq { DSLContext create ->
            Record result = create.select()
                    .from(ACCOUNT_EMAIL)
                    .join(CELLAR).onKey()
                    .where(ACCOUNT_EMAIL.EMAIL.eq(email))
                    .fetchOne()<commit_msg>Email logins are no longer case sensitive.<commit_after>package com.cellarhq.services

import static com.cellarhq.generated.Tables.*

import com.cellarhq.auth.PasswordService
import com.cellarhq.auth.Role
import com.cellarhq.domain.OAuthClient
import com.cellarhq.domain.Cellar
import com.cellarhq.domain.EmailAccount
import com.cellarhq.domain.OAuthAccount
import com.cellarhq.domain.Photo
import com.cellarhq.generated.tables.records.AccountEmailRecord
import com.cellarhq.generated.tables.records.AccountOauthRecord
import com.cellarhq.generated.tables.records.CellarRecord
import com.cellarhq.generated.tables.records.CellarRoleRecord
import com.cellarhq.generated.tables.records.PasswordChangeRequestRecord
import com.cellarhq.generated.tables.records.PhotoRecord
import com.cellarhq.services.photo.PhotoService
import com.cellarhq.services.photo.writer.PhotoWriteFailedException
import com.cellarhq.services.photo.model.ResizeCommand
import com.cellarhq.util.LogUtil
import com.google.inject.Inject
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.jooq.DSLContext
import org.jooq.Record
import org.jooq.impl.DSL
import ratpack.exec.ExecControl
import ratpack.form.UploadedFile

import javax.sql.DataSource
import java.sql.Timestamp
import java.time.LocalDateTime

@Slf4j
@CompileStatic
class AccountService extends BaseJooqService {

    private final PhotoService photoService
    private final PasswordService passwordService

    @Inject
    AccountService(DataSource dataSource,
                   ExecControl execControl,
                   PhotoService photoService,
                   PasswordService passwordService) {
        super(dataSource, execControl)
        this.photoService = photoService
        this.passwordService = passwordService
    }

    OAuthAccount findByCredentials(String username, OAuthClient client = OAuthClient.TWITTER) {
        (OAuthAccount) jooq { DSLContext create ->
            Record result = create.select()
                    .from(ACCOUNT_OAUTH)
                    .join(CELLAR).onKey()
                    .where(ACCOUNT_OAUTH.CLIENT.eq(client.toString()))
                        .and(ACCOUNT_OAUTH.USERNAME.equalIgnoreCase(username))
                    .fetchOne()

            if (result) {
                OAuthAccount oAuthAccount = result.into(OAuthAccount)
                oAuthAccount.cellar = result.into(Cellar)
                return oAuthAccount
            }
            return null
        }
    }

    EmailAccount findByEmail(String email) {
        (EmailAccount) jooq { DSLContext create ->
            create.select()
                .from(ACCOUNT_EMAIL)
                .where(ACCOUNT_EMAIL.EMAIL.equalIgnoreCase(email))
                .fetchOneInto(EmailAccount)
        }
    }

    EmailAccount findByEmailWithCellar(String email) {
        (EmailAccount) jooq { DSLContext create ->
            Record result = create.select()
                    .from(ACCOUNT_EMAIL)
                    .join(CELLAR).onKey()
                    .where(ACCOUNT_EMAIL.EMAIL.equalIgnoreCase(email))
                    .fetchOne()
{'fraction_non_alphanumeric': 0.0768111254851229, 'fraction_numerical': 0.000646830530401035, 'mean_word_length': 2.7303980699638117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4153230', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1711, 'n_words': 293}