This commit is contained in:
2021-02-08 15:48:33 +01:00
parent 1434918f8e
commit 9dd4d10396
5 changed files with 42 additions and 16 deletions

View File

@@ -36,7 +36,10 @@ const userSchema = mongoose.Schema({
maxlength: 64,
},
},
isRestaurant: Boolean,
isRestaurant: {
type: Boolean,
required: true
},
restaurants: [mongoose.Types.ObjectId],
trialUsed: Boolean,
preferences: {

View File

@@ -28,7 +28,7 @@ var router = express.Router();
router.post("/login", async (req, res) => {
try {
if (!req.body.password || !req.body.email) {
throw newError("Niepełne dane.", 204);
throw newError("Niepełne dane.", 403);
}
validateLogin(req.body);
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
router.post("/changepass", async (req, res) => {
try {

View File

@@ -8,18 +8,30 @@ const { deleteImage } = require("./oceanServices.js");
async function createUser(request) {
const password = await hashPass(request.body.password);
const user = new User({
_id: new mongoose.Types.ObjectId(),
email: request.body.email,
password: password,
firstname: request.body.firstname,
lastname: request.body.lastname,
billing: {
NIP: request.body.NIP,
adress: request.body.adress,
companyName: request.body.companyName,
},
});
let user;
if(request.body.isRestaurant === true){
user = new User({
_id: new mongoose.Types.ObjectId(),
email: request.body.email,
password: password,
firstname: request.body.firstname,
lastname: request.body.lastname,
isRestaurant: true,
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;
}
@@ -113,6 +125,8 @@ async function prepareSafeUser(user) {
firstname: user.firstname,
lastname: user.lastname,
email: user.email,
login: user.login,
isRestaurant: user.isRestaurant,
id: user._id,
restaurants: restaurants,
NIP: user.billing.NIP,

View File

@@ -40,7 +40,7 @@ function decodeAndSanitize(query) {
async function checkPassword(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) {

View File

@@ -5,7 +5,7 @@ const validateLogin = function(requestBody){
const email = validator.isEmail(requestBody.email) && validator.isLength(requestBody.email, { max: 64 })
const password = validator.isLength(requestBody.password, { max: 64 });
if(!email || !password){
throw newError("Dane logowania nieprawidłowe :/", 400);
throw newError("Dane logowania nieprawidłowe :/", 403);
}
}