tangled
alpha
login
or
join now
kacaii.dev
/
senac-brigade-server
0
fork
atom
wip: currently rewriting the project as a full stack application
tangled.org/kacaii.dev/sigo
gleam
0
fork
atom
overview
issues
1
pulls
pipelines
:card_file_box: handle "phone" field in the signup form
kacaii.dev
5 months ago
39752f4f
3f5031bd
+20
-9
3 changed files
expand all
collapse all
unified
split
src
app
routes
signup.gleam
sql
register_new_user.sql
sql.gleam
+14
-5
src/app/routes/signup.gleam
···
6
6
import wisp
7
7
8
8
type SignUp {
9
9
-
SignUp(name: String, registration: String, email: String, password: String)
9
9
+
SignUp(
10
10
+
name: String,
11
11
+
registration: String,
12
12
+
phone_number: String,
13
13
+
email: String,
14
14
+
password: String,
15
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
26
+
})
27
27
+
use phone_number <- form.field("telefone", {
28
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
30
-
31
31
-
form.success(SignUp(name:, registration:, email:, password:))
39
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
84
-
use hashes <- result.try(
92
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
103
+
data.phone_number,
95
104
data.email,
96
96
-
hashes.encoded_hash,
105
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
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
99
-
full_name, registration, email, password_hash
100
100
-
) VALUES ($1, $2, $3, $4)
100
100
+
full_name, registration, phone, email, password_hash
101
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
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
2
-
full_name, registration, email, password_hash
3
3
-
) VALUES ($1, $2, $3, $4)
2
2
+
full_name, registration, phone, email, password_hash
3
3
+
) VALUES ($1, $2, $3, $4, $5)