Im met behulp van alamofire om parse JSON aan te melden, im met behulp van MySQL database

stemmen
0

dat is mijn API-code met behulp van NodeJS, krijg ik op xcode console die de gebruiker zich met succes geregistreerd is, maar hij is niet toegevoegd aan de database, is het probleem op mijn api of in mijn swift source code? hulp alstublieft? i dnt denk dat het probleem is in mijn api oorzaak im testen op postbode en het werkt goed

app.post('/register/',(req,res,next)=>{
    var post_data = req.body;  //Get POST params
    var uid = uuid.v4();   //Get  UUID V4
    var plaint_password = post_data.password ;  //Get password from post params
    var hash_data = saltHashPassword(plaint_password);
    var password = hash_data.passwordHash;  //Get Hash value
    var salt = hash_data.salt; //Get salt

    var name = post_data.name;
    var email = post_data.email;
    var prenom = post_data.prenom
    var tel_user = post_data.tel_user;

    con.query('SELECT * FROM user where email=?',[email],function (err,result,fields) {
        con.on('error',function (err) {
            console.log('[MYSQL ERROR]',err);

        });
        if (result && result.length)
            res.json('Cette adresse mail est déjà utilisé');
        else {
            con.query('INSERT INTO `user`(`unique_id`, `name`, `email`, `encrypted_password`, `salt`, `created_at`, `updated_at`, `prenom`, `tel_user`) ' +
                'VALUES (?,?,?,?,?,NOW(),NOW(),?,?)',[uid,name,email,password,salt,prenom,tel_user],function (err,result,fields) {
                if (err) throw err;

                res.json('Vous ètes inscrit avec succés');

            })
        }
    });

})```

and that's how im using alamofire to parse json data 




@IBAction func btn_register (_ afzender: Any) {laten serverURL = http: // localhost: 1337 / register

    guard let email = emailtf.text, !email.isEmpty else {return}
    guard let password = passwordtf.text, !password.isEmpty else {return}
    guard let name = nametf.text, !name.isEmpty else {return}
    guard let prenom = prenomtf.text, !prenom.isEmpty else {return}
    guard let telephone = telephonetf.text, !telephone.isEmpty else {return}

    let registerRequest = [
        name : name,
        email : email,
        password : password,
         prenom : prenom,
        telephone : telephone,
    ]

    print(registerRequest)




          Alamofire.request(serverUrl, method: .post, parameters: registerRequest, encoding: JSONEncoding.default, headers: nil).responseJSON { (responseObject) -> Void in
                if responseObject.result.isSuccess {
                    let resJson = JSON(responseObject.result.value!)
                    print(resJson)



                }
                if responseObject.result.isFailure {
                    let error : Error = responseObject.result.error!
                    print(error)
                }


       }


}


i get on xcode console that the user is registered successfully but he's not added on the database, is it the problem on my api or in my swift source code? any help please? i dnt think that the problem is in my api cause im testing it on postman and it works good
De vraag is gesteld op 02/12/2019 om 23:54
bron van user
In andere talen...                            


1 antwoorden

Im met behulp van alamofire om parse JSON aan te melden, im met behulp van MySQL database

stemmen
0

dat is mijn API-code met behulp van NodeJS, krijg ik op xcode console die de gebruiker zich met succes geregistreerd is, maar hij is niet toegevoegd aan de database, is het probleem op mijn api of in mijn swift source code? hulp alstublieft? i dnt denk dat het probleem is in mijn api oorzaak im testen op postbode en het werkt goed

app.post('/register/',(req,res,next)=>{
    var post_data = req.body;  //Get POST params
    var uid = uuid.v4();   //Get  UUID V4
    var plaint_password = post_data.password ;  //Get password from post params
    var hash_data = saltHashPassword(plaint_password);
    var password = hash_data.passwordHash;  //Get Hash value
    var salt = hash_data.salt; //Get salt

    var name = post_data.name;
    var email = post_data.email;
    var prenom = post_data.prenom
    var tel_user = post_data.tel_user;

    con.query('SELECT * FROM user where email=?',[email],function (err,result,fields) {
        con.on('error',function (err) {
            console.log('[MYSQL ERROR]',err);

        });
        if (result && result.length)
            res.json('Cette adresse mail est déjà utilisé');
        else {
            con.query('INSERT INTO `user`(`unique_id`, `name`, `email`, `encrypted_password`, `salt`, `created_at`, `updated_at`, `prenom`, `tel_user`) ' +
                'VALUES (?,?,?,?,?,NOW(),NOW(),?,?)',[uid,name,email,password,salt,prenom,tel_user],function (err,result,fields) {
                if (err) throw err;

                res.json('Vous ètes inscrit avec succés');

            })
        }
    });

})```

and that's how im using alamofire to parse json data 




@IBAction func btn_register (_ afzender: Any) {laten serverURL = " http: // localhost: 1337 / register "

    guard let email = emailtf.text, !email.isEmpty else {return}
    guard let password = passwordtf.text, !password.isEmpty else {return}
    guard let name = nametf.text, !name.isEmpty else {return}
    guard let prenom = prenomtf.text, !prenom.isEmpty else {return}
    guard let telephone = telephonetf.text, !telephone.isEmpty else {return}

    let registerRequest = [
        "name" : name,
        "email" : email,
        "password" : password,
         "prenom" : prenom,
        "telephone" : telephone,
    ]

    print(registerRequest)




          Alamofire.request(serverUrl, method: .post, parameters: registerRequest, encoding: JSONEncoding.default, headers: nil).responseJSON { (responseObject) -> Void in
                if responseObject.result.isSuccess {
                    let resJson = JSON(responseObject.result.value!)
                    print(resJson)



                }
                if responseObject.result.isFailure {
                    let error : Error = responseObject.result.error!
                    print(error)
                }


       }


}


i get on xcode console that the user is registered successfully but he's not added on the database, is it the problem on my api or in my swift source code? any help please? i dnt think that the problem is in my api cause im testing it on postman and it works good
antwoordde op 02/12/2019 om 23:54
bron van user

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more