Finished up with email verification system and profile page redux.
This commit is contained in:
parent
c32f3df3f3
commit
40c004795b
15 changed files with 275 additions and 58 deletions
|
|
@ -28,8 +28,10 @@ const statModel = require('../statSchema');
|
|||
const flairModel = require('../flairSchema');
|
||||
const permissionModel = require('../permissionSchema');
|
||||
const emoteModel = require('../emoteSchema');
|
||||
const emailChangeModel = require('./emailChangeSchema');
|
||||
//Utils
|
||||
const hashUtil = require('../../utils/hashUtils');
|
||||
const mailUtil = require('../../utils/mailUtils');
|
||||
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
|
|
@ -214,13 +216,7 @@ userSchema.statics.register = async function(userObj, ip){
|
|||
//Check password confirmation matches
|
||||
if(pass == passConfirm){
|
||||
//Look for a user (case insensitive)
|
||||
var userDB = await this.findOne({user: new RegExp(user, 'i')});
|
||||
|
||||
//If we didn't find a user and we submitted an email
|
||||
if(userDB == null && email != null){
|
||||
//Check to make sure no one's used this email address
|
||||
userDB = await this.findOne({email});
|
||||
}
|
||||
var userDB = await this.findOne({user: new RegExp(user, 'i')});
|
||||
|
||||
//If the user is found or someones trying to impersonate tokeboi
|
||||
if(userDB || user.toLowerCase() == "tokebot"){
|
||||
|
|
@ -230,10 +226,17 @@ userSchema.statics.register = async function(userObj, ip){
|
|||
const id = await statModel.incrementUserCount();
|
||||
|
||||
//Create user document in the database
|
||||
const newUser = await this.create({id, user, pass, email});
|
||||
const newUser = await this.create({id, user, pass});
|
||||
|
||||
//Tattoo the hashed IP used to register to the new user
|
||||
await newUser.tattooIPRecord(ip);
|
||||
|
||||
//if we submitted an email
|
||||
if(email != null){
|
||||
const requestDB = await emailChangeModel.create({user: newUser._id, newEmail: email, ipHash: ip});
|
||||
|
||||
await mailUtil.sendAddressVerification(requestDB, newUser, email)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
throw new Error("Confirmation password doesn't match!");
|
||||
|
|
@ -268,7 +271,7 @@ userSchema.statics.authenticate = async function(user, pass, failLine = "Bad Use
|
|||
}
|
||||
}
|
||||
|
||||
userSchema.statics.findProfile = async function(user){
|
||||
userSchema.statics.findProfile = async function(user, includeEmail = false){
|
||||
//Catch null users
|
||||
if(user == null || user.user == null){
|
||||
return null;
|
||||
|
|
@ -298,7 +301,7 @@ userSchema.statics.findProfile = async function(user){
|
|||
}
|
||||
|
||||
//return the profile
|
||||
return userDB.getProfile();
|
||||
return userDB.getProfile(includeEmail);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -425,7 +428,7 @@ userSchema.methods.getAuthenticatedSessions = async function(){
|
|||
|
||||
}
|
||||
|
||||
userSchema.methods.getProfile = function(){
|
||||
userSchema.methods.getProfile = function(includeEmail = false){
|
||||
//Create profile hashtable
|
||||
const profile = {
|
||||
id: this.id,
|
||||
|
|
@ -439,6 +442,11 @@ userSchema.methods.getProfile = function(){
|
|||
bio: this.bio
|
||||
};
|
||||
|
||||
//Include the email if we need to
|
||||
if(includeEmail){
|
||||
profile.email = this.email;
|
||||
}
|
||||
|
||||
//return profile hashtable
|
||||
return profile;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue