This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/login', (req, res, next) => { | |
var promise = userController.loginControl(req.body); | |
promise.then((loginControlResult) => { | |
if (loginControlResult.success) { | |
res.send({ token: loginControlResult.token, message: loginControlResult.message,success:true }); | |
} | |
else { | |
res.send({ message: loginControlResult.message ,success:false}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var should = require(‘should’); //ingilizce konuşuyor gibi assert yapmak için kullanışlı bir paket | |
var mongoose = require(‘mongoose’); | |
var User = require(‘../model/user’); | |
var request = require(‘supertest’); //test ortamında request ihtiyaçları için paket | |
var mocha = require(‘mocha’); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Api test', () => { | |
var apiUrl = 'http://localhost:4000'; | |
var token = ''; | |
var app = undefined; | |
//Testin her çalıştırılmasında çalışacak kısım | |
beforeEach(done => { | |
User.remove({ name: { $ne: 'TestUser' } }, err => { | |
if (err) { | |
console.error('User collection”ı temizlenirken hata oluştu'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var should = require('should'); //ingilizce konuşuyor gibi assert yapmak için kullanışlı bir paket | |
var mongoose = require('mongoose'); | |
var User = require('../model/user'); | |
var request = require('supertest'); //test ortamında request ihtiyaçları için paket | |
var mocha = require('mocha'); | |
describe('Api test', () => { | |
var apiUrl = 'http://localhost:4000'; | |
var token = ''; | |
var app = undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const bodyParser = require('body-parser'); //get post requestlerinin üzerinde ki bilgileri okuyabilmek için | |
const logger = require('morgan'); //log yapısı için kullanılan paket | |
const projectConfig = require('./config/projectConfig'); //proje için gereken global değişkenler | |
const mainRouter = require('./route/mainRouter'); //login olmadan kullanılacak url ler (nonapi) | |
const apiRuter = require('./route/apiRouter'); //api url leri | |
projectConfig.connectMongoDb(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mongoose = require('mongoose'); | |
var projectConfig = { | |
coreConfig: { | |
'mongoDb': 'mongodb://localhost:27017/meanAppDb', | |
'secretKey': 'meanstackapplication', | |
'port': process.env.PORT || 4000, | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const userModel = require('../model/user'); | |
const Port = require('../config/projectConfig').coreConfig.port; | |
const userController = require('../controller/userController'); | |
const router = express.Router(); | |
router.get('/', (req, res, next) => { | |
res.send(`api http://localhost:${Port}/api den yayın yapmaktadır. /login ve /register sayfalarından giriş yapablirsiniz.`); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
const userSchema = new Schema({ | |
name: { | |
type: String, | |
required: [true, 'isim alanı zorunlu alan'] | |
}, | |
password: { | |
type: String, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let UserModel = require('../model/user'); | |
let userManager = require('../dataManager/userManager'); | |
let jwt = require('jsonwebtoken'); | |
let coreConfig = require('../config/projectConfig').coreConfig; | |
var userController = { | |
loginControl: (user) => { | |
var promise = userManager.getUserByNameAndPassword(user); | |
return promise.then((result) => { | |
if (result.success) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mongoose = require('mongoose'); | |
let userModel = require('../model/user'); | |
var userManager = { | |
getUserByNameAndPassword: (userNameAndPasword) => { | |
return userModel.findOne({ | |
"name": userNameAndPasword.name | |
}).then((user) => { | |
console.log(user); | |
if (!user) { return { success: false, message: 'Böyle bir kullanıcı yok!' }; } |
OlderNewer