Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
退会機能を実装
Browse files Browse the repository at this point in the history
  • Loading branch information
nsyee-test-member committed Nov 8, 2012
1 parent 0a4cced commit ce4787b
Show file tree
Hide file tree
Showing 26 changed files with 585 additions and 373 deletions.
6 changes: 4 additions & 2 deletions app.js
Expand Up @@ -197,14 +197,16 @@ app.get ('/mypage', csrf, authenticated, mypageController.show);
app.get ('/users/new', csrf, authenticated, userController.new);
app.post('/users', authenticated, userController.create);
app.get ('/users/:id', csrf, mypageController.show);
app.del ('/users/:id', authenticated, userController.destroy);

app.get ('/confirm_deactivation', csrf, authenticated, mypageController.confirmDeactivation);
app.post ('/deactivation', authenticated, mypageController.deactivation);

app.get ('/login', userController.login);
app.post('/login', passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/login',
failureFlash: true
}));

app.get('/auth/twitter', passport.authenticate('twitter'));
app.get('/auth/twitter/callback', passport.authenticate('twitter', {
failureRedirect: '/'
Expand Down
11 changes: 11 additions & 0 deletions grunt.js
Expand Up @@ -67,6 +67,13 @@ module.exports = function(grunt) {
'public/js/registerApp.js'
],
dest: 'public/js/dist/register.js'
},
deactivation: {
src: [
'public/js/views/deactivation.js',
'public/js/deactivationApp.js'
],
dest: 'public/js/dist/register.js'
}
},
min: {
Expand Down Expand Up @@ -97,6 +104,10 @@ module.exports = function(grunt) {
register: {
src: 'public/js/dist/register.js',
dest: 'public/js/dist/register.min.js'
},
deactivation: {
src: 'public/js/dist/deactivation.js',
dest: 'public/js/dist/deactivation.min.js'
}
}
});
Expand Down
3 changes: 0 additions & 3 deletions lib/controllers/chatroom.js
Expand Up @@ -101,7 +101,6 @@ exports.new = function(req, res, next) {
Category.find(function(err, categories) {
if (err) { return next(err); }
res.render('createChatroom', {
onetime_token: '',
categories: categories
});
});
Expand Down Expand Up @@ -175,7 +174,6 @@ exports.show = function(req, res, next) {
if (err) { return next(err); }
if (!chatroom) {
return next(new utils.NotFound(req.url));
return;
};

//オーナー判定
Expand Down Expand Up @@ -248,7 +246,6 @@ exports.show = function(req, res, next) {
isUrlOpen: isUrlOpen,
house_image: '',
dec_image: '',
onetime_token: '',
chats: chats
});
});
Expand Down
31 changes: 30 additions & 1 deletion lib/controllers/mypage.js
Expand Up @@ -2,9 +2,9 @@ var app = require('../../app');
var Chatroom = require('../models/chatroom').Chatroom;
var User = require('../models/user').User;
var CONST = require('../const').CONST;
var utils = require('../utils');
var check = require('validator').check;


exports.show = function(req, res, next) {
var logger = app.set('logger');
var profileId = req.param('id') || req.user.id;
Expand All @@ -25,10 +25,39 @@ exports.show = function(req, res, next) {
}

User.findOneById(profileId, function(err, profile) {
if (!profile) {
return next(new utils.NotFound(req.url));
}

res.render('mypage', {
profile: profile,
isMine: isMine
});
});

};

exports.confirmDeactivation = function(req, res, next) {
var logger = app.set('logger');

res.render('deactivation', {
});
};

exports.deactivation = function(req, res, next) {
var logger = app.set('logger');
var _csrf = req.session._csrf;

//CSRF Check
if (_csrf !== req.param('token')) {
logger.error('CSRF Invalid');
return;
}

User.deactivate(req.user.id, function(err) {
//セッション破棄
req.logout();

res.json({}, 200);
});
};
9 changes: 0 additions & 9 deletions lib/controllers/user.js
Expand Up @@ -9,7 +9,6 @@ exports.new = function(req, res, next) {
var logger = app.set('logger');

res.render('register', {
onetime_token: ''
});
};

