Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Commit

Permalink
Updated user registration methodology
Browse files Browse the repository at this point in the history
  • Loading branch information
IamRaviTejaG committed Jul 21, 2018
1 parent 06b9207 commit 0412a64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
13 changes: 7 additions & 6 deletions logic/Registration.js
Expand Up @@ -4,27 +4,28 @@ const jwt = require('jsonwebtoken');
const mongoose = require('mongoose');
const uuid = require('uuid/v4');
const config = require('../config/config');
const userCredentialSchema = require('../schema/userCredentialSchema');
const UserCredential = mongoose.model('UserCredential', userCredentialSchema);
const UserSchema = require('../schema/UserSchema');
const UserCredential = mongoose.model('User', UserSchema);

let register = {
user_signup: (req, res) => {
mongoose.connect(config.MongoURL, {useNewUrlParser: true});
UserCredential.find({$or: [
{Email: req.body.Email},
{Username: req.body.Username}
{Alias: req.body.Alias}
]}).exec().then(data => {
if (data.length === 0) {
bcrypt.hash(req.body.Password, config.SALT_ROUNDS).then(passhash => {
var userdata = new UserCredential({
Username: req.body.Username,
Alias: req.body.Alias,
Email: req.body.Email,
Passphrase: passhash,
Age: req.body.Age,
Country: req.body.Country,
VerificationToken: uuid(),
Verified: false
});
console.log(userdata)
userdata.save().then(result => {
res.status(200).json({
message: 'Signup successful! Proceed to verification.',
Expand All @@ -33,9 +34,9 @@ let register = {
});
});
} else {
if (data[0].Username === req.body.Username) {
if (data[0].Alias === req.body.Alias) {
res.status(401).json({
message: 'Username already taken! Try another username.'
message: 'Alias already taken! Try another alias.'
});
} else {
res.status(401).json({
Expand Down
15 changes: 0 additions & 15 deletions schema/UserCredentialSchema.js

This file was deleted.

6 changes: 5 additions & 1 deletion schema/UserSchema.js
Expand Up @@ -7,7 +7,11 @@ let Schema = mongoose.Schema;
let ObjectId = mongoose.Schema.Types.ObjectId;

let userSchema = {
_id: ObjectId,
_id: {
type: ObjectId,
required: true,
auto: true,
},
Alias: String,
Passphrase: String,
Email: String,
Expand Down

0 comments on commit 0412a64

Please sign in to comment.