Пример #1
0
def SettingsHandler(request):
    if request.method == 'GET':
        site = GetSite()
        browser = detect(request)
        session = request.session
        template_values = {}
        template_values['site'] = site
        template_values['system_version'] = SYSTEM_VERSION
        member = CheckAuth(request)
        l10n = GetMessages(member, site)
        template_values['l10n'] = l10n
        template_values[
            'page_title'] = site.title + u' › ' + l10n.settings.decode('utf-8')
        if (member):
            template_values['member'] = member
            template_values['member_realname'] = member.truename
            template_values['member_sex'] = member.sex
            template_values['member_username'] = member.user.username
            template_values['member_email'] = member.user.email
            if (member.website == None):
                member.website = ''
            template_values['member_website'] = member.website
            if (member.twitter == None):
                member.twitter = ''
            template_values['member_twitter'] = member.twitter
            if (member.location == None):
                member.location = ''
            if member.psn is None:
                member.psn = ''
            template_values['member_psn'] = member.psn
            if (member.my_home == None):
                member.my_home = ''
            template_values['member_my_home'] = member.my_home
            template_values['member_btc'] = member.btc
            template_values['member_location'] = member.location
            if (member.tagline == None):
                member.tagline = ''
            template_values['member_tagline'] = member.tagline
            if (member.bio == None):
                member.bio = ''
            template_values['member_bio'] = member.bio
            template_values['member_show_home_top'] = member.show_home_top
            template_values['member_show_quick_post'] = member.show_quick_post
            if member.l10n is None:
                member.l10n = 'en'
            template_values['member_l10n'] = member.l10n
            s = GetLanguageSelect(member.l10n)
            template_values['s'] = s
            if member.twitter_sync == 1:
                template_values['member_twitter_sync'] = 1
            if member.use_my_css == 1:
                template_values['member_use_my_css'] = 1
            if (member.my_css == None):
                member.my_css = ''
            template_values['member_my_css'] = member.my_css
            if 'message' in session:
                message = session['message']
                del session['message']
            else:
                message = None
            template_values['message'] = message
            try:
                blocked = pickle.loads(member.blocked.encode('utf-8'))
            except:
                blocked = []
            template_values['member_stats_blocks'] = len(blocked)
            if browser['ios']:
                path = os.path.join('mobile', 'member_settings.html')
            else:
                path = os.path.join('desktop', 'member_settings.html')
            return render_to_response(path, template_values)
        else:
            return HttpResponseRedirect('/signin')

    else:
        session = request.session
        site = GetSite()
        browser = detect(request)
        template_values = {}
        template_values['site'] = site
        template_values['system_version'] = SYSTEM_VERSION
        errors = 0
        member = CheckAuth(request)
        l10n = GetMessages(member, site)
        template_values['l10n'] = l10n
        template_values[
            'page_title'] = site.title + u' › ' + l10n.settings.decode('utf-8')
        if (member):
            template_values['member'] = member
            template_values['member_realname'] = member.truename
            template_values['member_sex'] = member.sex
            template_values['member_username'] = member.user.username
            template_values['member_email'] = member.user.email
            template_values['member_website'] = member.website
            template_values['member_twitter'] = member.twitter
            # Verification: realname
            member_realname_error = 0
            member_realname_error_messages = [
                '',
                l10n.realname_empty,
                l10n.realname_too_long,
            ]
            member_realname = request.POST['realname'].strip()
            if (len(member_realname) == 0):
                errors = errors + 1
                member_realname_error = 1
            else:
                if (len(member_realname) > 20):
                    errors = errors + 1
                    member_realname_error = 2
            template_values['member_realname'] = member_realname
            template_values['member_realname_error'] = member_realname_error
            template_values[
                'member_realname_error_message'] = member_realname_error_messages[
                    member_realname_error]
            # Verification: sex
            member_sex_error = 0
            member_sex_error_messages = [
                '',
                l10n.sex_empty,
            ]
            if 'sex' in request.POST:
                member_sex = request.POST['sex'].strip()
            else:
                member_sex = ''
            if (len(member_sex) == 0):
                errors = errors + 1
                member_sex_error = 1
            template_values['member_sex'] = member_sex
            template_values['member_sex_error'] = member_sex_error
            template_values[
                'member_sex_error_message'] = member_sex_error_messages[
                    member_sex_error]
            # Verification: username
            member_username_error = 0
            member_username_error_messages = [
                '', l10n.username_empty, l10n.username_too_long,
                l10n.username_too_short, l10n.username_invalid,
                l10n.username_taken, '你已经更改过一次账户'
            ]
            member_username = request.POST['username'].strip()
            if (len(member_username) == 0):
                errors = errors + 1
                member_username_error = 1
            else:
                if (len(member_username) > 16):
                    errors = errors + 1
                    member_username_error = 2
                else:
                    if (len(member_username) < 3):
                        errors = errors + 1
                        member_username_error = 3
                    else:
                        if (re.search('^[a-zA-Z0-9\_]+$', member_username)):
                            q = Member.objects.filter(
                                username_lower=member_username.lower(
                                )).exclude(id=member.id)
                            if len(q) > 0:
                                errors = errors + 1
                                member_username_error = 5
                            else:
                                if request.user.username != member_username and member.username_editable == 0:
                                    errors = errors + 1
                                    member_username_error = 6
                        else:
                            errors = errors + 1
                            member_username_error = 4
            template_values['member_username'] = member_username
            template_values['member_username_error'] = member_username_error
            template_values[
                'member_username_error_message'] = member_username_error_messages[
                    member_username_error]
            # Verification: email
            member_email_error = 0
            member_email_error_messages = [
                '', u'请输入你的电子邮件地址', u'电子邮件地址长度不能超过 32 个字符', u'你输入的电子邮件地址不符合规则',
                u'抱歉这个电子邮件地址已经有人注册过了'
            ]
            if 'email' in request.POST:
                member_email = request.POST['email'].strip()
            else:
                member_email = ''
            if (len(member_email) == 0):
                errors = errors + 1
                member_email_error = 1
            else:
                if (len(member_email) > 32):
                    errors = errors + 1
                    member_email_error = 2
                else:
                    p = re.compile(
                        r"(?:^|\s)[-a-z0-9_.]+@(?:[-a-z0-9]+\.)+[a-z]{2,6}(?:\s|$)",
                        re.IGNORECASE)
                    if (p.search(member_email)):
                        q = User.objects.filter(
                            email=member_email.lower()).exclude(
                                id=request.user.id)
                        if (len(q) > 0):
                            errors = errors + 1
                            member_email_error = 4
                    else:
                        errors = errors + 1
                        member_email_error = 3
            template_values['member_email'] = member_email
            template_values['member_email_error'] = member_email_error
            template_values[
                'member_email_error_message'] = member_email_error_messages[
                    member_email_error]
            # Verification: website
            member_website_error = 0
            member_website_error_messages = [
                '', u'个人网站地址长度不能超过 200 个字符', u'这个网站地址不符合规则'
            ]
            member_website = request.POST['website'].strip()
            if (len(member_website) == 0):
                member_website = ''
            else:
                if (len(member_website) > 200):
                    errors = errors + 1
                    member_website_error = 1
                else:
                    p = re.compile(
                        'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
                    )
                    if (p.search(member_website)):
                        errors = errors
                    else:
                        errors = errors + 1
                        member_website_error = 2
            template_values['member_website'] = member_website
            template_values['member_website_error'] = member_website_error
            template_values[
                'member_website_error_message'] = member_website_error_messages[
                    member_website_error]
            # Verification: Twitter
            member_twitter_error = 0
            member_twitter_error_messages = [
                '', u'Twitter 用户名长度不能超过 20 个字符', u'Twitter 用户名不符合规则'
            ]
            member_twitter = request.POST['twitter'].strip()
            if (len(member_twitter) == 0):
                member_twitter = ''
            else:
                if (len(member_twitter) > 20):
                    errors = errors + 1
                    member_twitter_error = 1
                else:
                    p = re.compile('[a-zA-Z0-9\_]+')
                    if (p.search(member_twitter)):
                        errors = errors
                    else:
                        errors = errors + 1
                        member_twitter_error = 2
            template_values['member_twitter'] = member_twitter
            template_values['member_twitter_error'] = member_twitter_error
            template_values[
                'member_twitter_error_message'] = member_twitter_error_messages[
                    member_twitter_error]
            # Verification: psn
            member_psn_error = 0
            member_psn_error_messages = [
                '', u'PSN ID 长度不能超过 20 个字符', u'PSN ID 不符合规则'
            ]
            member_psn = request.POST['psn'].strip()
            if (len(member_psn) == 0):
                member_psn = ''
            else:
                if (len(member_psn) > 20):
                    errors = errors + 1
                    member_psn_error = 1
                else:
                    p = re.compile('^[a-zA-Z0-9\-\_]+$')
                    if (p.search(member_psn)):
                        errors = errors
                    else:
                        errors = errors + 1
                        member_psn_error = 2
            template_values['member_psn'] = member_psn
            template_values['member_psn_error'] = member_psn_error
            template_values[
                'member_psn_error_message'] = member_psn_error_messages[
                    member_psn_error]
            # Verification: my_home
            member_my_home_error = 0
            member_my_home_error_messages = [
                '', u'不是一个合法的自定义首页跳转位置', u'自定义首页跳转位置长度不能超过 32 个字符',
                u'自定义首页跳转位置必须以 / 开头'
            ]
            member_my_home = request.POST['my_home'].strip()
            if len(member_my_home) > 0:
                if member_my_home == '/' or member_my_home.startswith(
                        '/signout'):
                    member_my_home_error = 1
                    errors = errors + 1
                else:
                    if len(member_my_home) > 32:
                        member_my_home_error = 2
                        errors = errors + 1
                    else:
                        if member_my_home.startswith('/') is not True:
                            member_my_home_error = 3
                            errors = errors + 1
            template_values['member_my_home'] = member_my_home
            template_values['member_my_home_error'] = member_my_home_error
            template_values[
                'member_my_home_error_message'] = member_my_home_error_messages[
                    member_my_home_error]
            # Verification: btc
            member_btc_error = 0
            member_btc_error_messages = [
                '', u'BTC 收款地址长度不能超过 40 个字符', u'BTC 收款地址不符合规则'
            ]
            member_btc = request.POST['btc'].strip()
            if (len(member_btc) == 0):
                member_btc = ''
            else:
                if (len(member_btc) > 40):
                    errors = errors + 1
                    member_btc_error = 1
                else:
                    p = re.compile('^[a-zA-Z0-9]+$')
                    if (p.search(member_btc)):
                        errors = errors
                    else:
                        errors = errors + 1
                        member_btc_error = 2
            template_values['member_btc'] = member_btc
            template_values['member_btc_error'] = member_btc_error
            template_values[
                'member_btc_error_message'] = member_btc_error_messages[
                    member_btc_error]
            # Verification: location
            member_location_error = 0
            member_location_error_messages = ['', u'所在地长度不能超过 40 个字符']
            member_location = request.POST['location'].strip()
            if (len(member_location) == 0):
                member_location = ''
            else:
                if (len(member_location) > 40):
                    errors = errors + 1
                    member_location_error = 1
            template_values['member_location'] = member_location
            template_values['member_location_error'] = member_location_error
            template_values[
                'member_location_error_message'] = member_location_error_messages[
                    member_location_error]
            # Verification: tagline
            member_tagline_error = 0
            member_tagline_error_messages = ['', u'个人签名长度不能超过 70 个字符']
            member_tagline = request.POST['tagline'].strip()
            if (len(member_tagline) == 0):
                member_tagline = ''
            else:
                if (len(member_tagline) > 70):
                    errors = errors + 1
                    member_tagline_error = 1
            template_values['member_tagline'] = member_tagline
            template_values['member_tagline_error'] = member_tagline_error
            template_values[
                'member_tagline_error_message'] = member_tagline_error_messages[
                    member_tagline_error]
            # Verification: bio
            member_bio_error = 0
            member_bio_error_messages = ['', u'个人简介长度不能超过 2000 个字符']
            member_bio = request.POST['bio'].strip()
            if (len(member_bio) == 0):
                member_bio = ''
            else:
                if (len(member_bio) > 2000):
                    errors = errors + 1
                    member_bio_error = 1
            template_values['member_bio'] = member_bio
            template_values['member_bio_error'] = member_bio_error
            template_values[
                'member_bio_error_message'] = member_bio_error_messages[
                    member_bio_error]
            # Verification: show_home_top and show_quick_post
            try:
                member_show_home_top = int(request.POST['show_home_top'])
            except:
                member_show_home_top = 1
            template_values['member_show_home_top'] = member_show_home_top
            try:
                member_show_quick_post = int(request.POST['show_quick_post'])
            except:
                member_show_quick_post = 0
            template_values['member_show_quick_post'] = member_show_quick_post
            if member_show_home_top not in [0, 1]:
                member_show_home_top = 1
            if member_show_quick_post not in [0, 1]:
                member_show_quick_post = 0
            # Verification: l10n
            member_l10n = request.POST['l10n'].strip()
            supported = GetSupportedLanguages()
            if member_l10n == '':
                member_l10n = site.l10n
            else:
                if member_l10n not in supported:
                    member_l10n = site.l10n
            s = GetLanguageSelect(member_l10n)
            template_values['s'] = s
            template_values['member_l10n'] = member_l10n
            # Verification: twitter_sync
            if member.twitter_oauth == 1:
                if 'twitter_sync' in request.POST:
                    member_twitter_sync = request.POST['twitter_sync']
                else:
                    member_twitter_sync = ''
                if member_twitter_sync == 'on':
                    member_twitter_sync = 1
                else:
                    member_twitter_sync = 0
                template_values['member_twitter_sync'] = member_twitter_sync
            # Verification: use_my_css
            member_use_my_css = None
            if 'use_my_css' in request.POST:
                member_use_my_css = request.POST['use_my_css']
            else:
                member_use_my_css = ''
            if member_use_my_css == 'on':
                member_use_my_css = 1
            else:
                member_use_my_css = 0
            template_values['member_use_my_css'] = member_use_my_css
            # Verification: my_css
            member_my_css_error = 0
            member_my_css_error_messages = [
                '', u'CSS Hack cannot be longer than 2000 characters'
            ]
            member_my_css = request.POST['my_css'].strip()
            if (len(member_my_css) == 0):
                member_my_css = ''
            else:
                if (len(member_my_css) > 2000):
                    errors = errors + 1
                    member_my_css_error = 1
            template_values['member_my_css'] = member_my_css
            template_values['member_my_css_error'] = member_my_css_error
            template_values[
                'member_my_css_error_message'] = member_my_css_error_messages[
                    member_my_css_error]
            template_values['errors'] = errors
            if (errors == 0):
                user = request.user
                member.truename = member_realname
                member.sex = member_sex
                # 如果用户更改了账户,则editable置为0
                if user.username != member_username:
                    user.username = member_username
                    member.username_editable = 0
                    member.username_lower = member_username.lower()
                user.email = member_email.lower()
                member.website = member_website
                member.twitter = member_twitter
                member.psn = member_psn
                member.btc = member_btc
                member.location = member_location
                member.tagline = member_tagline
                if member.twitter_oauth == 1:
                    member.twitter_sync = member_twitter_sync
                member.use_my_css = member_use_my_css
                member.my_css = member_my_css
                if member_my_home_error == 0 and len(member_my_home) > 0:
                    member.my_home = member_my_home
                else:
                    if member_my_home_error == 0:
                        member.my_home = ''
                member.bio = member_bio
                member.show_home_top = member_show_home_top
                member.show_quick_post = member_show_quick_post
                member.l10n = member_l10n
                user.save()
                member.save()
                memcache.delete('Member::' + str(member.user.username))
                memcache.delete('Member::' + str(member.username_lower))
                memcache.set('Member_' + str(member.num), member, 86400)
                session['message'] = '个人设置成功更新'
                return HttpResponseRedirect('/settings')
            else:
                if browser['ios']:
                    path = os.path.join('mobile', 'member_settings.html')
                else:
                    path = os.path.join('desktop', 'member_settings.html')
            return render_to_response(path, template_values)
        else:
            return HttpResponseRedirect('/signin')
