forked from jmug/stoatchat
Change how usernames, introduce display names.
This commit is contained in:
1075
Cargo.lock
generated
1075
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt"
|
name = "revolt"
|
||||||
version = "0.2.0"
|
version = "0.2.2"
|
||||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ pub struct User {
|
|||||||
pub email: String,
|
pub email: String,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
|
pub display_name: String,
|
||||||
pub access_token: Option<String>,
|
pub access_token: Option<String>,
|
||||||
pub email_verification: UserEmailVerification,
|
pub email_verification: UserEmailVerification,
|
||||||
pub relations: Option<Vec<UserRelationship>>,
|
pub relations: Option<Vec<UserRelationship>>,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use database::user::{User, UserRelationship};
|
|||||||
pub struct UserRef {
|
pub struct UserRef {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
|
pub display_name: String,
|
||||||
pub email_verified: bool,
|
pub email_verified: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ impl UserRef {
|
|||||||
.projection(doc! {
|
.projection(doc! {
|
||||||
"_id": 1,
|
"_id": 1,
|
||||||
"username": 1,
|
"username": 1,
|
||||||
|
"display_name": 1,
|
||||||
"email_verification.verified": 1,
|
"email_verification.verified": 1,
|
||||||
})
|
})
|
||||||
.build(),
|
.build(),
|
||||||
@@ -31,6 +33,7 @@ impl UserRef {
|
|||||||
Some(doc) => Some(UserRef {
|
Some(doc) => Some(UserRef {
|
||||||
id: doc.get_str("_id").unwrap().to_string(),
|
id: doc.get_str("_id").unwrap().to_string(),
|
||||||
username: doc.get_str("username").unwrap().to_string(),
|
username: doc.get_str("username").unwrap().to_string(),
|
||||||
|
display_name: doc.get_str("display_name").unwrap().to_string(),
|
||||||
email_verified: doc
|
email_verified: doc
|
||||||
.get_document("email_verification")
|
.get_document("email_verification")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -99,6 +102,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for UserRef {
|
|||||||
.projection(doc! {
|
.projection(doc! {
|
||||||
"_id": 1,
|
"_id": 1,
|
||||||
"username": 1,
|
"username": 1,
|
||||||
|
"display_name": 1,
|
||||||
"email_verification.verified": 1,
|
"email_verification.verified": 1,
|
||||||
})
|
})
|
||||||
.build(),
|
.build(),
|
||||||
@@ -109,6 +113,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for UserRef {
|
|||||||
Outcome::Success(UserRef {
|
Outcome::Success(UserRef {
|
||||||
id: user.get_str("_id").unwrap().to_string(),
|
id: user.get_str("_id").unwrap().to_string(),
|
||||||
username: user.get_str("username").unwrap().to_string(),
|
username: user.get_str("username").unwrap().to_string(),
|
||||||
|
display_name: user.get_str("display_name").unwrap().to_string(),
|
||||||
email_verified: user
|
email_verified: user
|
||||||
.get_document("email_verification")
|
.get_document("email_verification")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#![feature(proc_macro_hygiene, decl_macro)]
|
#![feature(proc_macro_hygiene, decl_macro)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ pub fn create(info: Json<Create>) -> Response {
|
|||||||
return Response::Conflict(json!({ "error": "Email already in use!" }));
|
return Response::Conflict(json!({ "error": "Email already in use!" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(_) = col
|
||||||
|
.find_one(doc! { "username": info.username.clone() }, None)
|
||||||
|
.expect("Failed user lookup")
|
||||||
|
{
|
||||||
|
return Response::Conflict(json!({ "error": "Username already in use!" }));
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(hashed) = hash(info.password.clone(), 10) {
|
if let Ok(hashed) = hash(info.password.clone(), 10) {
|
||||||
let access_token = gen_token(92);
|
let access_token = gen_token(92);
|
||||||
let code = gen_token(48);
|
let code = gen_token(48);
|
||||||
@@ -62,6 +69,7 @@ pub fn create(info: Json<Create>) -> Response {
|
|||||||
"_id": Ulid::new().to_string(),
|
"_id": Ulid::new().to_string(),
|
||||||
"email": info.email.clone(),
|
"email": info.email.clone(),
|
||||||
"username": info.username.clone(),
|
"username": info.username.clone(),
|
||||||
|
"display_name": info.username.clone(),
|
||||||
"password": hashed,
|
"password": hashed,
|
||||||
"access_token": access_token,
|
"access_token": access_token,
|
||||||
"email_verification": {
|
"email_verification": {
|
||||||
@@ -133,7 +141,7 @@ pub fn verify_email(code: String) -> Response {
|
|||||||
email::send_welcome_email(target.to_string(), user.username);
|
email::send_welcome_email(target.to_string(), user.username);
|
||||||
|
|
||||||
Response::Redirect(
|
Response::Redirect(
|
||||||
super::Redirect::to("https://example.com"), // ! FIXME; redirect to landing page
|
super::Redirect::to("https://app.revolt.chat"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ pub fn mount(rocket: Rocket) -> Rocket {
|
|||||||
routes![
|
routes![
|
||||||
user::me,
|
user::me,
|
||||||
user::user,
|
user::user,
|
||||||
user::lookup,
|
user::query,
|
||||||
user::dms,
|
user::dms,
|
||||||
user::dm,
|
user::dm,
|
||||||
user::get_friends,
|
user::get_friends,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use bson::doc;
|
|||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub fn root() -> Response {
|
pub fn root() -> Response {
|
||||||
Response::Success(json!({
|
Response::Success(json!({
|
||||||
"revolt": "0.2.0"
|
"revolt": "0.2.2"
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::notifications::{
|
|||||||
use crate::routes::channel;
|
use crate::routes::channel;
|
||||||
|
|
||||||
use bson::doc;
|
use bson::doc;
|
||||||
use mongodb::options::FindOptions;
|
use mongodb::options::{Collation, FindOptions, FindOneOptions};
|
||||||
use rocket_contrib::json::Json;
|
use rocket_contrib::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
@@ -20,6 +20,7 @@ pub fn me(user: UserRef) -> Response {
|
|||||||
Response::Success(json!({
|
Response::Success(json!({
|
||||||
"id": user.id,
|
"id": user.id,
|
||||||
"username": user.username,
|
"username": user.username,
|
||||||
|
"display_name": user.display_name,
|
||||||
"email": info.get_str("email").unwrap(),
|
"email": info.get_str("email").unwrap(),
|
||||||
"verified": user.email_verified,
|
"verified": user.email_verified,
|
||||||
}))
|
}))
|
||||||
@@ -36,6 +37,7 @@ pub fn user(user: UserRef, target: UserRef) -> Response {
|
|||||||
Response::Success(json!({
|
Response::Success(json!({
|
||||||
"id": target.id,
|
"id": target.id,
|
||||||
"username": target.username,
|
"username": target.username,
|
||||||
|
"display_name": target.display_name,
|
||||||
"relationship": get_relationship(&user, &target) as i32,
|
"relationship": get_relationship(&user, &target) as i32,
|
||||||
"mutual": {
|
"mutual": {
|
||||||
"guilds": mutual::find_mutual_guilds(&user.id, &target.id),
|
"guilds": mutual::find_mutual_guilds(&user.id, &target.id),
|
||||||
@@ -46,6 +48,46 @@ pub fn user(user: UserRef, target: UserRef) -> Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct UserQuery {
|
||||||
|
username: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// find a user by their username
|
||||||
|
#[post("/query", data = "<query>")]
|
||||||
|
pub fn query(user: UserRef, query: Json<UserQuery>) -> Response {
|
||||||
|
let relationships = user.fetch_relationships();
|
||||||
|
let col = database::get_collection("users");
|
||||||
|
|
||||||
|
if let Ok(result) = col.find_one(
|
||||||
|
doc! { "username": query.username.clone() },
|
||||||
|
FindOneOptions::builder()
|
||||||
|
.collation(
|
||||||
|
Collation::builder()
|
||||||
|
.locale("en")
|
||||||
|
.strength(2)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
) {
|
||||||
|
if let Some(doc) = result {
|
||||||
|
let id = doc.get_str("_id").unwrap();
|
||||||
|
Response::Success(json!({
|
||||||
|
"id": id,
|
||||||
|
"username": doc.get_str("username").unwrap(),
|
||||||
|
"display_name": doc.get_str("display_name").unwrap(),
|
||||||
|
"relationship": get_relationship_internal(&user.id, &id, &relationships) as i32
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
Response::NotFound(json!({
|
||||||
|
"error": "User not found!"
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Response::InternalServerError(json!({ "error": "Failed database query." }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*#[derive(Serialize, Deserialize)]
|
||||||
pub struct LookupQuery {
|
pub struct LookupQuery {
|
||||||
username: String,
|
username: String,
|
||||||
}
|
}
|
||||||
@@ -80,7 +122,7 @@ pub fn lookup(user: UserRef, query: Json<LookupQuery>) -> Response {
|
|||||||
} else {
|
} else {
|
||||||
Response::InternalServerError(json!({ "error": "Failed database query." }))
|
Response::InternalServerError(json!({ "error": "Failed database query." }))
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/// retrieve all of your DMs
|
/// retrieve all of your DMs
|
||||||
#[get("/@me/dms")]
|
#[get("/@me/dms")]
|
||||||
|
|||||||
Reference in New Issue
Block a user