<commit_before>module LoginForm exposing (..)

import Html exposing (..)
import Html.App as Html
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import List exposing (..)
import String exposing (..)
import Regex exposing (..)


main : Program Never
main =
    Html.beginnerProgram { model = model, view = view, update = update }



-- MODEL


type alias Model =
    { name : String
    , password : String
    , passwordAgain : String
    }


passwordRegex =
    Regex.regex "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{1,}$"


model : Model
model =
    Model "" "" ""



-- UPDATE


type Msg
    = Name String
    | Password String
    | PasswordAgain String


update : Msg -> Model -> Model
update msg model =
    case msg of
        Name name ->
            { model | name = name }

        Password password ->
            { model | password = password }

        PasswordAgain password ->
            { model | passwordAgain = password }



-- VIEW


view : Model -> Html Msg
view model =
    div []
        [ input [ type' "text", placeholder "Name", onInput Name ] []
        , input [ type' "password", placeholder "Password", onInput Password ] []
        , input [ type' "password", placeholder "Re-enter Password", onInput PasswordAgain ] []
        , viewValidation model
        ]


viewValidation : Model -> Html msg
viewValidation model =
    let
        ( color, messages ) =
            let
                messages =
                    validateModel model
            in
                if List.isEmpty (messages) then
                    ( "green", [ "Ok" ] )
                else
                    ( "red", messages )
    in
        div [ style [ ( "color", color ) ] ] (List.map (\m -> p [] [ (text m) ]) messages)


validateModel : Model -> List String
validateModel model =
    [ ( model.password /= model.passwordAgain, "Passwords do not match" )
    , ( String.length model.password < 8, "Password must be at least 8 characters" )
    , ( Regex.contains (passwordRegex) model.password /= True, "Password must contain at least 1 upper case letter, one lowercase letter, and one number" )
    ]
        |> List.filter fst
        |> List.map snd<commit_msg>Add age input with a greater than zero requirement<commit_after>module LoginForm exposing (..)

import Html exposing (..)
import Html.App as Html
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import List exposing (..)
import String exposing (..)
import Regex exposing (..)


main : Program Never
main =
    Html.beginnerProgram { model = model, view = view, update = update }



-- MODEL


type alias Model =
    { name : String
    , password : String
    , passwordAgain : String
    , age : Int
    }


passwordRegex =
    Regex.regex "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{1,}$"


model : Model
model =
    Model "" "" "" 0



-- UPDATE


type Msg
    = Name String
    | Password String
    | PasswordAgain String
    | Age String


update : Msg -> Model -> Model
update msg model =
    case msg of
        Name name ->
            { model | name = name }

        Password password ->
            { model | password = password }

        PasswordAgain password ->
            { model | passwordAgain = password }

        Age age ->
            let
                ageInt =
                    Result.withDefault 0 (String.toInt age)
            in
                { model | age = ageInt }



-- VIEW


view : Model -> Html Msg
view model =
    div []
        [ input [ type' "text", placeholder "Name", onInput Name ] []
        , input [ type' "password", placeholder "Password", onInput Password ] []
        , input [ type' "password", placeholder "Re-enter Password", onInput PasswordAgain ] []
        , input [ type' "number", onInput Age ] []
        , viewValidation model
        ]


viewValidation : Model -> Html msg
viewValidation model =
    let
        ( color, messages ) =
            let
                messages =
                    validateModel model
            in
                if List.isEmpty (messages) then
                    ( "green", [ "Ok" ] )
                else
                    ( "red", messages )
    in
        div [ style [ ( "color", color ) ] ] (List.map (\m -> p [] [ (text m) ]) messages)


validateModel : Model -> List String
validateModel model =
    [ ( model.password /= model.passwordAgain, "Passwords do not match" )
    , ( String.length model.password < 8, "Password must be at least 8 characters" )
    , ( Regex.contains (passwordRegex) model.password /= True, "Password must contain at least 1 upper case letter, one lowercase letter, and one number" )
    , ( model.age <= 0, "Age must be greater than 0" )
    ]
        |> List.filter fst
        |> List.map snd
{'fraction_non_alphanumeric': 0.11819137749737119, 'fraction_numerical': 0.002523659305993691, 'mean_word_length': 1.9303758471965495, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 26, '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': '2860058', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1294, 'n_words': 435}