Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration page #1143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#DATABASE = "mongodb://localhost:27017"
#RESEND_API = "your resend_api"
DATABASE = "mongodb+srv://lohahussain0:[email protected]/idurtest?retryWrites=true&w=majority"
H9660 marked this conversation as resolved.
Show resolved Hide resolved
RESEND_API = "re_iNBb6fxD_MGUSfxesy3rJQQTENYWrfDaC"
#OPENAI_API_KEY = "your open_ai api key"
JWT_SECRET= "your_private_jwt_secret_key"
NODE_ENV = "production"
Expand Down
6 changes: 3 additions & 3 deletions backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ app.use(compression());

// Here our API Routes

app.use('/api', coreAuthRouter);
app.use('/api', adminAuth.isValidAuthToken, coreApiRouter);
app.use('/api', adminAuth.isValidAuthToken, erpApiRouter);
app.use('/api', coreAuthRouter); // This is for common users
app.use('/api', adminAuth.isValidAuthToken, coreApiRouter); // This is for admins
app.use('/api', adminAuth.isValidAuthToken, erpApiRouter); // This is for erps
app.use('/download', coreDownloadRouter);
app.use('/public', corePublicRouter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');

const authUser = async (req, res, { user, databasePassword, password, UserPasswordModel }) => {
const isMatch = await bcrypt.compare(password, databasePassword.password);
const isMatch = await bcrypt.compare(databasePassword.salt + password, databasePassword.password);

if (!isMatch)
return res.status(403).json({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ const jwt = require('jsonwebtoken');
const Joi = require('joi');

const mongoose = require('mongoose');

const checkAndCorrectURL = require('./checkAndCorrectURL');
const sendMail = require('./sendMail');

const { loadSettings } = require('@/middlewares/settings');
const { useAppSettings } = require('@/settings');
const AdminPassword = require('@/models/coreModels/AdminPassword');

const register = async (req, res, { userModel }) => {
const UserPasswordModel = mongoose.model(userModel + 'Password');
const UserModel = mongoose.model(userModel);
const UserModel = new mongoose.model(userModel);
const PasswordInstance = new AdminPassword();

const { name, email, password, country } = req.body;

// validate
Expand Down Expand Up @@ -44,10 +44,8 @@ const register = async (req, res, { userModel }) => {
message: 'An account with this email already exists.',
});

// authUser if your has correct password
const salt = await bcrypt.genSalt(10);
console.log(salt)
const hashedPassword = await bcrypt.hash(password, salt);
const hashedPassword = await PasswordInstance.generateHash(salt, password);
const newUser = {
name: name,
email: email,
Expand All @@ -56,27 +54,41 @@ const register = async (req, res, { userModel }) => {
};

const createdUser = await UserModel.create(newUser);
const newUserPassword = {
const newUserPassword = new AdminPassword({
removed: false,
user: createdUser,
password: hashedPassword,
salt: salt,
emailVerified: false,
authType: "email",
loggedSessions: []
}
const databasePassword = await UserPasswordModel.create(newUserPassword);
if (!createdUser || !databasePassword) {
authType: 'email',
loggedSessions: [],
});

const newPassword = await newUserPassword.save();
const settings = useAppSettings();
const idurar_app_email = settings['idurar_app_email'];
const idurar_base_url = settings['idurar_base_url'];
const url = checkAndCorrectURL(idurar_base_url);
const link = url + '/verify/' + createdUser._id + '/' + newPassword.emailToken;
await sendMail({
email,
name,
link,
idurar_app_email,
emailToken: newPassword.emailToken,
});

if (!createdUser || !newUserPassword) {
return res.status(500).json({
success: false,
result: null,
message: 'Error creating your account.',
});
} else {
const success = {
success: true
}
const newUser = {...createdUser, ...success}
success: true,
};
const newUser = { ...createdUser, ...success };
return res.status(200).json(newUser);
}
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/auth/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const login = async ({ loginData }) => {

export const register = async ({ registerData }) => {
try {

const response = await axios.post(API_BASE_URL + `register`, registerData);

const { status, data } = response;
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const RegisterPage = () => {

const dispatch = useDispatch();
const onFinish = (values) => {
console.log("Finsihed")
console.log(values);
dispatch(register({ registerData: values }));
navigate('/')
navigate('/');
};

const FormContainer = () => {
return (
<Loading isLoading={isLoading}>
Expand Down