<commit_before>// @flow
import * as Keychain from 'react-native-keychain'

import * as storage from './storage'
import buildFormData from './formdata'
import {OLECARD_AUTH_URL} from './financials/urls'

const SIS_LOGIN_CREDENTIAL_KEY = 'stolaf.edu'

export function saveLoginCredentials(username: string, password: string) {
  return Keychain.setInternetCredentials(
    SIS_LOGIN_CREDENTIAL_KEY,
    username,
    password,
  ).catch(() => ({}))
}
export function loadLoginCredentials(): Promise<{
  username?: string,
  password?: string,
}> {
  return Keychain.getInternetCredentials(SIS_LOGIN_CREDENTIAL_KEY).catch(
    () => ({}),
  )
}
export function clearLoginCredentials() {
  return Keychain.resetInternetCredentials(SIS_LOGIN_CREDENTIAL_KEY).catch(
    () => ({}),
  )
}

export async function isLoggedIn(): Promise<boolean> {
  const result = await Promise.all([
    storage.getTokenValid(),
    storage.getCredentialsValid(),
  ])
  return result.every(result => result === true)
}

export async function performLogin(
  username?: string,
  password?: string,
): Promise<boolean> {
  if (!username || !password) {
    return false
  }

  const form = buildFormData({username, password})
  let loginResult = null
  try {
    loginResult = await fetch(OLECARD_AUTH_URL, {
    method: 'POST',
    body: form,
    })
  } catch (err) {
    return false
  }
  
  const page = await loginResult.text()

  if (page.includes('Password')) {<commit_msg>prettier<commit_after>// @flow
import * as Keychain from 'react-native-keychain'

import * as storage from './storage'
import buildFormData from './formdata'
import {OLECARD_AUTH_URL} from './financials/urls'

const SIS_LOGIN_CREDENTIAL_KEY = 'stolaf.edu'

export function saveLoginCredentials(username: string, password: string) {
  return Keychain.setInternetCredentials(
    SIS_LOGIN_CREDENTIAL_KEY,
    username,
    password,
  ).catch(() => ({}))
}
export function loadLoginCredentials(): Promise<{
  username?: string,
  password?: string,
}> {
  return Keychain.getInternetCredentials(SIS_LOGIN_CREDENTIAL_KEY).catch(
    () => ({}),
  )
}
export function clearLoginCredentials() {
  return Keychain.resetInternetCredentials(SIS_LOGIN_CREDENTIAL_KEY).catch(
    () => ({}),
  )
}

export async function isLoggedIn(): Promise<boolean> {
  const result = await Promise.all([
    storage.getTokenValid(),
    storage.getCredentialsValid(),
  ])
  return result.every(result => result === true)
}

export async function performLogin(
  username?: string,
  password?: string,
): Promise<boolean> {
  if (!username || !password) {
    return false
  }

  const form = buildFormData({username, password})
  let loginResult = null
  try {
    loginResult = await fetch(OLECARD_AUTH_URL, {
      method: 'POST',
      body: form,
    })
  } catch (err) {
    return false
  }

  const page = await loginResult.text()

  if (page.includes('Password')) {
{'fraction_non_alphanumeric': 0.13062908215881747, 'fraction_numerical': 0.0, 'mean_word_length': 4.262206148282098, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '4850615', 'n_tokens_mistral': 918, 'n_tokens_neox': 921, 'n_words': 208}