Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Http, Headers } from '@angular/http';
- import 'rxjs/add/operator/map';
- @Injectable()
- export class MyProvider1 {
- data: any;
- constructor(public http: Http) {
- this.data = null;
- }
- login(id,pwd){
- let headers = new Headers();
- headers.append('Content-Type', 'application/json');
- this.http.post('http://localhost:8080/',
- JSON.stringify({
- username: id ,
- password: pwd
- }), {headers: headers})
- .subscribe(res => {
- console.log(res.json());
- });
- }
- }
- this.http.post('http://localhost:8080/',
- JSON.stringify({
- username: id ,
- password: pwd
- }))
- .subscribe(res => {
- console.log(res.json());
- });
- var express = require('express');
- var app = express();
- var bodyParser = require('body-parser');
- var morgan = require('morgan');
- var mongoose = require('mongoose');
- //------------------------------------
- //Configuration
- //------------------------------------
- var config = require('./config.js');
- var port = process.env.PORT || config.SERVICE_PORT;
- app.use(morgan('dev'));
- app.use(bodyParser.urlencoded({ extended: false }));
- app.use(bodyParser.json());
- //------------------------------------
- //Routes
- //------------------------------------
- app.use('/admin', require('./app/routes/admin.js'));
- app.use('/', require('./app/routes/guest.js'));
- app.use('/chat', require('./app/routes/chat.js'));
- //------------------------------------
- //Server Start
- //------------------------------------
- mongoose.connect(config.database);
- app.listen(port);
- console.log('server start at port ' + port);
- ...
- router.route('/')
- .get(function(req,res){
- res.end('Welcome');
- })
- .post(function(req,res){
- UsersManager.login(req.body.username,req.body.password,function(err,user){
- if(err) throw err;
- if(!user){
- res.json({
- success: false,
- message: Const.notificationTokenAccessNOK
- });
- }else{
- var token = TokenManager.createToken(user);
- res.json({
- success: true,
- message: Const.notificationTokenAccessOK,
- token: token
- });
- }
- });
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement