Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- const express = require('express')
- const user_controller = require('../controller/user')
- const api = express.Router()
- // pagina de Inicio
- api.get('/index',function(req,res){
- res.render('index')
- })
- // Gestion de usuarios
- api.get('/usuarios',user_controller.getAllUsers)
- api.post('/usuarios',user_controller.newUser)
- api.get('/usuario',user_controller.getUser)
- api.post('/logear',user_controller.logear)
- api.post('/registrar',user_controller.registrar)
- module.exports = api
- function registrar(req,res){
- var bcrypt = require('bcrypt');
- var BCRYPT_SALT_ROUNDS = 12;
- var user = req.body.user;
- var email = req.body.email;
- var pass = req.body.pass;
- console.log('info: ' + user + ' ' + email + ' ' +pass);
- //console.log('perro: ' + req.body);
- // encriptamos la contraseña
- bcrypt.genSalt(10, function(err, salt) {
- if(error) throw error;
- else{
- bcrypt.hash(pass, BCRYPT_SALT_ROUNDS, function(err, hash) {
- pass = hash;
- });
- }
- });
- //bcrypt.hash(pass, BCRYPT_SALT_ROUNDS).then(function(hashedPassword) {pass = hashedPassword});
- conexion_db.query({ ... etc
- 'use strict'
- //configuracion del servidor
- const express = require('express');
- const bodyParser = require('body-parser');
- const app = express();
- app.use(bodyParser.urlencoded({extended:true}));
- app.use(bodyParser.json());
- app.set('view engine','jade');
- app.set('views', __dirname + '/views');
- app.use(express.static(__dirname + '/public'));
- const api = require('./routes');
- app.use('/api',api);
- module.exports = app
- $.ajax({
- url: 'http://localhost:3000/api/registrar',
- data: JSON.stringify({'user': $('#nick').val(),'email': $('#email').val(),'pass': $('#pass').val()}),
- type: "POST",
- dataType: 'json',
- success: function(json) {
- console.log("json: " + json.estado);
- console.log("json: " + json.user);
- console.log("json: " + json.pass);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement