invites:
handling result from diesel generally: fixed pub/private issue in modles module renamed rand_utils functions to be snake case
This commit is contained in:
parent
89836449a1
commit
e4f03b951e
@ -55,22 +55,18 @@ pub fn use_invite(hash: u64, conn: DBConn) -> Json<User> {
|
|||||||
use schema::invites::dsl::*;
|
use schema::invites::dsl::*;
|
||||||
use schema::users::dsl::*;
|
use schema::users::dsl::*;
|
||||||
|
|
||||||
// NOTE: collection of 1 item from the table could be done cleaner
|
|
||||||
let data = invites.select((id, expires, uses))
|
|
||||||
.filter(id.eq(hash))
|
|
||||||
.first::<Invite>(&conn.0)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let diesel_result: Result<Invite, diesel::result::Error> = invites.filter(id.eq(hash)).first(&conn.0);
|
let diesel_result: Result<Invite, diesel::result::Error> = invites.filter(id.eq(hash)).first(&conn.0);
|
||||||
// TODO: this is getting moved elsewhere to clean up so ignore this for now
|
// TODO: this is getting moved elsewhere to clean up so ignore this for now
|
||||||
match diesel_result {
|
match diesel_result {
|
||||||
Ok(data) => {
|
Ok(_data) => {
|
||||||
// we may have an unnecssary struct here but its not that big a deal raelly
|
// we may have an unnecssary struct here but its not that big a deal raelly
|
||||||
let user = crate::users::createNewUser();
|
let user = crate::users::create_new_user();
|
||||||
diesel::insert_into(users)
|
if let Ok(_v) = diesel::insert_into(users).values(&user).execute(&conn.0) {
|
||||||
.values(&user)
|
Json(user)
|
||||||
.execute(&conn.0);
|
}
|
||||||
Json(user)
|
else {
|
||||||
|
Json(blankNewUser!())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
Json(blankNewUser!())
|
Json(blankNewUser!())
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::schema::{invites, new_users};
|
use crate::schema::{invites, users};
|
||||||
#[derive(Insertable, Serialize, Deserialize, Queryable, Debug)]
|
#[derive(Insertable, Serialize, Deserialize, Queryable, Debug)]
|
||||||
#[table_name = "invites"]
|
#[table_name = "invites"]
|
||||||
pub struct Invite {
|
pub struct Invite {
|
||||||
@ -10,8 +10,8 @@ pub struct Invite {
|
|||||||
#[derive(Serialize, Deserialize, Queryable, Insertable, Debug)]
|
#[derive(Serialize, Deserialize, Queryable, Insertable, Debug)]
|
||||||
#[table_name = "users"]
|
#[table_name = "users"]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
userid: u64,
|
pub userid: u64,
|
||||||
username: String,
|
pub username: String,
|
||||||
key: String,
|
pub key: String,
|
||||||
date: u64,
|
pub date: u64,
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
// This modules mainly deals with creating various types of random data
|
// This modules mainly deals with creating various types of random data
|
||||||
use getrandom::getrandom;
|
use getrandom::getrandom;
|
||||||
|
|
||||||
pub fn newUserID() -> u64 {
|
pub fn new_user_id() -> u64 {
|
||||||
let mut buf = [0u8; 8];
|
let mut buf = [0u8; 8];
|
||||||
match getrandom::getrandom(&mut buf) { // honestly if this fails idk wtf you want
|
match getrandom::getrandom(&mut buf) { // honestly if this fails idk wtf you want
|
||||||
Ok(_val) => {u64::from_ne_bytes(buf)}
|
Ok(_val) => {u64::from_ne_bytes(buf)}
|
||||||
@ -9,7 +9,7 @@ pub fn newUserID() -> u64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn newKey() -> String { // Returns a random string which we later hash with bcrypt
|
pub fn new_key() -> String { // Returns a random string which we later hash with bcrypt
|
||||||
let mut raw_slice = [0u8; 32];
|
let mut raw_slice = [0u8; 32];
|
||||||
if let Ok(_ignored) = getrandom(&mut raw_slice) {
|
if let Ok(_ignored) = getrandom(&mut raw_slice) {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use crate::rand_utils::{newUserID, newKey};
|
use crate::rand_utils::{new_user_id, new_key};
|
||||||
use crate::models::User;
|
use crate::models::User;
|
||||||
|
|
||||||
// Returns a struct of payload::NewUserInfo
|
// Returns a struct of payload::NewUserInfo
|
||||||
pub fn createNewUser() -> User {
|
pub fn create_new_user() -> User {
|
||||||
let uid = newUserID();
|
let uid = new_user_id();
|
||||||
let uname = format!("User:#{}", uid);
|
let uname = format!("User:#{}", uid);
|
||||||
let rstring = newKey();
|
let rstring = new_key();
|
||||||
User {
|
User {
|
||||||
userid: uid,
|
userid: uid,
|
||||||
username: uname,
|
username: uname,
|
||||||
|
Loading…
Reference in New Issue
Block a user