wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam

:card_file_box: handle "phone" field in the signup form

+20 -9
+14 -5
src/app/routes/signup.gleam
··· 6 6 import wisp 7 7 8 8 type SignUp { 9 - SignUp(name: String, registration: String, email: String, password: String) 9 + SignUp( 10 + name: String, 11 + registration: String, 12 + phone_number: String, 13 + email: String, 14 + password: String, 15 + ) 10 16 } 11 17 12 18 /// 󱐁 A form that decodes the `SignUp` value. ··· 17 23 }) 18 24 use registration <- form.field("matricula", { 19 25 form.parse_string |> form.check_not_empty() 26 + }) 27 + use phone_number <- form.field("telefone", { 28 + form.parse_phone_number |> form.check_not_empty() 20 29 }) 21 30 use email <- form.field("email", { 22 31 form.parse_email |> form.check_not_empty() ··· 27 36 use _ <- form.field("confirma_senha", { 28 37 form.parse_string |> form.check_confirms(password) 29 38 }) 30 - 31 - form.success(SignUp(name:, registration:, email:, password:)) 39 + form.success(SignUp(name:, registration:, phone_number:, email:, password:)) 32 40 }) 33 41 } 34 42 ··· 81 89 signup data: SignUp, 82 90 context ctx: Context, 83 91 ) -> Result(Nil, SignupError) { 84 - use hashes <- result.try( 92 + use hashed_password <- result.try( 85 93 argus.hasher() 86 94 |> argus.hash(data.password, argus.gen_salt()) 87 95 |> result.replace_error(HashFailure), ··· 92 100 ctx.conn, 93 101 data.name, 94 102 data.registration, 103 + data.phone_number, 95 104 data.email, 96 - hashes.encoded_hash, 105 + hashed_password.encoded_hash, 97 106 ) 98 107 |> result.replace_error(InsertError), 99 108 )
+4 -2
src/app/sql.gleam
··· 92 92 arg_2: String, 93 93 arg_3: String, 94 94 arg_4: String, 95 + arg_5: String, 95 96 ) -> Result(pog.Returned(Nil), pog.QueryError) { 96 97 let decoder = decode.map(decode.dynamic, fn(_) { Nil }) 97 98 98 99 "INSERT INTO user_account ( 99 - full_name, registration, email, password_hash 100 - ) VALUES ($1, $2, $3, $4) 100 + full_name, registration, phone, email, password_hash 101 + ) VALUES ($1, $2, $3, $4, $5) 101 102 " 102 103 |> pog.query 103 104 |> pog.parameter(pog.text(arg_1)) 104 105 |> pog.parameter(pog.text(arg_2)) 105 106 |> pog.parameter(pog.text(arg_3)) 106 107 |> pog.parameter(pog.text(arg_4)) 108 + |> pog.parameter(pog.text(arg_5)) 107 109 |> pog.returning(decoder) 108 110 |> pog.execute(db) 109 111 }
+2 -2
src/app/sql/register_new_user.sql
··· 1 1 INSERT INTO user_account ( 2 - full_name, registration, email, password_hash 3 - ) VALUES ($1, $2, $3, $4) 2 + full_name, registration, phone, email, password_hash 3 + ) VALUES ($1, $2, $3, $4, $5)