Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. fn login_to_auth(username: String, password: String) -> Result<Authentication, String> {
  2. // unimplemented!();
  3. let vu: Vec<&str> = username.split(':').collect();
  4. match *vu {
  5. [] => Err(String::from("Comprend pas")),
  6. [login] => Ok(Authentication::Login {
  7. username: login.to_string(),
  8. password: password.to_string(),
  9. }),
  10. [auth_type, imei, idtel] if auth_type == "ident" => Ok(Authentication::Ident {
  11. imei: imei.to_string(),
  12. idtel: idtel.to_string(),
  13. }),
  14. [auth_type, imei, idtel] if auth_type == "auth" => {
  15. let vt: Vec<&str> = password.split(':').collect();
  16. match *vt {
  17. [uid, token] => Ok(Authentication::Token {
  18. uid: uid.to_string(),
  19. token: token.to_string(),
  20. imei: imei.to_string(),
  21. idtel: idtel.to_string(),
  22. }),
  23. _ => Err(String::from(format!(
  24. "this imei {} is trying to use a password {} that is not a token.",
  25. imei, password
  26. ))),
  27. }
  28. }
  29. _ => Err(String::from("I don't understand the username chain.")),
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement