compiling state [wip]
This commit is contained in:
@@ -0,0 +1 @@
|
||||
pub mod user;
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod new_user;
|
||||
pub mod user;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
extern crate bcrypt;
|
||||
|
||||
use bcrypt::{hash, DEFAULT_COST};
|
||||
use diesel::Insertable;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::schema::users;
|
||||
|
||||
#[derive(Insertable, Clone)]
|
||||
#[diesel(table_name=users)]
|
||||
pub struct NewUser {
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub unique_id: String,
|
||||
}
|
||||
|
||||
impl NewUser {
|
||||
pub fn new(username: String, email: String, password: String) -> NewUser {
|
||||
let hashed_password: String = hash(password.as_str(), DEFAULT_COST).unwrap();
|
||||
let uuid = Uuid::new_v4();
|
||||
NewUser {
|
||||
username,
|
||||
email,
|
||||
password: hashed_password,
|
||||
unique_id: uuid.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
extern crate bcrypt;
|
||||
|
||||
use bcrypt::verify;
|
||||
use diesel::{Identifiable, Queryable};
|
||||
|
||||
use crate::schema::users;
|
||||
|
||||
#[derive(Queryable, Identifiable)]
|
||||
#[diesel(table_name=users)]
|
||||
#[derive(Clone)]
|
||||
pub struct User {
|
||||
pub id: i32,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub unique_id: String,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn verify(self, password: String) -> bool {
|
||||
return verify(password.as_str(), &self.password).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
use std::error::Error;
|
||||
|
||||
use rss::Channel;
|
||||
|
||||
pub async fn get_feed(feed: &String) -> Result<Channel, Box<dyn Error>> {
|
||||
let content = reqwest::get(feed).await?.bytes().await?;
|
||||
let channel = Channel::read_from(&content[..])?;
|
||||
Ok(channel)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod feeds;
|
||||
@@ -0,0 +1,11 @@
|
||||
// @generated automatically by Diesel CLI.
|
||||
|
||||
diesel::table! {
|
||||
users (id) {
|
||||
id -> Int4,
|
||||
username -> Varchar,
|
||||
email -> Varchar,
|
||||
password -> Varchar,
|
||||
unique_id -> Varchar,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
use actix_web::web;
|
||||
|
||||
pub fn views_factory(app: &mut web::ServiceConfig) {
|
||||
// auth::auth_factory(app);
|
||||
// to_do::item_factory(app);
|
||||
// app::app_factory(app);
|
||||
// users::user_factory(app);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
pub struct Path {
|
||||
pub prefix: String,
|
||||
pub backend: bool,
|
||||
}
|
||||
|
||||
impl Path {
|
||||
pub fn define(&self, following_path: String) -> String {
|
||||
match self.backend {
|
||||
true => {
|
||||
let path: String = self.prefix.to_owned() + &following_path;
|
||||
return String::from("/api/v1") + &path;
|
||||
}
|
||||
false => self.prefix.to_owned() + &following_path,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user