Skip to content

Instantly share code, notes, and snippets.

@nazrdogan
Created May 23, 2014 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazrdogan/2f0395c28b88eaa96f02 to your computer and use it in GitHub Desktop.
Save nazrdogan/2f0395c28b88eaa96f02 to your computer and use it in GitHub Desktop.
Route
doctype
html
head
title=title
meta(name='viewport', content='width=device-width, initial-scale=1.0')
link(rel="stylesheet", href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css')
link(rel="stylesheet", href='/css/style.css')
script(src='http://code.jquery.com/jquery.js')
script(src='js/bootstrap.min.js')
body
ul
each item in value
li=item.friend.username
doctype
html
head
title=title
meta(name='viewport', content='width=device-width, initial-scale=1.0')
link(rel="stylesheet", href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css')
link(rel="stylesheet", href='/css/style.css')
script(src='http://code.jquery.com/jquery.js')
script(src='js/bootstrap.min.js')
body
if (user)
p You are currently logged in as #{user.username}
a(href="/logout") Logout
br
div(style='height:20px')
input#search(type="search", placeholder="Kullanıcı Arama")
br
h2#results
div#request(style='display:none')
button#button(type='button',) Send Request
button#buttonCancel(type='button') Cancel Request
script(src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js')
script(src="/js/main.js")
div(style='height:300px;margin-left:0px;float:left')
p Arkadaş Listem
button#status(style='display:none')
ul#list
script.
$.get( "/showRequestAccepted", function( data ) {
var obj=JSON.parse(data);
console.log(obj);
if(obj==''){
}
else
for(var i=0; i<=obj.length; i++) {
//$('#test').append(obj[i].friend.username);
$("#list").append("<li id='test'><div style='width:100px; height:100px;'>"+obj[i].friend.username+"<div></li>");
}
});
var passport = require('passport');
var Account = require('./models/account');
var Status = require("mongoose-friends").Status;
module.exports = function (app) {
app.get('/', function (req, res) {
res.render('index', { user : req.user });
});
app.get('/register', function(req, res) {
res.render('register', { });
});
app.post('/register', function(req, res) {
console.log(req.body.email);
Account.register(new Account({ username : req.body.username,email:req.body.email}),req.body.password, function(err, account) {
if (err) {
return res.render("register", {info: "Sorry. That username already exists. Try again."});
}
passport.authenticate('local')(req, res, function () {
res.redirect('/');
});
});
});
app.get('/login', function(req, res) {
res.render('login', { user : req.user });
});
/*
app.post('/login', passport.authenticate('local'), function(req, res) {
res.redirect('/profil');
});
*/
app.post('/login',
passport.authenticate('local', { successRedirect: '/profil',
failureRedirect: '/login'
})
);
app.get('/searching', function(req, res) {
Account.findOne({email: req.query.search}, function (err, sonuc) {
if (sonuc == null) {
res.send('kullanıcı bulunamadı')
}
else {
if (err) throw err
else
res.send({username:sonuc.username,user_id:sonuc._id});
}
});
});
app.post('/sendRequest',function(req,res){
console.log(req.user.username);
Account.requestFriend(req.user._id,req.body.user2,function(err,sonuc){
if(err) throw err
else
res.end('OK');
});
});
app.get('/showRequestPending',function(req,res){
Account.getFriends(req.user,{"friends.status":Status.Pending},function(err,sonuc){
if(err) throw err
var json;
// console.log(sonuc);
json=JSON.stringify(sonuc,null,4);
// console.log(json);
// res.render('profil',{json:json});
});
});
app.get('/showRequestAccepted',function(req,res){
Account.getFriends(req.user,{"friends.status":Status.Accepted},function(err,sonuc){
if(err) throw err
//Json'i formatted göstermek için null ve 4 boşluk için
else
var documents=JSON.stringify(sonuc,null,4);
res.send(documents);
});
});
app.get('/removeFriend',function(req,res){
Account.removeFriend(req.body.user2,req.user,function(err,sonuc){
if(err) throw err
else
res.send('ok');
});
});
app.get('/profil', function (req, res) {
res.render('profil', { user : req.user ,title:'profil'});
});
app.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
app.get('/ping', function(req, res){
res.send("pong!", 200);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment