Permalink
Browse files

退会機能を実装

  • Loading branch information...
1 parent 0a4cced commit ce4787b0d3cb03e5b7ed225f591a88bc5ca94303 @nsyee nsyee committed Nov 8, 2012
View
6 app.js
@@ -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: '/'
View
@@ -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: {
@@ -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'
}
}
});
@@ -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
});
});
@@ -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;
};
//オーナー判定
@@ -248,7 +246,6 @@ exports.show = function(req, res, next) {
isUrlOpen: isUrlOpen,
house_image: '',
dec_image: '',
- onetime_token: '',
chats: chats
});
});
View
@@ -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;
@@ -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);
+ });
+};
View
@@ -9,7 +9,6 @@ exports.new = function(req, res, next) {
var logger = app.set('logger');
res.render('register', {
- onetime_token: ''
});
};
@@ -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')
});
};
View
@@ -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'+
@@ -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'+
View
@@ -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'+
@@ -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'+
@@ -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'+
@@ -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'+
@@ -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'+
View
@@ -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;
@@ -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);
View
@@ -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);
Oops, something went wrong.

0 comments on commit ce4787b

Please sign in to comment.