Compare commits
15 Commits
dogsitters
...
02e50bb2f9
| Author | SHA1 | Date | |
|---|---|---|---|
| 02e50bb2f9 | |||
| fadc62c8f0 | |||
| 4759f6f7ee | |||
| 14f2164a82 | |||
| 14ef1f9bad | |||
| dc99318ff0 | |||
| d2fc5f4d5c | |||
| 938bd48fff | |||
| 96f819dc91 | |||
| 25eee8adf5 | |||
| d2b2a29d3d | |||
| 1cf71261d1 | |||
| 88552eb04f | |||
| ab92c99321 | |||
| 02963de893 |
@@ -81,7 +81,7 @@ app.use(require("./root"))
|
||||
app.use("/kfu-m-24-1", require("./routers/kfu-m-24-1"))
|
||||
app.use("/epja-2024-1", require("./routers/epja-2024-1"))
|
||||
app.use("/v1/todo", require("./routers/todo"))
|
||||
// app.use("/dogsitters-finder", require("./routers/dogsitters-finder"))
|
||||
app.use("/dogsitters-finder", require("./routers/dogsitters-finder"))
|
||||
app.use("/kazan-explore", require("./routers/kazan-explore"))
|
||||
app.use("/edateam", require("./routers/edateam-legacy"))
|
||||
app.use("/dry-wash", require("./routers/dry-wash"))
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
const { Router } = require("express");
|
||||
const hash = require("pbkdf2-password")();
|
||||
const { promisify } = require("node:util");
|
||||
const jwt = require('jsonwebtoken')
|
||||
|
||||
const { getAnswer } = require("../../utils/common");
|
||||
|
||||
const { AuthModel } = require("./model/todo/auth");
|
||||
const { TOKEN_KEY } = require('./const')
|
||||
const { UserModel } = require("./model/todo/user");
|
||||
|
||||
const { requiredValidate } = require('./utils')
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post(
|
||||
"/signup",
|
||||
requiredValidate("login", "password", "email"),
|
||||
async (req, res, next) => {
|
||||
const { login, password, email } = req.body
|
||||
|
||||
const user = await AuthModel.findOne({ login });
|
||||
|
||||
if (user) {
|
||||
throw new Error("Пользователь с таким логином уже существует");
|
||||
}
|
||||
|
||||
hash({ password }, async function (err, pass, salt, hash) {
|
||||
if (err) return next(err);
|
||||
|
||||
const user = await UserModel.create({ login, email });
|
||||
await AuthModel.create({ login, hash, salt, userId: user.id });
|
||||
|
||||
res.json(getAnswer(null, { ok: true }))
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
function authenticate(login, pass, cb) {
|
||||
AuthModel.findOne({ login }).populate('userId').exec().then((user) => {
|
||||
if (!user) return cb(null, null)
|
||||
|
||||
hash({ password: pass, salt: user.salt }, function (err, pass, salt, hash) {
|
||||
if (err) return cb(err)
|
||||
if (hash === user.hash) return cb(null, user)
|
||||
cb(null, null)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const auth = promisify(authenticate)
|
||||
|
||||
router.post('/signin', requiredValidate('login', 'password'), async (req, res) => {
|
||||
const { login, password } = req.body
|
||||
|
||||
const user = await auth(login, password)
|
||||
|
||||
if (!user) {
|
||||
throw new Error("Неверный логин или пароль")
|
||||
}
|
||||
|
||||
const accessToken = jwt.sign({
|
||||
...JSON.parse(JSON.stringify(user.userId)),
|
||||
}, TOKEN_KEY, {
|
||||
expiresIn: '12h'
|
||||
})
|
||||
|
||||
res.json(getAnswer(null, {
|
||||
user: user.userId,
|
||||
token: accessToken,
|
||||
}))
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,3 +1,2 @@
|
||||
exports.DSF_AUTH_PASSWD_MODEL_NAME = 'DSF_AUTH_PASSWD'
|
||||
exports.DSF_AUTH_USER_MODEL_NAME = 'DSF_AUTH_USER'
|
||||
exports.DSF_INTERACTION_MODEL_NAME = 'DSF_INTERACTION'
|
||||
|
||||
@@ -67,3 +67,5 @@ router.get("/auth/session", (request, response) => {
|
||||
return response.status(403).json({ error: "Invalid token" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router
|
||||
@@ -1,39 +1,69 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"phone_number": 89283244141,
|
||||
"first_name": "Вася",
|
||||
"second_name": "Пупкин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, улица Пушкина, 12",
|
||||
"price": 1500,
|
||||
"about_me": "Я люблю собак"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"phone_number": 89272844541,
|
||||
"first_name": "Ваня",
|
||||
"second_name": "Пуськин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, улица Абсалямова, 19",
|
||||
"price": 1000000,
|
||||
"about_me": "Я не люблю собак. И вообще я котоман."
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"phone_number": 89872855893,
|
||||
"first_name": "Гадий",
|
||||
"second_name": "Петрович",
|
||||
"role": "owner"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"phone_number": 89872844591,
|
||||
"first_name": "Галкин",
|
||||
"second_name": "Максим",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, проспект Ямашева, 83",
|
||||
"price": 1000000,
|
||||
"about_me": "Миллион алых роз"
|
||||
}
|
||||
]
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"phone_number": "89999999999",
|
||||
"first_name": "Вася",
|
||||
"second_name": "Пупкин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, Пушкина, 12",
|
||||
"price": "1500",
|
||||
"about_me": "Я люблю собак!",
|
||||
"rating": 5,
|
||||
"ratings": [
|
||||
5,
|
||||
5
|
||||
],
|
||||
"tg": "jullllllie"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"phone_number": 89272844541,
|
||||
"first_name": "Ваня",
|
||||
"second_name": "Пуськин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, улица Абсалямова, 19",
|
||||
"price": 2000,
|
||||
"about_me": "Я не люблю собак. И вообще я котоман.",
|
||||
"rating": 4,
|
||||
"ratings": [
|
||||
4,
|
||||
4
|
||||
],
|
||||
"tg": "vanya006"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"phone_number": 89559999999,
|
||||
"first_name": "Гадий",
|
||||
"second_name": "Петрович",
|
||||
"role": "owner"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"phone_number": 89872844591,
|
||||
"first_name": "Галкин",
|
||||
"second_name": "Максим",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, проспект Ямашева, 83",
|
||||
"price": 1750,
|
||||
"about_me": "Миллион алых роз",
|
||||
"rating": 4.5,
|
||||
"ratings": [
|
||||
4,
|
||||
5
|
||||
],
|
||||
"tg": "maks100500"
|
||||
}
|
||||
],
|
||||
"interactions": [
|
||||
{
|
||||
"owner_id": 3,
|
||||
"dogsitter_id": 4
|
||||
},
|
||||
{
|
||||
"owner_id": 1,
|
||||
"dogsitter_id": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
const { Schema, model } = require("mongoose");
|
||||
|
||||
const {
|
||||
DSF_AUTH_PASSWD_MODEL_NAME,
|
||||
DSF_AUTH_USER_MODEL_NAME,
|
||||
} = require("../../const");
|
||||
|
||||
const schema = new Schema({
|
||||
login: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true
|
||||
},
|
||||
hash: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
salt: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: DSF_AUTH_USER_MODEL_NAME
|
||||
},
|
||||
created: {
|
||||
type: Date,
|
||||
default: () => new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
|
||||
schema.set("toJSON", {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
transform: function (doc, ret) {
|
||||
delete ret._id;
|
||||
},
|
||||
});
|
||||
|
||||
schema.virtual("id").get(function () {
|
||||
return this._id.toHexString();
|
||||
});
|
||||
|
||||
exports.AuthModel = model(DSF_AUTH_PASSWD_MODEL_NAME, schema);
|
||||
Reference in New Issue
Block a user