Remove old configuration code
This commit is contained in:
parent
a281612051
commit
dd152f2607
|
@ -73,8 +73,6 @@ fn main() {
|
||||||
routes::comments::create,
|
routes::comments::create,
|
||||||
|
|
||||||
routes::instance::index,
|
routes::instance::index,
|
||||||
routes::instance::configure,
|
|
||||||
routes::instance::post_config,
|
|
||||||
routes::instance::shared_inbox,
|
routes::instance::shared_inbox,
|
||||||
routes::instance::nodeinfo,
|
routes::instance::nodeinfo,
|
||||||
|
|
||||||
|
|
|
@ -485,16 +485,16 @@ impl Signer for User {
|
||||||
impl NewUser {
|
impl NewUser {
|
||||||
/// Creates a new local user
|
/// Creates a new local user
|
||||||
pub fn new_local(
|
pub fn new_local(
|
||||||
|
conn: &PgConnection,
|
||||||
username: String,
|
username: String,
|
||||||
display_name: String,
|
display_name: String,
|
||||||
is_admin: bool,
|
is_admin: bool,
|
||||||
summary: String,
|
summary: String,
|
||||||
email: String,
|
email: String,
|
||||||
password: String,
|
password: String
|
||||||
instance_id: i32
|
) -> User {
|
||||||
) -> NewUser {
|
|
||||||
let (pub_key, priv_key) = gen_keypair();
|
let (pub_key, priv_key) = gen_keypair();
|
||||||
NewUser {
|
User::insert(conn, NewUser {
|
||||||
username: username,
|
username: username,
|
||||||
display_name: display_name,
|
display_name: display_name,
|
||||||
outbox_url: String::from(""),
|
outbox_url: String::from(""),
|
||||||
|
@ -503,11 +503,11 @@ impl NewUser {
|
||||||
summary: SafeString::new(&summary),
|
summary: SafeString::new(&summary),
|
||||||
email: Some(email),
|
email: Some(email),
|
||||||
hashed_password: Some(password),
|
hashed_password: Some(password),
|
||||||
instance_id: instance_id,
|
instance_id: Instance::local_id(conn),
|
||||||
ap_url: String::from(""),
|
ap_url: String::from(""),
|
||||||
public_key: String::from_utf8(pub_key).unwrap(),
|
public_key: String::from_utf8(pub_key).unwrap(),
|
||||||
private_key: Some(String::from_utf8(priv_key).unwrap()),
|
private_key: Some(String::from_utf8(priv_key).unwrap()),
|
||||||
shared_inbox_url: None
|
shared_inbox_url: None
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,31 +33,6 @@ fn index(conn: DbConn, user: Option<User>) -> Template {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/configure")]
|
|
||||||
fn configure() -> Template {
|
|
||||||
Template::render("instance/configure", json!({}))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(FromForm)]
|
|
||||||
struct NewInstanceForm {
|
|
||||||
name: String
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/configure", data = "<data>")]
|
|
||||||
fn post_config(conn: DbConn, data: Form<NewInstanceForm>) -> Redirect {
|
|
||||||
let form = data.get();
|
|
||||||
let inst = Instance::insert(&*conn, NewInstance {
|
|
||||||
public_domain: BASE_URL.as_str().to_string(),
|
|
||||||
name: form.name.to_string(),
|
|
||||||
local: true
|
|
||||||
});
|
|
||||||
if inst.has_admin(&*conn) {
|
|
||||||
Redirect::to("/")
|
|
||||||
} else {
|
|
||||||
Redirect::to("/users/new")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/inbox", data = "<data>")]
|
#[post("/inbox", data = "<data>")]
|
||||||
fn shared_inbox(conn: DbConn, data: String) -> String {
|
fn shared_inbox(conn: DbConn, data: String) -> String {
|
||||||
let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap();
|
let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap();
|
||||||
|
|
|
@ -164,7 +164,6 @@ struct NewUserForm {
|
||||||
|
|
||||||
#[post("/users/new", data = "<data>")]
|
#[post("/users/new", data = "<data>")]
|
||||||
fn create(conn: DbConn, data: Form<NewUserForm>) -> Result<Redirect, String> {
|
fn create(conn: DbConn, data: Form<NewUserForm>) -> Result<Redirect, String> {
|
||||||
let inst = Instance::get_local(&*conn).unwrap();
|
|
||||||
let form = data.get();
|
let form = data.get();
|
||||||
|
|
||||||
if form.username.clone().len() < 1 {
|
if form.username.clone().len() < 1 {
|
||||||
|
@ -174,15 +173,15 @@ fn create(conn: DbConn, data: Form<NewUserForm>) -> Result<Redirect, String> {
|
||||||
} else if form.password.clone().len() < 8 {
|
} else if form.password.clone().len() < 8 {
|
||||||
Err(String::from("Password should be at least 8 characters long"))
|
Err(String::from("Password should be at least 8 characters long"))
|
||||||
} else if form.password == form.password_confirmation {
|
} else if form.password == form.password_confirmation {
|
||||||
User::insert(&*conn, NewUser::new_local(
|
NewUser::new_local(
|
||||||
|
&*conn,
|
||||||
form.username.to_string(),
|
form.username.to_string(),
|
||||||
form.username.to_string(),
|
form.username.to_string(),
|
||||||
!inst.has_admin(&*conn),
|
false,
|
||||||
String::from(""),
|
String::from(""),
|
||||||
form.email.to_string(),
|
form.email.to_string(),
|
||||||
User::hash_pass(form.password.to_string()),
|
User::hash_pass(form.password.to_string())
|
||||||
inst.id
|
).update_boxes(&*conn);
|
||||||
)).update_boxes(&*conn);
|
|
||||||
Ok(Redirect::to(format!("/@/{}/", data.get().username)))
|
Ok(Redirect::to(format!("/@/{}/", data.get().username)))
|
||||||
} else {
|
} else {
|
||||||
Err(String::from("Passwords don't match"))
|
Err(String::from("Passwords don't match"))
|
||||||
|
|
|
@ -193,15 +193,15 @@ fn create_admin(instance: Instance, conn: DbConn) {
|
||||||
println!("What is your password?");
|
println!("What is your password?");
|
||||||
let password = rpassword::read_password().expect("Couldn't read your password.");
|
let password = rpassword::read_password().expect("Couldn't read your password.");
|
||||||
|
|
||||||
User::insert(&*conn, NewUser::new_local(
|
NewUser::new_local(
|
||||||
|
&*conn,
|
||||||
name.clone(),
|
name.clone(),
|
||||||
name,
|
name,
|
||||||
true,
|
true,
|
||||||
format!("Admin of {}", instance.name),
|
format!("Admin of {}", instance.name),
|
||||||
email,
|
email,
|
||||||
User::hash_pass(password),
|
User::hash_pass(password),
|
||||||
instance.id
|
).update_boxes(&*conn);
|
||||||
)).update_boxes(&*conn);
|
|
||||||
|
|
||||||
println!("{}\n", " ✔️ Your account was succesfully created!".green());
|
println!("{}\n", " ✔️ Your account was succesfully created!".green());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue