diff --git a/Cargo.toml b/Cargo.toml index c1c71bc..43e5ea5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,5 +60,6 @@ regex = "1.11" random-string = "1.1" lettre = { version = "0.11", features = ["tokio1", "tokio1-native-tls"] } chrono = { version = "0.4.41", features = ["serde"] } +rand = "0.9.1" diff --git a/src/api/v1/auth/login.rs b/src/api/v1/auth/login.rs index 2faaeb4..cef4726 100644 --- a/src/api/v1/auth/login.rs +++ b/src/api/v1/auth/login.rs @@ -7,10 +7,7 @@ use diesel_async::RunQueryDsl; use serde::Deserialize; use crate::{ - Data, - error::Error, - schema::*, - utils::{PASSWORD_REGEX, generate_token, new_refresh_token_cookie, user_uuid_from_identifier}, + error::Error, schema::*, utils::{generate_token, new_refresh_token_cookie, user_uuid_from_identifier, PASSWORD_REGEX}, generate_device_name::generate_device_name, Data }; use super::Response; @@ -19,7 +16,6 @@ use super::Response; struct LoginInformation { username: String, password: String, - device_name: String, } #[post("/login")] @@ -63,12 +59,14 @@ pub async fn response( use refresh_tokens::dsl as rdsl; + let device_name = generate_device_name(); + insert_into(refresh_tokens::table) .values(( rdsl::token.eq(&refresh_token), rdsl::uuid.eq(uuid), rdsl::created_at.eq(current_time), - rdsl::device_name.eq(&login_information.device_name), + rdsl::device_name.eq(&device_name), )) .execute(&mut conn) .await?; @@ -87,5 +85,5 @@ pub async fn response( Ok(HttpResponse::Ok() .cookie(new_refresh_token_cookie(&data.config, refresh_token)) - .json(Response { access_token })) + .json(Response { access_token, device_name })) } diff --git a/src/api/v1/auth/mod.rs b/src/api/v1/auth/mod.rs index 0e6b006..947e7aa 100644 --- a/src/api/v1/auth/mod.rs +++ b/src/api/v1/auth/mod.rs @@ -20,6 +20,7 @@ mod verify_email; #[derive(Serialize)] struct Response { access_token: String, + device_name: String, } pub fn web() -> Scope { diff --git a/src/api/v1/auth/refresh.rs b/src/api/v1/auth/refresh.rs index abd9a34..e9a444b 100644 --- a/src/api/v1/auth/refresh.rs +++ b/src/api/v1/auth/refresh.rs @@ -77,6 +77,15 @@ pub async fn res(req: HttpRequest, data: web::Data) -> Result()?; + let device_name: String; + + // fix me tomorrow + // let devices: Vec = dsl::refresh_tokens + // .filter(dsl::uuid.eq(uuid)) + // .select(Device::as_select()) + // .get_results(&mut conn) + // .await?; + update(access_tokens::table) .filter(dsl::refresh_token.eq(&refresh_token)) .set(( @@ -88,7 +97,7 @@ pub async fn res(req: HttpRequest, data: web::Data) -> Result String { + let adjective_index = rand::rng().random_range(0..ADJECTIVES_LENGTH-1); + let animal_index = rand::rng().random_range(0..ANIMALS_LENGTH-1); + + return [ADJECTIVES[adjective_index], ANIMALS[animal_index]].join(" ") +} + +const ANIMALS_LENGTH: usize = 223; +const ADJECTIVES_LENGTH: usize = 765; + +const ANIMALS: [&'static str; ANIMALS_LENGTH] = [ + "Aardvark", + "Albatross", + "Alligator", + "Alpaca", + "Ant", + "Anteater", + "Antelope", + "Ape", + "Armadillo", + "Donkey", + "Baboon", + "Badger", + "Barracuda", + "Bat", + "Bear", + "Beaver", + "Bee", + "Bison", + "Boar", + "Buffalo", + "Butterfly", + "Camel", + "Capybara", + "Caribou", + "Cassowary", + "Cat", + "Caterpillar", + "Cattle", + "Chamois", + "Cheetah", + "Chicken", + "Chimpanzee", + "Chinchilla", + "Chough", + "Clam", + "Cobra", + "Cockroach", + "Cod", + "Cormorant", + "Coyote", + "Crab", + "Crane", + "Crocodile", + "Crow", + "Curlew", + "Deer", + "Dinosaur", + "Dog", + "Dogfish", + "Dolphin", + "Dotterel", + "Dove", + "Dragonfly", + "Duck", + "Dugong", + "Dunlin", + "Eagle", + "Echidna", + "Eel", + "Eland", + "Elephant", + "Elk", + "Emu", + "Falcon", + "Ferret", + "Finch", + "Fish", + "Flamingo", + "Fly", + "Fox", + "Frog", + "Gaur", + "Gazelle", + "Gerbil", + "Giraffe", + "Gnat", + "Gnu", + "Goat", + "Goldfinch", + "Goldfish", + "Goose", + "Gorilla", + "Goshawk", + "Grasshopper", + "Grouse", + "Guanaco", + "Gull", + "Hamster", + "Hare", + "Hawk", + "Hedgehog", + "Heron", + "Herring", + "Hippopotamus", + "Hornet", + "Horse", + "Hummingbird", + "Hyena", + "Ibex", + "Ibis", + "Jackal", + "Jaguar", + "Jay", + "Jellyfish", + "Kangaroo", + "Kingfisher", + "Koala", + "Kookabura", + "Kouprey", + "Kudu", + "Lapwing", + "Lark", + "Lemur", + "Leopard", + "Lion", + "Llama", + "Lobster", + "Locust", + "Loris", + "Louse", + "Lyrebird", + "Magpie", + "Mallard", + "Manatee", + "Mandrill", + "Mantis", + "Marten", + "Meerkat", + "Mink", + "Mole", + "Mongoose", + "Monkey", + "Moose", + "Mosquito", + "Mouse", + "Mule", + "Narwhal", + "Newt", + "Nightingale", + "Octopus", + "Okapi", + "Opossum", + "Oryx", + "Ostrich", + "Otter", + "Owl", + "Oyster", + "Panther", + "Parrot", + "Partridge", + "Peafowl", + "Pelican", + "Penguin", + "Pheasant", + "Pig", + "Pigeon", + "Pony", + "Porcupine", + "Porpoise", + "Quail", + "Quelea", + "Quetzal", + "Rabbit", + "Raccoon", + "Rail", + "Ram", + "Rat", + "Raven", + "Red deer", + "Red panda", + "Reindeer", + "Rhinoceros", + "Rook", + "Salamander", + "Salmon", + "Sand Dollar", + "Sandpiper", + "Sardine", + "Scorpion", + "Seahorse", + "Seal", + "Shark", + "Sheep", + "Shrew", + "Skunk", + "Snail", + "Snake", + "Sparrow", + "Spider", + "Spoonbill", + "Squid", + "Squirrel", + "Starling", + "Stingray", + "Stinkbug", + "Stork", + "Swallow", + "Swan", + "Tapir", + "Tarsier", + "Termite", + "Tiger", + "Toad", + "Trout", + "Turkey", + "Turtle", + "Viper", + "Vulture", + "Wallaby", + "Walrus", + "Wasp", + "Weasel", + "Whale", + "Wildcat", + "Wolf", + "Wolverine", + "Wombat", + "Woodcock", + "Woodpecker", + "Worm", + "Wren", + "Yak", + "Zebra", +]; + +const ADJECTIVES: [&'static str; ADJECTIVES_LENGTH] = [ + "other", + "such", + "first", + "many", + "new", + "more", + "same", + "own", + "good", + "different", + "great", + "long", + "high", + "social", + "little", + "much", + "important", + "small", + "most", + "large", + "old", + "few", + "general", + "second", + "public", + "last", + "several", + "early", + "certain", + "economic", + "least", + "common", + "present", + "next", + "local", + "best", + "particular", + "young", + "various", + "necessary", + "whole", + "only", + "true", + "able", + "major", + "full", + "low", + "available", + "real", + "similar", + "total", + "special", + "less", + "short", + "specific", + "single", + "self", + "national", + "individual", + "clear", + "personal", + "higher", + "better", + "third", + "natural", + "greater", + "open", + "difficult", + "current", + "further", + "main", + "physical", + "foreign", + "lower", + "strong", + "private", + "likely", + "international", + "significant", + "late", + "basic", + "hard", + "modern", + "simple", + "normal", + "sure", + "central", + "original", + "effective", + "following", + "direct", + "final", + "cultural", + "big", + "recent", + "complete", + "financial", + "positive", + "primary", + "appropriate", + "legal", + "european", + "equal", + "larger", + "average", + "historical", + "critical", + "wide", + "traditional", + "additional", + "active", + "complex", + "former", + "independent", + "entire", + "actual", + "close", + "constant", + "previous", + "easy", + "serious", + "potential", + "fine", + "industrial", + "subject", + "future", + "internal", + "initial", + "well", + "essential", + "dark", + "popular", + "successful", + "standard", + "year", + "past", + "ready", + "professional", + "wrong", + "very", + "proper", + "separate", + "heavy", + "civil", + "responsible", + "considerable", + "light", + "cold", + "above", + "older", + "practical", + "external", + "sufficient", + "interesting", + "upper", + "scientific", + "key", + "annual", + "limited", + "smaller", + "southern", + "earlier", + "commercial", + "powerful", + "later", + "like", + "clinical", + "ancient", + "educational", + "typical", + "technical", + "environmental", + "formal", + "aware", + "beautiful", + "variable", + "obvious", + "secondary", + "enough", + "urban", + "regular", + "relevant", + "greatest", + "spiritual", + "time", + "double", + "happy", + "term", + "multiple", + "dependent", + "correct", + "northern", + "middle", + "rural", + "official", + "fundamental", + "numerous", + "overall", + "usual", + "native", + "regional", + "highest", + "north", + "agricultural", + "literary", + "broad", + "perfect", + "experimental", + "fourth", + "global", + "ordinary", + "related", + "apparent", + "daily", + "principal", + "contemporary", + "severe", + "reasonable", + "subsequent", + "worth", + "longer", + "emotional", + "intellectual", + "unique", + "pure", + "familiar", + "american", + "solid", + "brief", + "famous", + "fresh", + "day", + "corresponding", + "characteristic", + "maximum", + "detailed", + "outside", + "theoretical", + "fair", + "opposite", + "capable", + "visual", + "interested", + "joint", + "adequate", + "based", + "substantial", + "unable", + "structural", + "soft", + "false", + "largest", + "inner", + "mean", + "extensive", + "excellent", + "rapid", + "absolute", + "consistent", + "continuous", + "administrative", + "strange", + "willing", + "alternative", + "slow", + "distinct", + "safe", + "permanent", + "front", + "corporate", + "academic", + "thin", + "nineteenth", + "universal", + "functional", + "unknown", + "careful", + "narrow", + "evident", + "sound", + "classical", + "minor", + "weak", + "suitable", + "chief", + "extreme", + "yellow", + "warm", + "mixed", + "flat", + "huge", + "vast", + "stable", + "valuable", + "rare", + "visible", + "sensitive", + "mechanical", + "state", + "radical", + "extra", + "superior", + "conventional", + "thick", + "dominant", + "post", + "collective", + "younger", + "efficient", + "linear", + "organic", + "oral", + "century", + "creative", + "vertical", + "dynamic", + "empty", + "minimum", + "cognitive", + "logical", + "afraid", + "equivalent", + "quick", + "near", + "concrete", + "mass", + "acute", + "sharp", + "easier", + "quiet", + "adult", + "accurate", + "ideal", + "partial", + "bright", + "identical", + "conservative", + "magnetic", + "frequent", + "electronic", + "fixed", + "square", + "cross", + "clean", + "back", + "organizational", + "constitutional", + "genetic", + "ultimate", + "secret", + "vital", + "dramatic", + "objective", + "round", + "alive", + "straight", + "unusual", + "rational", + "electric", + "mutual", + "class", + "competitive", + "revolutionary", + "statistical", + "random", + "musical", + "crucial", + "racial", + "sudden", + "acid", + "content", + "temporary", + "line", + "remarkable", + "exact", + "valid", + "helpful", + "nice", + "comprehensive", + "united", + "level", + "fifth", + "nervous", + "expensive", + "prominent", + "healthy", + "liquid", + "institutional", + "silent", + "sweet", + "strategic", + "molecular", + "comparative", + "called", + "electrical", + "raw", + "acceptable", + "scale", + "violent", + "all", + "desirable", + "tall", + "steady", + "wonderful", + "sub", + "distant", + "progressive", + "enormous", + "horizontal", + "and", + "intense", + "smooth", + "applicable", + "over", + "animal", + "abstract", + "wise", + "worst", + "gold", + "precise", + "legislative", + "remote", + "technological", + "outer", + "uniform", + "slight", + "attractive", + "evil", + "tiny", + "royal", + "angry", + "advanced", + "friendly", + "dear", + "busy", + "spatial", + "rough", + "primitive", + "judicial", + "systematic", + "lateral", + "sorry", + "plain", + "off", + "comfortable", + "definite", + "massive", + "firm", + "widespread", + "prior", + "twentieth", + "mathematical", + "verbal", + "marginal", + "excessive", + "stronger", + "gross", + "world", + "productive", + "wider", + "glad", + "linguistic", + "patient", + "symbolic", + "earliest", + "plastic", + "type", + "prime", + "eighteenth", + "blind", + "neutral", + "guilty", + "hand", + "extraordinary", + "metal", + "surprising", + "fellow", + "york", + "grand", + "thermal", + "artificial", + "five", + "lowest", + "genuine", + "dimensional", + "optical", + "unlikely", + "developmental", + "reliable", + "executive", + "comparable", + "satisfactory", + "golden", + "diverse", + "preliminary", + "wooden", + "noble", + "part", + "striking", + "cool", + "classic", + "elderly", + "four", + "temporal", + "indirect", + "romantic", + "intermediate", + "differential", + "passive", + "life", + "voluntary", + "out", + "adjacent", + "behavioral", + "exclusive", + "closed", + "inherent", + "inevitable", + "complicated", + "quantitative", + "respective", + "artistic", + "probable", + "anxious", + "informal", + "strict", + "fiscal", + "ideological", + "profound", + "extended", + "eternal", + "known", + "infinite", + "proud", + "honest", + "peculiar", + "absent", + "pleasant", + "optimal", + "renal", + "static", + "outstanding", + "presidential", + "digital", + "integrated", + "legitimate", + "curious", + "aggressive", + "deeper", + "elementary", + "history", + "surgical", + "occasional", + "flexible", + "convenient", + "solar", + "atomic", + "isolated", + "latest", + "sad", + "conceptual", + "underlying", + "everyday", + "cost", + "intensive", + "odd", + "subjective", + "mid", + "worthy", + "pale", + "meaningful", + "therapeutic", + "making", + "circular", + "realistic", + "multi", + "child", + "sophisticated", + "down", + "leading", + "intelligent", + "governmental", + "numerical", + "minimal", + "diagnostic", + "indigenous", + "aesthetic", + "distinctive", + "operational", + "sole", + "material", + "fast", + "bitter", + "broader", + "brilliant", + "peripheral", + "rigid", + "automatic", + "lesser", + "routine", + "favorable", + "cooperative", + "cardiac", + "arbitrary", + "loose", + "favorite", + "subtle", + "uncertain", + "hostile", + "monthly", + "naval", + "physiological", + "historic", + "developed", + "skilled", + "anterior", + "pro", + "gentle", + "loud", + "pulmonary", + "innocent", + "provincial", + "mild", + "page", + "specialized", + "bare", + "excess", + "inter", + "shaped", + "theological", + "sensory", + "the", + "stress", + "novel", + "working", + "shorter", + "secular", + "geographical", + "intimate", + "liable", + "selective", + "influential", + "modest", + "successive", + "continued", + "water", + "expert", + "municipal", + "marine", + "thirty", + "adverse", + "wacky", + "closer", + "virtual", + "peaceful", + "mobile", + "sixth", + "immune", + "coastal", + "representative", + "lead", + "forward", + "faithful", + "crystal", + "protective", + "elaborate", + "tremendous", + "welcoming", + "abnormal", + "grateful", + "proportional", + "dual", + "operative", + "precious", + "sympathetic", + "accessible", + "lovely", + "spinal", + "even", + "marked", + "observed", + "point", + "mature", + "competent", + "residential", + "impressive", + "unexpected", + "nearby", + "unnecessary", + "generous", + "cerebral", + "unpublished", + "delicate", + "analytical", + "tropical", + "statutory", + "cell", + "weekly", + "end", + "online", + "beneficial", + "aged", + "tough", + "eager", + "ongoing", + "silver", + "persistent", + "calm", + "nearest", + "hidden", + "magic", + "pretty", + "wealthy", + "exciting", + "decisive", + "confident", + "invisible", + "notable", + "medium", + "manual", + "select", + "thorough", + "causal", + "giant", + "bigger", + "pink", + "improved", + "immense", + "hour", + "intact", + "grade", + "dense", + "hungry", + "biggest", + "abundant", + "handsome", + "retail", + "insufficient", + "irregular", + "intrinsic", + "residual", + "follow", + "fluid", + "mysterious", + "descriptive", + "elastic", + "destructive", + "architectural", + "synthetic", + "continental", + "evolutionary", + "lucky", + "bold", + "funny", + "peak", + "smallest", + "reluctant", + "suspicious", + "smart", + "mighty", + "brave", + "humble", + "vocal", + "obscure", + "innovative", +]; \ No newline at end of file