mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-13 12:31:09 +00:00
c883a49a40
* First pass at invite-only migration. * Implement email verification (fixes #219) * remove unwrap * Adding views and functionality to registration application. #209 * Add private instance site column, and back end checks. * Adding some message fields to LoginResponse * Adding private instance to site setup. * A few additions: - Add a DeleteAccount response. - RegistrationApplicationView now has the safe LocalUserSettings. - Adding VerifyEmail to websocket API, added a proper response type. * Adding and reorganizing some email helpers. * A few fixes for private sites: - Added a check_registration_application function. - Only send a verification email if its been changed. - VerifyEmail now returns LoginResponse. - Deleting the old tokens after a successful email verify. - If port is missing on email config, display a better error message. * Version 0.15.0-rc.3 * Adding published to email_verification table. * Adding fixes from comments. * Version 0.15.0-rc.4 * Adding modlog private site check. * Version 0.15.0-rc.6 Co-authored-by: Felix Ableitner <me@nutomic.com>
55 lines
1.7 KiB
Rust
55 lines
1.7 KiB
Rust
use crate::{newtypes::LocalUserId, source::email_verification::*, traits::Crud};
|
|
use diesel::{
|
|
dsl::*,
|
|
insert_into,
|
|
result::Error,
|
|
ExpressionMethods,
|
|
PgConnection,
|
|
QueryDsl,
|
|
RunQueryDsl,
|
|
};
|
|
|
|
impl Crud for EmailVerification {
|
|
type Form = EmailVerificationForm;
|
|
type IdType = i32;
|
|
fn create(conn: &PgConnection, form: &EmailVerificationForm) -> Result<Self, Error> {
|
|
use crate::schema::email_verification::dsl::*;
|
|
insert_into(email_verification)
|
|
.values(form)
|
|
.get_result::<Self>(conn)
|
|
}
|
|
|
|
fn read(conn: &PgConnection, id_: i32) -> Result<Self, Error> {
|
|
use crate::schema::email_verification::dsl::*;
|
|
email_verification.find(id_).first::<Self>(conn)
|
|
}
|
|
|
|
fn update(conn: &PgConnection, id_: i32, form: &EmailVerificationForm) -> Result<Self, Error> {
|
|
use crate::schema::email_verification::dsl::*;
|
|
diesel::update(email_verification.find(id_))
|
|
.set(form)
|
|
.get_result::<Self>(conn)
|
|
}
|
|
|
|
fn delete(conn: &PgConnection, id_: i32) -> Result<usize, Error> {
|
|
use crate::schema::email_verification::dsl::*;
|
|
diesel::delete(email_verification.find(id_)).execute(conn)
|
|
}
|
|
}
|
|
|
|
impl EmailVerification {
|
|
pub fn read_for_token(conn: &PgConnection, token: &str) -> Result<Self, Error> {
|
|
use crate::schema::email_verification::dsl::*;
|
|
email_verification
|
|
.filter(verification_token.eq(token))
|
|
.filter(published.gt(now - 7.days()))
|
|
.first::<Self>(conn)
|
|
}
|
|
pub fn delete_old_tokens_for_local_user(
|
|
conn: &PgConnection,
|
|
local_user_id_: LocalUserId,
|
|
) -> Result<usize, Error> {
|
|
use crate::schema::email_verification::dsl::*;
|
|
diesel::delete(email_verification.filter(local_user_id.eq(local_user_id_))).execute(conn)
|
|
}
|
|
}
|