Пример #2
0
def SettingsHandler(request):
    if request.method == 'GET':
        site = GetSite()
        browser = detect(request)
        session = request.session
        template_values = {}
        template_values['site'] = site
        template_values['system_version'] = SYSTEM_VERSION
        member = CheckAuth(request)
        l10n = GetMessages(member, site)
        template_values['l10n'] = l10n
        template_values['page_title'] = site.title + u' › ' + l10n.settings.decode('utf-8')
        if (member):
            template_values['member'] = member
            template_values['member_realname'] = member.truename
            template_values['member_sex'] = member.sex
            template_values['member_username'] = member.user.username
            template_values['member_email'] = member.user.email
            if (member.website == None):
                member.website = ''
            template_values['member_website'] = member.website
            if (member.twitter == None):
                member.twitter = ''
            template_values['member_twitter'] = member.twitter
            if (member.location == None):
                member.location = ''
            if member.psn is None:
                member.psn = ''
            template_values['member_psn'] = member.psn
            if (member.my_home == None):
                member.my_home = ''
            template_values['member_my_home'] = member.my_home
            template_values['member_btc'] = member.btc
            template_values['member_location'] = member.location
            if (member.tagline == None):
                member.tagline = ''
            template_values['member_tagline'] = member.tagline
            if (member.bio == None):
                member.bio = ''
            template_values['member_bio'] = member.bio
            template_values['member_show_home_top'] = member.show_home_top
            template_values['member_show_quick_post'] = member.show_quick_post
            if member.l10n is None:
                member.l10n = 'en'
            template_values['member_l10n'] = member.l10n
            s = GetLanguageSelect(member.l10n)
            template_values['s'] = s
            if member.twitter_sync == 1:
                template_values['member_twitter_sync'] = 1
            if member.use_my_css == 1:
                template_values['member_use_my_css'] = 1
            if (member.my_css == None):
                member.my_css = ''
            template_values['member_my_css'] = member.my_css
            if 'message' in session:
                message = session['message']
                del session['message']
            else:
                message = None
            template_values['message'] = message
            try:
                blocked = pickle.loads(member.blocked.encode('utf-8'))
            except:
                blocked = []
            template_values['member_stats_blocks'] = len(blocked)
            if browser['ios']:
                path = os.path.join('mobile', 'member_settings.html')
            else:
                path = os.path.join('desktop', 'member_settings.html')
            return render_to_response(path, template_values)
        else:
            return HttpResponseRedirect('/signin')

    else:
        session = request.session
        site = GetSite()
        browser = detect(request)
        template_values = {}
        template_values['site'] = site
        template_values['system_version'] = SYSTEM_VERSION
        errors = 0
        member = CheckAuth(request)
        l10n = GetMessages(member, site)
        template_values['l10n'] = l10n
        template_values['page_title'] = site.title + u' › ' + l10n.settings.decode('utf-8')
        if (member):
            template_values['member'] = member
            template_values['member_realname'] = member.truename
            template_values['member_sex'] = member.sex
            template_values['member_username'] = member.user.username
            template_values['member_email'] = member.user.email
            template_values['member_website'] = member.website
            template_values['member_twitter'] = member.twitter
            # Verification: realname
            member_realname_error = 0
            member_realname_error_messages = ['',
                l10n.realname_empty,
                l10n.realname_too_long,]
            member_realname = request.POST['realname'].strip()
            if (len(member_realname) == 0):
                errors = errors + 1
                member_realname_error = 1
            else:
                if (len(member_realname) > 20):
                    errors = errors + 1
                    member_realname_error = 2
            template_values['member_realname'] = member_realname
            template_values['member_realname_error'] = member_realname_error
            template_values['member_realname_error_message'] = member_realname_error_messages[member_realname_error]
            # Verification: sex
            member_sex_error = 0
            member_sex_error_messages = ['',
                l10n.sex_empty,]
            if 'sex' in request.POST:
                member_sex = request.POST['sex'].strip()
            else:
                member_sex = ''
            if (len(member_sex) == 0):
                errors = errors + 1
                member_sex_error = 1
            template_values['member_sex'] = member_sex
            template_values['member_sex_error'] = member_sex_error
            template_values['member_sex_error_message'] = member_sex_error_messages[member_sex_error]
            # Verification: username
            member_username_error = 0
            member_username_error_messages = ['',
                l10n.username_empty,
                l10n.username_too_long,
                l10n.username_too_short,
                l10n.username_invalid,
                l10n.username_taken,
                '你已经更改过一次账户']
            member_username = request.POST['username'].strip()
            if (len(member_username) == 0):
                errors = errors + 1
                member_username_error = 1
            else:
                if (len(member_username) > 16):
                    errors = errors + 1
                    member_username_error = 2
                else:
                    if (len(member_username) < 3):
                        errors = errors + 1
                        member_username_error = 3
                    else:
                        if (re.search('^[a-zA-Z0-9\_]+$', member_username)):
                            q = Member.objects.filter(username_lower=member_username.lower()).exclude(id=member.id)
                            if len(q) > 0:
                                errors = errors + 1
                                member_username_error = 5
                            else:
                                if request.user.username != member_username and member.username_editable == 0:
                                    errors = errors + 1
                                    member_username_error = 6
                        else:
                            errors = errors + 1
                            member_username_error = 4
            template_values['member_username'] = member_username
            template_values['member_username_error'] = member_username_error
            template_values['member_username_error_message'] = member_username_error_messages[member_username_error]
            # Verification: email
            member_email_error = 0
            member_email_error_messages = ['',
                u'请输入你的电子邮件地址',
                u'电子邮件地址长度不能超过 32 个字符',
                u'你输入的电子邮件地址不符合规则',
                u'抱歉这个电子邮件地址已经有人注册过了']
            if 'email' in request.POST:
                member_email = request.POST['email'].strip()
            else:
                member_email = ''
            if (len(member_email) == 0):
                errors = errors + 1
                member_email_error = 1
            else:
                if (len(member_email) > 32):
                    errors = errors + 1
                    member_email_error = 2
                else:
                    p = re.compile(r"(?:^|\s)[-a-z0-9_.]+@(?:[-a-z0-9]+\.)+[a-z]{2,6}(?:\s|$)", re.IGNORECASE)
                    if (p.search(member_email)):
                        q = User.objects.filter(email=member_email.lower()).exclude(id=request.user.id)
                        if (len(q) > 0):
                            errors = errors + 1
                            member_email_error = 4
                    else:
                        errors = errors + 1
                        member_email_error = 3
            template_values['member_email'] = member_email
            template_values['member_email_error'] = member_email_error
            template_values['member_email_error_message'] = member_email_error_messages[member_email_error]
            # Verification: website
            member_website_error = 0
            member_website_error_messages = ['',
                u'个人网站地址长度不能超过 200 个字符',
                u'这个网站地址不符合规则'
            ]
            member_website = request.POST['website'].strip()
            if (len(member_website) == 0):
                member_website = ''
            else:
                if (len(member_website) > 200):
                    errors = errors + 1
                    member_website_error = 1
                else:
                    p = re.compile('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
                    if (p.search(member_website)):
                        errors = errors
                    else:
                        errors = errors + 1
                        member_website_error = 2
            template_values['member_website'] = member_website
            template_values['member_website_error'] = member_website_error
            template_values['member_website_error_message'] = member_website_error_messages[member_website_error]
            # Verification: Twitter
            member_twitter_error = 0
            member_twitter_error_messages = ['',
                u'Twitter 用户名长度不能超过 20 个字符',
                u'Twitter 用户名不符合规则'
            ]
            member_twitter = request.POST['twitter'].strip()
            if (len(member_twitter) == 0):
                member_twitter = ''
            else:
                if (len(member_twitter) > 20):
                    errors = errors + 1
                    member_twitter_error = 1
                else:
                    p = re.compile('[a-zA-Z0-9\_]+')
                    if (p.search(member_twitter)):
                        errors = errors
                    else:
                        errors = errors + 1
                        member_twitter_error = 2
            template_values['member_twitter'] = member_twitter
            template_values['member_twitter_error'] = member_twitter_error
            template_values['member_twitter_error_message'] = member_twitter_error_messages[member_twitter_error]
            # Verification: psn
            member_psn_error = 0
            member_psn_error_messages = ['',
                u'PSN ID 长度不能超过 20 个字符',
                u'PSN ID 不符合规则'
            ]
            member_psn = request.POST['psn'].strip()
            if (len(member_psn) == 0):
                member_psn = ''
            else:
                if (len(member_psn) > 20):
                    errors = errors + 1
                    member_psn_error = 1
                else:
                    p = re.compile('^[a-zA-Z0-9\-\_]+$')
                    if (p.search(member_psn)):
                        errors = errors
                    else:
                        errors = errors + 1
                        member_psn_error = 2
            template_values['member_psn'] = member_psn
            template_values['member_psn_error'] = member_psn_error
            template_values['member_psn_error_message'] = member_psn_error_messages[member_psn_error]
            # Verification: my_home
            member_my_home_error = 0
            member_my_home_error_messages = ['',
                u'不是一个合法的自定义首页跳转位置',
                u'自定义首页跳转位置长度不能超过 32 个字符',
                u'自定义首页跳转位置必须以 / 开头'
            ]
            member_my_home = request.POST['my_home'].strip()
            if len(member_my_home) > 0:
                if member_my_home == '/' or member_my_home.startswith('/signout'):
                    member_my_home_error = 1
                    errors = errors + 1
                else:
                    if len(member_my_home) > 32:
                        member_my_home_error = 2
                        errors = errors + 1
                    else:
                        if member_my_home.startswith('/') is not True:
                            member_my_home_error = 3
                            errors = errors + 1
            template_values['member_my_home'] = member_my_home
            template_values['member_my_home_error'] = member_my_home_error
            template_values['member_my_home_error_message'] = member_my_home_error_messages[member_my_home_error]
            # Verification: btc
            member_btc_error = 0
            member_btc_error_messages = ['',
                u'BTC 收款地址长度不能超过 40 个字符',
                u'BTC 收款地址不符合规则'
            ]
            member_btc = request.POST['btc'].strip()
            if (len(member_btc) == 0):
                member_btc = ''
            else:
                if (len(member_btc) > 40):
                    errors = errors + 1
                    member_btc_error = 1
                else:
                    p = re.compile('^[a-zA-Z0-9]+$')
                    if (p.search(member_btc)):
                        errors = errors
                    else:
                        errors = errors + 1
                        member_btc_error = 2
            template_values['member_btc'] = member_btc
            template_values['member_btc_error'] = member_btc_error
            template_values['member_btc_error_message'] = member_btc_error_messages[member_btc_error]
            # Verification: location
            member_location_error = 0
            member_location_error_messages = ['',
                u'所在地长度不能超过 40 个字符'
            ]
            member_location = request.POST['location'].strip()
            if (len(member_location) == 0):
                member_location = ''
            else:
                if (len(member_location) > 40):
                    errors = errors + 1
                    member_location_error = 1
            template_values['member_location'] = member_location
            template_values['member_location_error'] = member_location_error
            template_values['member_location_error_message'] = member_location_error_messages[member_location_error]
            # Verification: tagline
            member_tagline_error = 0
            member_tagline_error_messages = ['',
                u'个人签名长度不能超过 70 个字符'
            ]
            member_tagline = request.POST['tagline'].strip()
            if (len(member_tagline) == 0):
                member_tagline = ''
            else:
                if (len(member_tagline) > 70):
                    errors = errors + 1
                    member_tagline_error = 1
            template_values['member_tagline'] = member_tagline
            template_values['member_tagline_error'] = member_tagline_error
            template_values['member_tagline_error_message'] = member_tagline_error_messages[member_tagline_error]
            # Verification: bio
            member_bio_error = 0
            member_bio_error_messages = ['',
                u'个人简介长度不能超过 2000 个字符'
            ]
            member_bio = request.POST['bio'].strip()
            if (len(member_bio) == 0):
                member_bio = ''
            else:
                if (len(member_bio) > 2000):
                    errors = errors + 1
                    member_bio_error = 1
            template_values['member_bio'] = member_bio
            template_values['member_bio_error'] = member_bio_error
            template_values['member_bio_error_message'] = member_bio_error_messages[member_bio_error]
            # Verification: show_home_top and show_quick_post
            try:
                member_show_home_top = int(request.POST['show_home_top'])
            except:
                member_show_home_top = 1
            template_values['member_show_home_top'] = member_show_home_top
            try:
                member_show_quick_post = int(request.POST['show_quick_post'])
            except:
                member_show_quick_post = 0
            template_values['member_show_quick_post'] = member_show_quick_post
            if member_show_home_top not in [0, 1]:
                member_show_home_top = 1
            if member_show_quick_post not in [0, 1]:
                member_show_quick_post = 0
            # Verification: l10n
            member_l10n = request.POST['l10n'].strip()
            supported = GetSupportedLanguages()
            if member_l10n == '':
                member_l10n = site.l10n
            else:
                if member_l10n not in supported:
                    member_l10n = site.l10n
            s = GetLanguageSelect(member_l10n)
            template_values['s'] = s
            template_values['member_l10n'] = member_l10n
            # Verification: twitter_sync
            if member.twitter_oauth == 1:
                if 'twitter_sync' in request.POST:
                    member_twitter_sync = request.POST['twitter_sync']
                else:
                    member_twitter_sync = ''
                if member_twitter_sync == 'on':
                    member_twitter_sync = 1
                else:
                    member_twitter_sync = 0
                template_values['member_twitter_sync'] = member_twitter_sync
            # Verification: use_my_css
            member_use_my_css = None
            if 'use_my_css' in request.POST:
                member_use_my_css = request.POST['use_my_css']
            else:
                member_use_my_css = ''
            if member_use_my_css == 'on':
                member_use_my_css = 1
            else:
                member_use_my_css = 0
            template_values['member_use_my_css'] = member_use_my_css
            # Verification: my_css
            member_my_css_error = 0
            member_my_css_error_messages = ['',
                u'CSS Hack cannot be longer than 2000 characters'
            ]
            member_my_css = request.POST['my_css'].strip()
            if (len(member_my_css) == 0):
                member_my_css = ''
            else:
                if (len(member_my_css) > 2000):
                    errors = errors + 1
                    member_my_css_error = 1
            template_values['member_my_css'] = member_my_css
            template_values['member_my_css_error'] = member_my_css_error
            template_values['member_my_css_error_message'] = member_my_css_error_messages[member_my_css_error]
            template_values['errors'] = errors
            if (errors == 0):
                user = request.user
                member.truename = member_realname
                member.sex = member_sex
                # 如果用户更改了账户,则editable置为0
                if user.username != member_username:
                    user.username = member_username
                    member.username_editable = 0
                    member.username_lower = member_username.lower()
                user.email = member_email.lower()
                member.website = member_website
                member.twitter = member_twitter
                member.psn = member_psn
                member.btc = member_btc
                member.location = member_location
                member.tagline = member_tagline
                if member.twitter_oauth == 1:
                    member.twitter_sync = member_twitter_sync
                member.use_my_css = member_use_my_css
                member.my_css = member_my_css
                if member_my_home_error == 0 and len(member_my_home) > 0:
                    member.my_home = member_my_home
                else:
                    if member_my_home_error == 0:
                        member.my_home = ''
                member.bio = member_bio
                member.show_home_top = member_show_home_top
                member.show_quick_post = member_show_quick_post
                member.l10n = member_l10n
                user.save()
                member.save()
                memcache.delete('Member::' + str(member.user.username))
                memcache.delete('Member::' + str(member.username_lower))
                memcache.set('Member_' + str(member.num), member, 86400)
                session['message'] = '个人设置成功更新'
                return HttpResponseRedirect('/settings')
            else:
                if browser['ios']:
                    path = os.path.join('mobile', 'member_settings.html')
                else:
                    path = os.path.join('desktop', 'member_settings.html')
            return render_to_response(path, template_values)
        else:
            return HttpResponseRedirect('/signin')