<commit_before>jQuery = require 'jquery'
passwordHelper = require '../../lib/password_helper'

module.exports = {
    name: 'password',
    route: 'register/password',
    view : 'steps/password'

    # If OK, return null
    # if not return an Array of errors
    # that will be triggered throw onboarding
    # to dispatch error into app
    validate: (data={}) ->
        errors = {}
        if not data or not data.password
            errors.password = '<PASSWORD>'
        else if data.password
            passwordStrength = passwordHelper.getStrength data.password
            if passwordStrength?.label is 'weak'
                errors.password = '<PASSWORD>'

        if Object.keys(errors).length
            return errors
        else
            return null


    save: (data) ->
        return fetch '/register/password',
            method: 'POST',
            body: JSON.stringify data
        .then @handleSaveSuccess, @handleServerError
}<commit_msg>[fix] Add credentials to password fetch call, for authentication<commit_after>jQuery = require 'jquery'
passwordHelper = require '../../lib/password_helper'

module.exports = {
    name: 'password',
    route: 'register/password',
    view : 'steps/password'

    # If OK, return null
    # if not return an Array of errors
    # that will be triggered throw onboarding
    # to dispatch error into app
    validate: (data={}) ->
        errors = {}
        if not data or not data.password
            errors.password = '<PASSWORD>'
        else if data.password
            passwordStrength = passwordHelper.getStrength data.password
            if passwordStrength?.label is 'weak'
                errors.password = '<PASSWORD>'

        if Object.keys(errors).length
            return errors
        else
            return null


    save: (data) ->
        return fetch '/register/password',
            method: 'POST',
            credentials: 'include',
            body: JSON.stringify data
        .then @handleSaveSuccess, @handleServerError
}
{'fraction_non_alphanumeric': 0.09639149777558081, 'fraction_numerical': 0.0, 'mean_word_length': 2.0900763358778627, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '1444101', 'n_tokens_mistral': 517, 'n_tokens_neox': 499, 'n_words': 166}