Skip to content

Commit

Permalink
Fixed the nickname changing bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Taehoon Kang committed Nov 11, 2012
1 parent 55be941 commit 70c92fb
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
13 changes: 4 additions & 9 deletions action/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
import models
import settings
import urllib

try:
import json
except ImportError:
import simplejson as json

class Article(Action):
def _captcha_validation(self, challenge, response):
Expand All @@ -37,10 +32,7 @@ def post(self, category_name):

@login_required
def put(self):
unqouted = urllib.unquote_plus(self.request.body).decode('utf8')
if unqouted[-1:] != '}':
unqouted = unqouted[:-1]
params = json.loads(unqouted)
params = self.get_json_payload()
article_id = int(params['id'])
article = models.Article.get_by_id(article_id)
if article.author.user != users.get_current_user():
Expand Down Expand Up @@ -83,6 +75,9 @@ def get(self, article_id):
self.article = models.Article.get_by_id(article_id)

if not self.is_ajax and not self.is_crawler:
if not self.article:
self.response.set_status(404)
return
self.redirect('/#!/%s/%d' % (urllib.quote(self.article.category.name.encode('utf8')), article_id))

if self.article:
Expand Down
6 changes: 1 addition & 5 deletions action/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
from lib.controller import Action
from lib.decorators import login_required
from models import User, UserNicknameHistory
try:
import json
except ImportError:
import simplejson as json

class Index(Action):
def get(self, user_id=None):
Expand All @@ -19,7 +15,7 @@ def get(self, user_id=None):

@login_required
def put(self):
params = json.loads(self.request.body)
params = self.get_json_payload()
me = User.get_current()
self.user = me
if me.nickname == params['nickname']:
Expand Down
Binary file removed bootstrap.pyc
Binary file not shown.
8 changes: 7 additions & 1 deletion lib/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ def _get_context(self):
self.__context['request'] = self.request
self.__context['response'] = self.response
self.__context['app'] = app_identity
return self.__context
return self.__context

def get_json_payload(self):
unqouted = urllib.unquote_plus(self.request.body).decode('utf8')
if unqouted[-1:] != '}':
unqouted = unqouted[:-1]
return json.loads(unqouted)

class Result(object):
DEFAULT = ''
Expand Down
2 changes: 1 addition & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class User(db.Model):
email_hash = db.StringProperty()

def nickname_exists(self, nickname):
return User.gql('WHERE user != :1 AND nickname = :2', self, nickname).get() != None
return User.gql('WHERE user != :1 AND nickname = :2', self.user, nickname).get() != None

def change_nickname(self, nickname):
db.run_in_transaction_options(xg_on, UserNicknameHistory(user=self, nickname=bleach.clean(self.nickname)).put)
Expand Down
Binary file removed models.pyc
Binary file not shown.
Binary file removed settings.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion static/js/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ var initializeModels = function() {
$.ajax({
type: "PUT",
url: "/user/me",
data: JSON.stringify(json),
data: encodeURIComponent(JSON.stringify(json)),
cache: false,
success: function(data) {
self.changed(data.user);
Expand Down
3 changes: 1 addition & 2 deletions templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ <h3>표현의 자유를 위한 노력 = 여러분의 지성을 믿습니다.</h3
</ul>
<h3>권리</h3>
<ul>
<li><!--[if lte IE 8]><span style="filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2); display: inline-block;"><![endif]--><span style="-webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -o-transform: rotate(180deg); -khtml-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); display: inline-block;">&copy;</span><!--[if lte IE 8]></span><![endif]--> Copyleft. 이 웹사이트/서비스에 대한 <a href="http://openalive.googlecode.com" target="_blank">소스코드</a>는 모두 <a href="http://www.gnu.org/licenses/lgpl.html" target="_blank">공개(LGPL)</a>되어 있습니다. 자유롭게 사용하실 수 있습니다. </li>
<li><!--[if lte IE 8]><span style="filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2); display: inline-block;"><![endif]--><span style="-webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -o-transform: rotate(180deg); -khtml-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); display: inline-block;">&copy;</span><!--[if lte IE 8]></span><![endif]--> Copyleft. 이 웹사이트/서비스에 대한 <a href="http://github.com/fguy/openalive" target="_blank">소스코드</a>는 모두 <a href="http://www.gnu.org/licenses/lgpl.html" target="_blank">공개(LGPL)</a>되어 있습니다. 자유롭게 사용하실 수 있습니다. </li>
<li>{% trans 'Open Alive' %} 서비스 개발자/운영자는 게시되는 글에 대한 권리를 일체 소유하지 않습니다.</li>
<li>소스코드외에 축적된 데이터는 차후 여건이 되는대로 민감한 정보(회원정보 등)를 제외하고 다운로드 가능한 형태로 제공하겠습니다. (Data Liberation)</li>
</ul>
<h3>도움</h3>
<ul>
Expand Down

0 comments on commit 70c92fb

Please sign in to comment.