0010
This commit is contained in:
@@ -3,6 +3,6 @@
|
|||||||
- [ ] Developed RESTful API for flight search and booking
|
- [ ] Developed RESTful API for flight search and booking
|
||||||
- [ ] User Authentication
|
- [ ] User Authentication
|
||||||
- [ ] Implemented comprehensive flight search functionality
|
- [ ] Implemented comprehensive flight search functionality
|
||||||
- [ ] Implemented user registration and login functionality
|
- [x] Implemented user registration and login functionality
|
||||||
- [ ] Implemented secure booking process
|
- [ ] Implemented secure booking process
|
||||||
- [x] Create database schema for flights, users, and bookings
|
- [x] Create database schema for flights, users, and bookings
|
||||||
|
@@ -41,13 +41,35 @@ fn (app &App) service_update_user(id ?string, first_name string, last_name strin
|
|||||||
return error('User ID is required')
|
return error('User ID is required')
|
||||||
}
|
}
|
||||||
|
|
||||||
salt := auth.generate_salt()
|
// Get current user data
|
||||||
hashed_password := auth.hash_password_with_salt(password, salt)
|
current_user := sql app.db {
|
||||||
|
select from User where id == id limit 1
|
||||||
sql app.db {
|
|
||||||
update User set first_name = first_name, last_name = last_name, password = hashed_password,
|
|
||||||
salt = salt where id == id
|
|
||||||
}!
|
}!
|
||||||
|
|
||||||
|
if current_user.len == 0 {
|
||||||
|
return error('User not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
mut updates := []string{}
|
||||||
|
|
||||||
|
// Check which fields have changed
|
||||||
|
if first_name != current_user[0].first_name {
|
||||||
|
sql app.db {
|
||||||
|
update User set first_name = first_name where id == id
|
||||||
|
}!
|
||||||
|
}
|
||||||
|
if last_name != current_user[0].last_name {
|
||||||
|
sql app.db {
|
||||||
|
update User set last_name = last_name where id == id
|
||||||
|
}!
|
||||||
|
}
|
||||||
|
if password != '' { // Only update password if a new one is provided
|
||||||
|
salt := auth.generate_salt()
|
||||||
|
hashed_password := auth.hash_password_with_salt(password, salt)
|
||||||
|
sql app.db {
|
||||||
|
update User set password = hashed_password, salt = salt where id == id
|
||||||
|
}!
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user