Skip to content

Commit

Permalink
Merge pull request #3 from talafarael/срфтпу
Browse files Browse the repository at this point in the history
срфтпу
  • Loading branch information
talafarael authored Mar 13, 2024
2 parents a33104f + c0c3d3b commit e490dc7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 43 deletions.
93 changes: 51 additions & 42 deletions src/Router/authLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,40 @@ const storage = new Storage({
})
const bucket = storage.bucket("storageafarel")
class authController {
async registration(req, res) {
async editprofileimage(req, res) {
try {
let fileName
if (!req.file) {
return res.status(400).json({
message: "Not all fields are filled in, please try again",
})
}
if (req.file) {
console.log("File found, trying to upload...")
const {token} = req.body
console.log("File found, trying to upload...")

const blob = bucket.file(req.file.originalname)
const blobStream = blob.createWriteStream()
const blob = bucket.file(req.file.originalname)
const blobStream = blob.createWriteStream()

blobStream.on("finish", () => {
console.log("Success")
})
blobStream.on("finish", () => {
console.log("Success")
})

blobStream.end(req.file.buffer)

const fileName = `https://storage.googleapis.com/storageafarel/${req.file.originalname}`

const {user, id} = await verifyToken(token, res)
user.img = fileName

await user.save()
return res.status(200).json({message: "regis good"})
} catch (e) {
console.error(e)
res.status(400).json({message: "Registration error"})
}
}
async registration(req, res) {
try {

blobStream.end(req.file.buffer)
}
if(req.file.originalname){
fileName = `https://storage.googleapis.com/storageafarel/${req.file.originalname}`
}
console.log(fileName)
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({
Expand Down Expand Up @@ -79,7 +89,7 @@ class authController {
tempData.setTempData(
"registrationData",
{
fileName,

name,
email,
chaecknum,
Expand All @@ -95,33 +105,33 @@ class authController {
}
}

async validateToken(req,res){
async validateToken(req, res) {
try {
const {token}=req.body
const {token} = req.body
if (!token) {
return res
.status(403)
.json({message: "Пользователь не авторизован"})
}
const decodedData = await jwt.verify(token, secret)
if(!decodedData ){
return res
.status(403)
.json({message: "Пользователь не авторизован"})
}
const decodedData = await jwt.verify(token, secret)
if (!decodedData) {
return res.status(400).json({
message: "Is not valid token",
});
})
}
const id = decodedData.id;
const user = await User.findById(id.trim());
const id = decodedData.id
const user = await User.findById(id.trim())
if (!user) {
return res.status(400).json({
message: "The user with this name does not exist",
});
return res.status(400).json({
message: "The user with this name does not exist",
})
}
return res.status(200).json({message: "valid good"})
} catch (error) {
} catch (error) {
return res.status(401).json({
message: "Invalid token",
});
}
message: "Invalid token",
})
}
}
async resendemail(req, res) {
try {
Expand All @@ -139,7 +149,7 @@ return res
tempData.setTempData(
"registrationData",
{
fileName: savedData.fileName,

name,
email,
chaecknum,
Expand All @@ -162,7 +172,7 @@ return res
.status(400)
.json({message: "Registration data not found"})
}
const {name, email, chaecknum,fileName} = savedData
const {name, email, chaecknum} = savedData

let status = savedData.status
if (status) {
Expand All @@ -175,7 +185,7 @@ return res
tempData.setTempData(
"registrationData",
{
fileName,

name,
email,
chaecknum,
Expand Down Expand Up @@ -237,11 +247,11 @@ return res
.json({message: "Registration data not found"})
}

const {name, email, chaecknum, hashPassword, status,fileName} = savedData
const {name, email, chaecknum, hashPassword, status} = savedData
console.log(name)
if (chaecknum == code) {
const user = new User({
img:fileName,

name: name,
email: email,
password: hashPassword,
Expand Down Expand Up @@ -294,8 +304,7 @@ return res
const token = generateAccessToken(user._id)
return res.status(200).json({
token: token,
balance:user.balance

balance: user.balance,
})
} catch (e) {
console.log(e)
Expand All @@ -307,7 +316,7 @@ return res
const {token} = req.body
const {user, id} = await verifyToken(token, res)
const userInfo = {
name:user.name,
name: user.name,
email: user.email,
balance: user.balance,
bidAuction: user.bidAuction,
Expand Down
1 change: 1 addition & 0 deletions src/authRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ router.post('/registration',type,controllerLogin.registration)
router.post('/resendemail',controllerLogin.resendemail)
router.post('/registercreate',controllerLogin.registerCreate)
router.get('/sendemail',controllerLogin.SendEmail)
router.post('/editprofileimage',type,controllerLogin.editprofileimage)
router.post('/validatetoken',controllerLogin.validateToken)
//aukction
router.get('/getauction',auctionController.getAuction)
Expand Down
3 changes: 2 additions & 1 deletion src/model/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const user = new Schema({
password: {type: String, required: true},
balance:{type:Number},
bidAuction:{type:[]},
ownAuction:{type:[]}
ownAuction:{type:[]},
img:{type:String}
})
module.exports= model("User", user)

0 comments on commit e490dc7

Please sign in to comment.