fixes
This commit is contained in:
@@ -36,7 +36,10 @@ const userSchema = mongoose.Schema({
|
|||||||
maxlength: 64,
|
maxlength: 64,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isRestaurant: Boolean,
|
isRestaurant: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
restaurants: [mongoose.Types.ObjectId],
|
restaurants: [mongoose.Types.ObjectId],
|
||||||
trialUsed: Boolean,
|
trialUsed: Boolean,
|
||||||
preferences: {
|
preferences: {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ var router = express.Router();
|
|||||||
router.post("/login", async (req, res) => {
|
router.post("/login", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req.body.password || !req.body.email) {
|
if (!req.body.password || !req.body.email) {
|
||||||
throw newError("Niepełne dane.", 204);
|
throw newError("Niepełne dane.", 403);
|
||||||
}
|
}
|
||||||
validateLogin(req.body);
|
validateLogin(req.body);
|
||||||
const user = await fetchUser(req.body.email);
|
const user = await fetchUser(req.body.email);
|
||||||
@@ -87,6 +87,15 @@ router.post("/register", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// CHANGE USER DATA
|
||||||
|
router.post("/edit", async (req, res) => {
|
||||||
|
try {
|
||||||
|
console.log("23")
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, res)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// CHANGE PASSWORD
|
// CHANGE PASSWORD
|
||||||
router.post("/changepass", async (req, res) => {
|
router.post("/changepass", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -8,18 +8,30 @@ const { deleteImage } = require("./oceanServices.js");
|
|||||||
|
|
||||||
async function createUser(request) {
|
async function createUser(request) {
|
||||||
const password = await hashPass(request.body.password);
|
const password = await hashPass(request.body.password);
|
||||||
const user = new User({
|
let user;
|
||||||
_id: new mongoose.Types.ObjectId(),
|
if(request.body.isRestaurant === true){
|
||||||
email: request.body.email,
|
user = new User({
|
||||||
password: password,
|
_id: new mongoose.Types.ObjectId(),
|
||||||
firstname: request.body.firstname,
|
email: request.body.email,
|
||||||
lastname: request.body.lastname,
|
password: password,
|
||||||
billing: {
|
firstname: request.body.firstname,
|
||||||
NIP: request.body.NIP,
|
lastname: request.body.lastname,
|
||||||
adress: request.body.adress,
|
isRestaurant: true,
|
||||||
companyName: request.body.companyName,
|
billing: {
|
||||||
},
|
NIP: request.body.NIP,
|
||||||
});
|
adress: request.body.adress,
|
||||||
|
companyName: request.body.companyName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
user = new User({
|
||||||
|
_id: new mongoose.Types.ObjectId(),
|
||||||
|
email: request.body.email,
|
||||||
|
login: request.body.login,
|
||||||
|
password: password,
|
||||||
|
isRestaurant: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +125,8 @@ async function prepareSafeUser(user) {
|
|||||||
firstname: user.firstname,
|
firstname: user.firstname,
|
||||||
lastname: user.lastname,
|
lastname: user.lastname,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
|
login: user.login,
|
||||||
|
isRestaurant: user.isRestaurant,
|
||||||
id: user._id,
|
id: user._id,
|
||||||
restaurants: restaurants,
|
restaurants: restaurants,
|
||||||
NIP: user.billing.NIP,
|
NIP: user.billing.NIP,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ function decodeAndSanitize(query) {
|
|||||||
|
|
||||||
async function checkPassword(password, hash) {
|
async function checkPassword(password, hash) {
|
||||||
const result = await bcrypt.compare(password, hash);
|
const result = await bcrypt.compare(password, hash);
|
||||||
if (!result) throw newError("Hasło nieprawidłowe", 401);
|
if (!result) throw newError("Hasło nieprawidłowe", 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateAuthToken(user) {
|
function generateAuthToken(user) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const validateLogin = function(requestBody){
|
|||||||
const email = validator.isEmail(requestBody.email) && validator.isLength(requestBody.email, { max: 64 })
|
const email = validator.isEmail(requestBody.email) && validator.isLength(requestBody.email, { max: 64 })
|
||||||
const password = validator.isLength(requestBody.password, { max: 64 });
|
const password = validator.isLength(requestBody.password, { max: 64 });
|
||||||
if(!email || !password){
|
if(!email || !password){
|
||||||
throw newError("Dane logowania nieprawidłowe :/", 400);
|
throw newError("Dane logowania nieprawidłowe :/", 403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user