Kibou is a federated social networking server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

create_user.rs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. extern crate chrono;
  2. extern crate diesel;
  3. extern crate getopts;
  4. extern crate kibou;
  5. use chrono::Utc;
  6. use getopts::Options;
  7. use kibou::actor;
  8. use kibou::database;
  9. use kibou::env;
  10. fn main() {
  11. let database = database::establish_connection();
  12. let args: Vec<String> = std::env::args().collect();
  13. let mut options = Options::new();
  14. options.reqopt(
  15. "e",
  16. "email",
  17. "e-mail address for the new user",
  18. "alyssa@example.com",
  19. );
  20. options.reqopt(
  21. "p",
  22. "password",
  23. "password for the new user",
  24. "MySecretPassword",
  25. );
  26. options.reqopt("u", "username", "username for the new user", "alyssatest");
  27. options.optopt(
  28. "s",
  29. "summary",
  30. "a summary (bio) for the new user",
  31. "I am a Kibou Test-Actor, how are you doing?",
  32. );
  33. let matches = match options.parse(&args[1..]) {
  34. Ok(m) => m,
  35. Err(e) => panic!(e.to_string()),
  36. };
  37. let mut new_actor = actor::Actor {
  38. id: 0,
  39. email: Some(matches.opt_str("email").unwrap()),
  40. password: Some(matches.opt_str("password").unwrap()),
  41. actor_uri: format!(
  42. "{base_scheme}://{base_domain}/actors/{username}",
  43. base_scheme = env::get_value(String::from("endpoint.base_scheme")),
  44. base_domain = env::get_value(String::from("endpoint.base_domain")),
  45. username = matches.opt_str("username").unwrap()
  46. ),
  47. username: Some(matches.opt_str("username").unwrap()),
  48. preferred_username: matches.opt_str("username").unwrap(),
  49. summary: matches.opt_str("summary"),
  50. followers: serde_json::json!({"activitypub": []}),
  51. inbox: None,
  52. icon: None,
  53. local: true,
  54. keys: serde_json::json!({}),
  55. created: Utc::now().naive_utc(),
  56. modified: Utc::now().naive_utc(),
  57. };
  58. actor::create_actor(&database, &mut new_actor)
  59. }