Update part5

This commit is contained in:
Richard Feldman
2018-05-01 21:48:38 -04:00
parent d22a7a9c47
commit 0f673557eb
17 changed files with 111 additions and 18301 deletions

View File

@@ -4,7 +4,7 @@ import Data.AuthToken as AuthToken exposing (AuthToken)
import Data.UserPhoto as UserPhoto exposing (UserPhoto)
import Html exposing (Html)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, required)
import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode exposing (Value)
import Json.Encode.Extra as EncodeExtra
import UrlParser
@@ -16,8 +16,6 @@ type alias User =
, username : Username
, bio : Maybe String
, image : UserPhoto
, createdAt : String
, updatedAt : String
}
@@ -33,8 +31,6 @@ decoder =
|> required "username" usernameDecoder
|> required "bio" (Decode.nullable Decode.string)
|> required "image" UserPhoto.decoder
|> required "createdAt" Decode.string
|> required "updatedAt" Decode.string
encode : User -> Value
@@ -45,8 +41,6 @@ encode user =
, ( "username", encodeUsername user.username )
, ( "bio", EncodeExtra.maybe Encode.string user.bio )
, ( "image", UserPhoto.encode user.image )
, ( "createdAt", Encode.string user.createdAt )
, ( "updatedAt", Encode.string user.updatedAt )
]

View File

@@ -143,7 +143,7 @@ update msg model =
RegisterCompleted (Err error) ->
let
errorMessages =
case error of
case Debug.log "ERROR:" error of
Http.BadStatus response ->
response.body
|> decodeString (field "errors" errorsDecoder)
@@ -186,10 +186,23 @@ modelValidator =
Validate.all
[ ifBlank .username ( Username, "username can't be blank." )
, ifBlank .email ( Email, "email can't be blank." )
, ifBlank .password ( Password, "password can't be blank." )
, Validate.fromErrors passwordLength
]
minPasswordChars : Int
minPasswordChars =
6
passwordLength : Model -> List Error
passwordLength { password } =
if String.length password < minPasswordChars then
[ ( Password, "password must be at least " ++ toString minPasswordChars ++ " characters long." ) ]
else
[]
errorsDecoder : Decoder (List String)
errorsDecoder =
decode (\email username password -> List.concat [ email, username, password ])

View File

@@ -3,4 +3,4 @@ module Request.Helpers exposing (apiUrl)
apiUrl : String -> String
apiUrl str =
"http://0.0.0.0:3000/api" ++ str
"http://localhost:3000/api" ++ str