Expand Down Expand Up @@ -64,19 +63,11 @@ exports.create = function(req, res, next) {
});
};

exports.update = function(req, res, next) {
var logger = app.set('logger');
};

exports.destroy = function(req, res, next) {
var logger = app.set('logger');
};

exports.login = function(req, res, next) {
var logger = app.set('logger');

res.render('login', {
onetime_token: '',
error: req.flash('error')
});
};
Expand Down
7 changes: 5 additions & 2 deletions lib/models/chat.js
Expand Up @@ -17,6 +17,7 @@ Chat.find = function(params, next) {
var query = 'SELECT c.id, c.message, c.user_id, c.invited,'+
' u.name AS username, u.image AS userimage,'+
' CONCAT("/users/", u.id) AS userpage, '+
' u.`delete` AS isInactive, '+
' DATE_FORMAT(c.created_at, "%Y-%c-%d %k:%i:%s") AS time'+
' FROM chats c'+
' LEFT JOIN users u ON u.id = c.user_id'+
Expand Down Expand Up @@ -73,8 +74,10 @@ Chat.findLatest = function(params, next) {

client.query(
'SELECT c.id, c.user_id AS userId, c.message,'+
' u.name AS username, u.image AS userimage'+
' FROM chats c'+ ' LEFT JOIN users u ON u.id = c.user_id'+
' u.name AS username, u.image AS userimage,'+
' u.`delete` AS isInactive'+
' FROM chats c'+
' LEFT JOIN users u ON u.id = c.user_id'+
' WHERE c.chatroom_id = ? AND c.status <> 0'+
' AND c.user_id <> ?'+
' AND c.`delete` = false'+
Expand Down
23 changes: 14 additions & 9 deletions lib/models/chatroom.js
Expand Up @@ -14,10 +14,11 @@ Chatroom.find = function(params, next) {
var limit = params.limit;

client.query(
'SELECT cr.id, cr.title, cr.description, cr.status, '+
'SELECT cr.id, cr.title, cr.description, cr.status,'+
' cr.owner_id, cr.member, c.title AS category,'+
' u.name AS owner, u.image AS ownerimage,'+
' CONCAT("/users/", u.id) AS ownerpage'+
' CONCAT("/users/", u.id) AS ownerpage,'+
' u.`delete` AS isOwnerInactive'+
' FROM chatrooms cr'+
' LEFT JOIN category c ON c.id = cr.category_id'+
' LEFT JOIN users u ON u.id = cr.owner_id'+
Expand Down Expand Up @@ -70,7 +71,8 @@ Chatroom.findOneById = function(id, next) {
' cr.status, cr.public, c.title AS category,'+
' DATE_FORMAT(cr.created_at, "%Y年%m月%d日 %k:%i") AS date,'+
' u.name AS owner, u.image AS ownerimage,'+
' CONCAT("/users/", u.id) AS ownerpage'+
' CONCAT("/users/", u.id) AS ownerpage,'+
' u.`delete` AS isOwnerInactive'+
' FROM chatrooms cr'+
' LEFT JOIN category c ON c.id = cr.category_id'+
' LEFT JOIN users u ON u.id = cr.owner_id'+
Expand All @@ -96,10 +98,11 @@ Chatroom.findOwnerRoom = function(params, next) {
var limit = params.limit;

client.query(
'SELECT cr.id, cr.title, cr.description, cr.status, '+
'SELECT cr.id, cr.title, cr.description, cr.status,'+
' cr.member, c.title AS category,'+
' u.name AS owner, u.image AS ownerimage,'+
' CONCAT("/users/", u.id) AS ownerpage'+
' CONCAT("/users/", u.id) AS ownerpage,'+
' u.`delete` AS isOwnerInactive'+
' FROM chatrooms cr'+
' LEFT JOIN category c ON c.id = cr.category_id'+
' LEFT JOIN users u ON u.id = cr.owner_id'+
Expand All @@ -123,10 +126,11 @@ Chatroom.findEntryRoom = function(params, next) {
var limit = params.limit;

client.query(
'SELECT DISTINCT cr.id, cr.title, cr.description, cr.status, '+
'SELECT DISTINCT cr.id, cr.title, cr.description, cr.status,'+
' cr.member, c.title AS category,'+
' u.name AS owner, u.image AS ownerimage,'+
' CONCAT("/users/", u.id) AS ownerpage'+
' CONCAT("/users/", u.id) AS ownerpage,'+
' u.`delete` AS isOwnerInactive'+
' FROM chatrooms cr'+
' LEFT JOIN category c ON c.id = cr.category_id'+
' LEFT JOIN chats ch ON cr.id = ch.chatroom_id'+
Expand All @@ -153,10 +157,11 @@ Chatroom.findJoinRoom = function(params, next) {
var limit = params.limit;

client.query(
'SELECT cr.id, cr.title, cr.description, cr.status, '+
'SELECT cr.id, cr.title, cr.description, cr.status,'+
' cr.member, c.title AS category,'+
' u.name AS owner, u.image AS ownerimage,'+
' CONCAT("/users/", u.id) AS ownerpage'+
' CONCAT("/users/", u.id) AS ownerpage,'+
' u.`delete` AS isOwnerInactive'+
' FROM chatrooms cr'+
' LEFT JOIN category c ON c.id = cr.category_id'+
' LEFT JOIN users u ON u.id = cr.owner_id'+
Expand Down
17 changes: 17 additions & 0 deletions lib/models/user.js
Expand Up @@ -151,4 +151,21 @@ User.updateTwitterImage = function(params, next) {
);
};


User.deactivate = function(userId, next) {
var logger = app.set('logger');
var client = app.set('mySqlClient');

client.query(
'UPDATE users SET'+
' `delete`=true'+
' WHERE id = ?',
[userId],
function(err, results) {
if (err) { return next(err);}
return next(null);
}
);
};

exports.User = User;
10 changes: 10 additions & 0 deletions public/js/deactivationApp.js
@@ -0,0 +1,10 @@
(function() {
var syaberi = this.syaberi != null ? this.syaberi : this.syaberi = {};

$(function() {
var deactivationView = new syaberi.DeactivationView;
deactivationView.render();
Backbone.emulateHTTP = true;
});

}).call(this);
94 changes: 47 additions & 47 deletions public/js/dist/chatroom.js
Expand Up @@ -5,56 +5,56 @@
syaberi.templates.chat = {};

syaberi.templates.chat.chatL = Handlebars.compile(
'<div class="message-owner-inbox" id="chat-content-{{chatId}}">'+
'<div class="owner-icon">'+
'<a href="/users/{{userId}}"><img class="icon_m" src="{{userImage}}"></a>'+
'</div>'+
'<div class="owner-titlebox">'+
'<p class="owner-title">{{{message}}}</p>'+
'{{#if extImageUrl}}'+
'<img src="{{extImageUrl}}" class="owner-img">'+
'{{/if}}'+
'{{#if youtubeVid}}'+
'<iframe width="500" height="300" src="'+
'http://www.youtube.com/embed/{{youtubeVid}}"'+
' frameborder="0" allowfullscreen></iframe>'+
'{{/if}}'+
'<div class="owner-username"><a href="/users/{{userId}}">by.{{userName}}</a></div>'+
'<div class="owner-date">{{time}} [1]'+
'{{#if isHis}}'+
'<img src="/img/remove.gif" width="12" height="12" alt="閉じる" class="delete_cmt" data-chatid="{{chatId}}">'+
'{{/if}}'+
'</div>'+
'</div>'+
'</div>'
'<div class="message-owner-inbox" id="chat-content-{{chatId}}">\
<div class="owner-icon">\
<a href="/users/{{userId}}"><img class="icon_m" src="{{userImage}}"></a>\
</div>\
<div class="owner-titlebox">\
<p class="owner-title">{{{message}}}</p>\
{{#if extImageUrl}}\
<img src="{{extImageUrl}}" class="owner-img">\
{{/if}}\
{{#if youtubeVid}}\
<iframe width="500" height="300" src="\
http://www.youtube.com/embed/{{youtubeVid}}"\
frameborder="0" allowfullscreen></iframe>\
{{/if}}\
<div class="owner-username"><a href="/users/{{userId}}">by.{{userName}}</a></div>\
<div class="owner-date">{{time}} [1]\
{{#if isHis}}\
<img src="/img/remove.gif" width="12" height="12" alt="閉じる" class="delete_cmt" data-chatid="{{chatId}}">\
{{/if}}\
</div>\
</div>\
</div>'
);

syaberi.templates.chat.chatR = Handlebars.compile(
'<div class="message-member-inbox" id="chat-content-{{chatId}}">'+
'<div class="member-icon">'+
'<a href="/users/{{userId}}"><img class="icon_m" src="{{userImage}}"></a>'+
'</div>'+
'<div class="member-titlebox">'+
'<p class="member-title">{{{message}}}</p>'+
'{{#if extImageUrl}}'+
'<img src="{{extImageUrl}}" class="member-img">'+
'{{/if}}'+
'{{#if youtubeVid}}'+
'<iframe width="500" height="300" src="'+
'http://www.youtube.com/embed/{{youtubeVid}}"'+
' frameborder="0" allowfullscreen></iframe>'+
'{{/if}}'+
'<div class="member-username"><a href="/users/{{userId}}">by.{{userName}}</a></div>'+
'<div class="member-date">{{time}} [2]'+
'{{#if isHis}}'+
'<img src="/img/remove.gif" width="12" height="12" alt="閉じる" class="delete_cmt" data-chatid="{{chatId}}">'+
'{{/if}}'+
'</div>'+
'{{#if isInvite}}{{#unless isUrlOpen}}{{#if isOwner}}'+
'<a href="javascript:void(0);" class="start_chat" data-userid="{{userId}}" data-chatid="{{chatId}}">[招待]</a>'+
'{{/if}}{{/unless}}{{/if}}'+
'</div>'+
'</div>'
'<div class="message-member-inbox" id="chat-content-{{chatId}}">\
<div class="member-icon">\
<a href="/users/{{userId}}"><img class="icon_m" src="{{userImage}}"></a>\
</div>\
<div class="member-titlebox">\
<p class="member-title">{{{message}}}</p>\
{{#if extImageUrl}}\
<img src="{{extImageUrl}}" class="member-img">\
{{/if}}\
{{#if youtubeVid}}\
<iframe width="500" height="300" src="\
http://www.youtube.com/embed/{{youtubeVid}}"\
frameborder="0" allowfullscreen></iframe>\
{{/if}}\
<div class="member-username"><a href="/users/{{userId}}">by.{{userName}}</a></div>\
<div class="member-date">{{time}} [2]\
{{#if isHis}}\
<img src="/img/remove.gif" width="12" height="12" alt="閉じる" class="delete_cmt" data-chatid="{{chatId}}">\
{{/if}}\
</div>\
{{#if isInvite}}{{#unless isUrlOpen}}{{#if isOwner}}\
<a href="javascript:void(0);" class="start_chat" data-userid="{{userId}}" data-chatid="{{chatId}}">[招待]</a>\
{{/if}}{{/unless}}{{/if}}\
</div>\
</div>'
);

}).call(this);
Expand Down

0 comments on commit ce4787b

Please sign in to comment.