login
This commit is contained in:
parent
fb904dadd3
commit
63781ba7e2
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Iniciar",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/app.js",
|
||||
"stopOnEntry": false,
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"preLaunchTask": null,
|
||||
"runtimeExecutable": null,
|
||||
"runtimeArgs": [
|
||||
"--nolazy"
|
||||
],
|
||||
"env": {
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"console": "internalConsole",
|
||||
"sourceMaps": false,
|
||||
"outFiles": []
|
||||
},
|
||||
{
|
||||
"name": "Asociar",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"port": 5858,
|
||||
"address": "localhost",
|
||||
"restart": false,
|
||||
"sourceMaps": false,
|
||||
"outFiles": [],
|
||||
"localRoot": "${workspaceRoot}",
|
||||
"remoteRoot": null
|
||||
},
|
||||
{
|
||||
"name": "Asociar al proceso",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"processId": "${command.PickProcess}",
|
||||
"port": 5858,
|
||||
"sourceMaps": false,
|
||||
"outFiles": []
|
||||
},
|
||||
{
|
||||
"name": "Iniciar node-server",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}\\@salix-services\\login\\server\\server.js",
|
||||
"stopOnEntry": false,
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"preLaunchTask": null,
|
||||
"runtimeExecutable": null,
|
||||
"runtimeArgs": [
|
||||
"--nolazy"
|
||||
],
|
||||
"env": {
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"console": "internalConsole",
|
||||
"sourceMaps": false,
|
||||
"outFiles": []
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<h1>prueba</h1>
|
||||
</html>
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
module.exports = function(app) {
|
||||
var User = app.models.User;
|
||||
console.log(app.models.AccessToken);
|
||||
User.create ({
|
||||
email: 'admin@admin.com',
|
||||
password: '1234'
|
||||
}, function (err, user) {
|
||||
console.log ('User created!');
|
||||
});
|
||||
};
|
|
@ -3,9 +3,11 @@
|
|||
module.exports = function(server) {
|
||||
// Install a `/` route that returns server status
|
||||
var router = server.loopback.Router();
|
||||
|
||||
router.get('/status', server.loopback.status());
|
||||
router.get(['/'],function(req,res){
|
||||
res.send("Hello");
|
||||
res.send('hello');
|
||||
});
|
||||
|
||||
server.use(router);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
module.exports = function(app) {
|
||||
var User = app.models.User;
|
||||
app.get('/login',(req,res)=>{
|
||||
res.render('index.ejs',{});
|
||||
});
|
||||
|
||||
app.post('/login', function(req, res) {
|
||||
User.login({
|
||||
email: req.body.email,
|
||||
password: req.body.password
|
||||
}, 'user', function(err, token) {
|
||||
if (err) {
|
||||
res.send(JSON.stringify({
|
||||
title: 'Login failed',
|
||||
content: err,
|
||||
redirectTo: '/',
|
||||
redirectToLinkText: 'Try again'
|
||||
}));
|
||||
} else {
|
||||
res.send(JSON.stringify({
|
||||
email: req.body.email,
|
||||
accessToken: token.id
|
||||
}));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1 +1,9 @@
|
|||
{}
|
||||
{
|
||||
|
||||
"db": {
|
||||
"name": "db",
|
||||
"connector": "memory",
|
||||
"file": "myToken.json"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"compression": {},
|
||||
"cors": {
|
||||
"params": {
|
||||
"origin": true,
|
||||
"origin": "*",
|
||||
"credentials": true,
|
||||
"maxAge": 86400
|
||||
}
|
||||
|
|
|
@ -12,5 +12,14 @@
|
|||
"../common/mixins",
|
||||
"./mixins"
|
||||
]
|
||||
},
|
||||
"User": {
|
||||
"dataSource": "db",
|
||||
"public": false
|
||||
},
|
||||
"AccessToken": {
|
||||
"dataSource": "db",
|
||||
"public": false,
|
||||
"strict": true
|
||||
}
|
||||
}
|
|
@ -2,15 +2,25 @@
|
|||
|
||||
var loopback = require('loopback');
|
||||
var boot = require('loopback-boot');
|
||||
|
||||
var express=require('express');
|
||||
var path = require('path');
|
||||
var app = module.exports = loopback();
|
||||
|
||||
|
||||
// modificado
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views',path.join(__dirname,'../client'));
|
||||
app.use(loopback.static(path.resolve(__dirname, '../client')));
|
||||
// fin
|
||||
|
||||
|
||||
|
||||
app.start = function() {
|
||||
// start the web server
|
||||
return app.listen(function() {
|
||||
app.emit('started');
|
||||
var baseUrl = app.get('url').replace(/\/$/, '');
|
||||
console.log('Web server listening at: %s', baseUrl);
|
||||
console.log('Web server LOGIN listening at: %s', baseUrl);
|
||||
if (app.get('loopback-component-explorer')) {
|
||||
var explorerPath = app.get('loopback-component-explorer').mountPath;
|
||||
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
|
||||
|
|
|
@ -60,4 +60,9 @@ export const COMPONENT =
|
|||
};
|
||||
|
||||
module.component('vnLogin', COMPONENT);
|
||||
module.config(['$httpProvider', function($httpProvider) {
|
||||
$httpProvider.defaults.useXDomain = true;
|
||||
delete $httpProvider.defaults.headers.common['X-Requested-With'];
|
||||
}
|
||||
]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue