Skip to content

Commit

Permalink
img user
Browse files Browse the repository at this point in the history
  • Loading branch information
talafarael committed Mar 10, 2024
1 parent d0a16ee commit a33104f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
47 changes: 43 additions & 4 deletions src/Router/authLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,46 @@ const Emailsend = require("../email")
const {json} = require("express")
const verifyToken = require("../middleware/verify")
const emailSender = new Emailsend()
const {Storage} = require("@google-cloud/storage")
const projectId = "commanding-ring-409619" // Get this from Google Cloud
const keyFilename = "mykey.json"
const generateAccessToken = (id) => {
const playold = {
id,
}
return jwt.sign(playold, secret, {expiresIn: "24h"})
}

const storage = new Storage({
projectId,
keyFilename,
})
const bucket = storage.bucket("storageafarel")
class authController {
async registration(req, res) {
try {
console.log("1")
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 blob = bucket.file(req.file.originalname)
const blobStream = blob.createWriteStream()

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

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 @@ -48,7 +78,13 @@ class authController {
const status = true
tempData.setTempData(
"registrationData",
{name, email, chaecknum, hashPassword, status},
{
fileName,
name,
email,
chaecknum,
hashPassword,
status},
30 * 60 * 1000
)

Expand Down Expand Up @@ -103,6 +139,7 @@ return res
tempData.setTempData(
"registrationData",
{
fileName: savedData.fileName,
name,
email,
chaecknum,
Expand All @@ -125,7 +162,7 @@ return res
.status(400)
.json({message: "Registration data not found"})
}
const {name, email, chaecknum} = savedData
const {name, email, chaecknum,fileName} = savedData

let status = savedData.status
if (status) {
Expand All @@ -138,6 +175,7 @@ return res
tempData.setTempData(
"registrationData",
{
fileName,
name,
email,
chaecknum,
Expand Down Expand Up @@ -199,10 +237,11 @@ return res
.json({message: "Registration data not found"})
}

const {name, email, chaecknum, hashPassword, status} = savedData
const {name, email, chaecknum, hashPassword, status,fileName} = savedData
console.log(name)
if (chaecknum == code) {
const user = new User({
img:fileName,
name: name,
email: email,
password: hashPassword,
Expand Down
2 changes: 1 addition & 1 deletion src/authRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var type = multer.single("img")
//authorization
router.post('/getuser',middlewareUser,controllerLogin.getUser)
router.post('/login', controllerLogin.login)
router.post('/registration',controllerLogin.registration)
router.post('/registration',type,controllerLogin.registration)
router.post('/resendemail',controllerLogin.resendemail)
router.post('/registercreate',controllerLogin.registerCreate)
router.get('/sendemail',controllerLogin.SendEmail)
Expand Down
1 change: 1 addition & 0 deletions src/model/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {model, Schema} = require("mongoose")
const user = new Schema({
img:{type: String},
name: {type: String},
email: {type: String, uniqne: true, required: true},
password: {type: String, required: true},
Expand Down

0 comments on commit a33104f

Please sign in to comment.