<commit_before>import axios from "axios";
import { generatePassword } from "../password/passwordGenerator";

export function setJWT(jwt) {
  return {
    type: "SET_JWT",
    jwt
  };
}

function getJWT(credentials) {
  return (dispatch, getState) => {
    const { settings } = getState();
    return axios
      .post(
        `${settings.lesspassDatabaseDefaultUrl}/api/tokens/auth/`,
        credentials
      )
      .then(response => {
        dispatch(setJWT(response.data.token));
        return response;
      });
  };
}

function getEncryptedCredentials(credentials) {
  return () => {
    return generatePassword(credentials.password, {
      site: "lesspass.com",
      login: credentials.email,
      options: {
        lowercase: true,
        uppercase: true,
        digits: true,
        symbols: true,
        length: 16,
        counter: 1
      }
    }).then(encryptedPassword => ({
      email: credentials.email,
      password: <PASSWORD>
    }));
  };
}

export function signIn(credentials, encryptCredentials) {
  return dispatch => {
    if (encryptCredentials) {
      return dispatch(getEncryptedCredentials(credentials)).then(
        encryptedCredentials => dispatch(getJWT(encryptedCredentials))
      );
    }
    return dispatch(getJWT(credentials));
  };
}

function register(credentials) {<commit_msg>Fix Android App crashes on sign in<commit_after>import axios from "axios";
import { generatePassword } from "../password/passwordGenerator";

export function setJWT(jwt) {
  return {
    type: "SET_JWT",
    jwt
  };
}

function getJWT(credentials) {
  return (dispatch, getState) => {
    const { settings } = getState();
    return axios
      .post(
        `${settings.lesspassDatabaseDefaultUrl}/api/tokens/auth/`,
        credentials
      )
      .then(response => {
        dispatch(setJWT(response.data.token));
        return response;
      });
  };
}

function getEncryptedCredentials(credentials) {
  return () => {
    return generatePassword(credentials.password, {
      site: "lesspass.com",
      login: credentials.email,
      lowercase: true,
      uppercase: true,
      digits: true,
      symbols: true,
      length: 16,
      counter: 1
    }).then(encryptedPassword => ({
      email: credentials.email,
      password: <PASSWORD>
    }));
  };
}

export function signIn(credentials, encryptCredentials) {
  return dispatch => {
    if (encryptCredentials) {
      return dispatch(getEncryptedCredentials(credentials)).then(
        encryptedCredentials => dispatch(getJWT(encryptedCredentials))
      );
    }
    return dispatch(getJWT(credentials));
  };
}

function register(credentials) {
{'fraction_non_alphanumeric': 0.12311746987951808, 'fraction_numerical': 0.002259036144578313, 'mean_word_length': 2.8619186046511627, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4601431', 'n_tokens_mistral': 778, 'n_tokens_neox': 788, 'n_words': 155}