Skip to content

Commit 0d9d671

Browse files
committedJun 1, 2023
add ability for user to have 'full name' added
1 parent a64a7ef commit 0d9d671

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed
 

‎backend/db/models.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ type TimeBase struct {
2525
type User struct {
2626
UUIDBase
2727
TimeBase
28-
Username string `gorm:"uniqueIndex;not null;type:varchar(30)" json:"username"`
29-
Password []byte `gorm:"not null" json:"-"`
30-
Books []Book `gorm:"foreignKey:OwnerID" json:"books,omitempty"`
28+
Username string `gorm:"uniqueIndex;not null;type:varchar(30)" json:"username"`
29+
Password []byte `gorm:"not null" json:"-"`
30+
Name *string `gorm:"size:128" json:"name"`
31+
Books []Book `gorm:"foreignKey:OwnerID" json:"books,omitempty"`
3132
}
3233

3334
func (u *User) SetPassword(newPlainPassword string) {

‎backend/db/types.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package db
33
import "github.com/google/uuid"
44

55
type CreateUser struct {
6-
Username string `json:"username" validate:"required,alphanum,min=3,max=30"`
7-
Password string `json:"password" validate:"required"`
6+
Username string `json:"username" validate:"required,alphanum,min=3,max=30"`
7+
Password string `json:"password" validate:"required"`
8+
Name *string `json:"name"`
89
}
910

1011
func (u *CreateUser) IntoUser() User {
1112
user := User{
1213
Username: u.Username,
14+
Name: u.Name,
1315
}
1416
user.SetPassword(u.Password)
1517
return user

‎frontend/src/core/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type OAuth2AccessToken = {
1919
export type User = {
2020
id: string
2121
username: string
22+
name?: string
2223
}
2324

2425
export type Book = {
@@ -39,6 +40,7 @@ export type Note = {
3940
export type CreateUser = {
4041
username: string
4142
password: string
43+
name?: string
4244
}
4345

4446
export type CreateBook = {

‎frontend/src/pages/signup.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ const Signup: Component = () => {
99
const { api } = useApi()
1010
const { pushToast } = useToast()
1111
const navigate = useNavigate()
12-
const [formDetails, setFormDetails] = createStore({ username: "", password: "", passwordConfirm: "" })
12+
const [formDetails, setFormDetails] = createStore({
13+
username: "",
14+
password: "",
15+
passwordConfirm: "",
16+
name: "",
17+
})
1318
const [loading, setLoading] = createSignal(false)
1419

1520
const onSubmit = async (ev: Event) => {
@@ -18,6 +23,7 @@ const Signup: Component = () => {
1823
let result = await api().createUser({
1924
username: formDetails.username,
2025
password: formDetails.password,
26+
name: formDetails.name || undefined,
2127
})
2228
setLoading(false)
2329
if (result instanceof ApiError) {
@@ -62,6 +68,19 @@ const Signup: Component = () => {
6268
required
6369
/>
6470
</div>
71+
<div class="form-control">
72+
<label class="label">
73+
<span class="label-text">Full Name</span>
74+
</label>
75+
<input
76+
class="input input-bordered"
77+
value={formDetails.name}
78+
oninput={(ev) => { setFormDetails({ name: ev.currentTarget.value }) }}
79+
type="text"
80+
placeholder="e.g. Leo S"
81+
maxlength={128}
82+
/>
83+
</div>
6584
<div class="form-control">
6685
<label class="label">
6786
<span class="label-text">Password</span>

0 commit comments

Comments
 (0)
Please sign in to comment.