-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(mobile): allow users to change contact details #1994
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE | ||
users RENAME COLUMN contact TO email; | ||
ALTER TABLE | ||
users ADD COLUMN nostr TEXT; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE | ||
users RENAME COLUMN email TO contact; | ||
ALTER TABLE | ||
users DROP COLUMN nostr; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ use crate::collaborative_revert::confirm_legacy_collaborative_revert; | |
use crate::db; | ||
use crate::db::liquidity::LiquidityRequestLog; | ||
use crate::db::user; | ||
use crate::db::user::User; | ||
use crate::is_liquidity_sufficient; | ||
use crate::leaderboard::generate_leader_board; | ||
use crate::leaderboard::LeaderBoard; | ||
|
@@ -160,7 +161,11 @@ pub fn router( | |
.route("/api/orderbook/websocket", get(websocket_handler)) | ||
.route("/api/trade", post(post_trade)) | ||
.route("/api/rollover/:dlc_channel_id", post(rollover)) | ||
// Deprecated: we just keep it for backwards compatbility as otherwise old apps won't | ||
// pass registration | ||
.route("/api/register", post(post_register)) | ||
.route("/api/users", post(post_register)) | ||
.route("/api/users/:trader_pubkey", get(get_user)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 That api is concerning for me. If somebody learns about a users node id they can use this api to query user data. I propose we either validate a users signature on that api or rather put that information into the authenticated message received by the app after a successful login. (there we already verify the users signature) |
||
.route("/api/admin/wallet/balance", get(get_balance)) | ||
.route("/api/admin/wallet/utxos", get(get_utxos)) | ||
.route("/api/admin/channels", get(list_channels).post(open_channel)) | ||
|
@@ -438,8 +443,8 @@ pub async fn post_register( | |
.get() | ||
.map_err(|e| AppError::InternalServerError(format!("Could not get connection: {e:#}")))?; | ||
|
||
if let Some(email) = register_params.email { | ||
user::upsert_email(&mut conn, register_params.pubkey, email) | ||
if let Some(contact) = register_params.contact { | ||
user::upsert_user(&mut conn, register_params.pubkey, contact) | ||
.map_err(|e| AppError::InternalServerError(format!("Could not upsert user: {e:#}")))?; | ||
} else { | ||
tracing::warn!(trader_id=%register_params.pubkey, "Did not receive an email during registration"); | ||
|
@@ -448,6 +453,40 @@ pub async fn post_register( | |
Ok(()) | ||
} | ||
|
||
impl TryFrom<User> for commons::User { | ||
type Error = AppError; | ||
fn try_from(value: User) -> Result<Self, Self::Error> { | ||
Ok(commons::User { | ||
pubkey: PublicKey::from_str(&value.pubkey).map_err(|_| { | ||
AppError::InternalServerError("Could not parse user pubkey".to_string()) | ||
})?, | ||
contact: Some(value.contact).filter(|s| !s.is_empty()), | ||
}) | ||
} | ||
} | ||
|
||
#[instrument(skip_all, err(Debug))] | ||
pub async fn get_user( | ||
State(state): State<Arc<AppState>>, | ||
Path(trader_pubkey): Path<String>, | ||
) -> Result<Json<commons::User>, AppError> { | ||
let mut conn = state | ||
.pool | ||
.get() | ||
.map_err(|e| AppError::InternalServerError(format!("Could not get connection: {e:#}")))?; | ||
|
||
let trader_pubkey = PublicKey::from_str(trader_pubkey.as_str()) | ||
.map_err(|_| AppError::BadRequest("Invalid trader id provided".to_string()))?; | ||
|
||
let option = user::get_user(&mut conn, trader_pubkey) | ||
.map_err(|e| AppError::InternalServerError(format!("Could not load users: {e:#}")))?; | ||
|
||
match option { | ||
None => Err(AppError::NoMatchFound("No user found".to_string())), | ||
Some(user) => Ok(Json(user.try_into()?)), | ||
} | ||
} | ||
|
||
async fn get_settings(State(state): State<Arc<AppState>>) -> impl IntoResponse { | ||
let settings = state.settings.read().await; | ||
serde_json::to_string(&*settings).expect("to be able to serialise settings") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, anybody could use this api to update the contact details of a user.