Procházet zdrojové kódy

닉네임 기능 추가

잉여개발기 (SPDV) před 2 roky
rodič
revize
9d4930fdd7

+ 2 - 0
app.py

@@ -456,6 +456,8 @@ app.route('/change/head/<skin_name>', methods=['GET', 'POST'])(user_setting_head
 app.route('/change/head_reset', methods=['GET', 'POST'])(user_setting_head_reset)
 app.route('/change/skin_set')(user_setting_skin_set)
 app.route('/change/top_menu', methods=['GET', 'POST'])(user_setting_top_menu)
+app.route('/change/user_name', methods=['GET', 'POST'])(user_setting_user_name)
+app.route('/change/user_name/<user_name>', methods=['GET', 'POST'])(user_setting_user_name)
 # 하위 호환용 S
 app.route('/skin_set')(user_setting_skin_set)
 # 하위 호환용 E

+ 1 - 1
lang/en-US.json

@@ -552,7 +552,7 @@
             "error_skin_set" : "The skin you are using does not support individual settings.",
             "error_skin_set_old" : "Some older skins may only work by using the old version link.",
             "same_id_exist_error" : "There are users using the same username.",
-            "long_id_error" : "Username must be shorter than 20 characters.",
+            "long_id_error" : "Username must be shorter than 32 characters.",
             "id_char_error" : "Only Korean letters and alphabets are allowed for Username.",
             "file_exist_error" : "The file does not exist.",
             "password_error" : "Password does not match.",

+ 1 - 1
lang/ko-KR.json

@@ -208,7 +208,7 @@
     "name": "이름",
     "period": "기간",
     "writer": "작성자",
-    "long_id_error": "ID는 20자보다 짧아야 합니다.",
+    "long_id_error": "ID는 32자보다 짧아야 합니다.",
     "edit_record_error": "사유는 500자를 넘을 수 없습니다.",
     "revert": "복원",
     "discussion_authority": "토론 관리 권한",

+ 1 - 0
route/__init__.py

@@ -149,6 +149,7 @@ from route.user_setting_pw import user_setting_pw
 from route.user_setting_skin_set import user_setting_skin_set
 from route.user_setting_skin_set_main import user_setting_skin_set_main
 from route.user_setting_top_menu import user_setting_top_menu
+from route.user_setting_user_name import user_setting_user_name
 
 from route.user_watch_list import user_watch_list
 from route.user_watch_list_name import user_watch_list_name

+ 4 - 0
route/give_user_fix.py

@@ -53,6 +53,10 @@ def give_user_fix(user_name = ''):
                 imp = [load_lang('user_fix'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
                 data = '''
                     <form method="post">
+                        <div id="opennamu_get_user_info">''' + html.escape(user_name) + '''</div>
+                        <hr class="main_hr">
+                        <a href="/change/user_name/''' + url_pas(user_name) + '''">(''' + load_lang('change_user_name') + ''')</a>
+                        <hr class="main_hr">
                         <select name="select">
                             <option value="password_change">''' + load_lang('password_change') + '''</option>
                             <option value="2fa_password_change">''' + load_lang('2fa_password_change') + '''</option>

+ 1 - 14
route/login_register.py

@@ -44,22 +44,9 @@ def login_register_2():
                 if password_min_length > len(user_pw):
                     return re_error('/error/40')
 
-            # ID 글자 확인
-            if re.search(r'(?:[^A-Za-zㄱ-힣0-9])', user_id):
+            if do_user_name_check(user_id) == 1:
                 return re_error('/error/8')
 
-            # ID 필터
-            curs.execute(db_change('select html from html_filter where kind = "name"'))
-            set_d = curs.fetchall()
-            for i in set_d:
-                check_r = re.compile(i[0], re.I)
-                if check_r.search(user_id):
-                    return re_error('/error/8')
-
-            # ID 길이 제한 (32글자)
-            if len(user_id) > 32:
-                return re_error('/error/7')
-
             # 중복 확인
             curs.execute(db_change("select id from user_set where id = ?"), [user_id])
             if curs.fetchall():

+ 28 - 3
route/tool/func.py

@@ -1641,6 +1641,28 @@ def captcha_post(re_data, num = 1):
         return 0
 
 # Func-user
+def do_user_name_check(user_name):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
+        # ID 글자 확인
+        if re.search(r'(?:[^A-Za-zㄱ-힣0-9])', user_name):
+            return 1
+
+        # ID 필터
+        curs.execute(db_change('select html from html_filter where kind = "name"'))
+        set_d = curs.fetchall()
+        for i in set_d:
+            check_r = re.compile(i[0], re.I)
+            if check_r.search(user_name):
+                return 1
+
+        # ID 길이 제한 (32글자)
+        if len(user_name) > 32:
+            return 1
+        
+        return 0
+
 def get_admin_auth_list(num = None):
     # without_DB
 
@@ -2144,11 +2166,13 @@ def ip_pas(raw_ip, type_data = 0):
 
                     change_ip = 1
                 else:
-                    ip = raw_ip
+                    curs.execute(db_change('select data from user_set where name = "user_name" and id = ?'), [raw_ip])
+                    db_data = curs.fetchall()
+                    ip = db_data[0][0] if db_data else raw_ip
                 
             if type_data == 0 and change_ip == 0:
                 if is_this_ip == 0:
-                    ip = '<a href="/w/' + url_pas('user:' + raw_ip) + '">' + raw_ip + '</a>'
+                    ip = '<a href="/w/' + url_pas('user:' + raw_ip) + '">' + ip + '</a>'
                     
                     if admin_check('all', None, raw_ip) == 1:
                         ip = '<b>' + ip + '</b>'
@@ -2612,9 +2636,10 @@ def re_error(data):
             elif num == 6:
                 data = load_lang('same_id_exist_error')
             elif num == 7:
+                # 폐지
                 data = load_lang('long_id_error')
             elif num == 8:
-                data = load_lang('id_char_error') + ' <a href="/name_filter">(' + load_lang('id_filter_list') + ')</a>'
+                data = load_lang('long_id_error') + '<br>' + load_lang('id_char_error') + ' <a href="/name_filter">(' + load_lang('id_filter_list') + ')</a>'
             elif num == 9:
                 data = load_lang('file_exist_error')
             elif num == 10:

+ 8 - 0
route/user_setting.py

@@ -95,6 +95,10 @@ def user_setting():
                 fa_data_pw = curs.fetchall()
                 fa_data_pw = load_lang('2fa_password_change') if fa_data_pw else load_lang('2fa_password')
 
+                curs.execute(db_change('select data from user_set where name = "user_name" and id = ?'), [ip])
+                db_data = curs.fetchall()
+                user_name = db_data[0][0] if db_data else ip
+
                 curs.execute(db_change('select data from user_set where name = "sub_user_name" and id = ?'), [ip])
                 db_data = curs.fetchall()
                 sub_user_name = db_data[0][0] if db_data else ''
@@ -130,6 +134,10 @@ def user_setting():
                             <select name="2fa" id="twofa_check_input">''' + fa_data_select + '''</select>
                             <hr class="main_hr">
                             <input type="password" name="2fa_pw" placeholder="''' + fa_data_pw + '''">
+                            <h2>''' + load_lang('main_user_name') + '''</h2>
+                            <a href="/change/user_name">(''' + load_lang('change_user_name') + ''')</a>
+                            <hr class="main_hr">
+                            ''' + load_lang('user_name') + ''' : ''' + html.escape(user_name) + '''
                             <h2>''' + load_lang('sub_user_name') + '''</h2>
                             <input name="sub_user_name" value="''' + html.escape(sub_user_name) + '''" placeholder="''' + load_lang('sub_user_name') + '''">
                             <hr class="main_hr">

+ 1 - 1
route/user_setting_head.py

@@ -73,5 +73,5 @@ def user_setting_head(skin_name = ''):
                         <button id="opennamu_save_button" type="submit">''' + load_lang('save') + '''</button>
                     </form>
                 ''',
-                menu = [['user', load_lang('return')]]
+                menu = [['change', load_lang('return')]]
             ))

+ 54 - 0
route/user_setting_user_name.py

@@ -0,0 +1,54 @@
+from .tool.func import *
+
+def user_setting_user_name(user_name = ''):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
+        ip = ip_check()
+        if user_name != '':
+            if admin_check() != 1:
+                return re_error('/error/3')
+            else:
+                ip = user_name
+    
+        if ip_or_user(ip) == 0:
+            if flask.request.method == 'POST':
+                auto_data = ['user_name', flask.request.form.get('new_user_name', '')]
+                if do_user_name_check(auto_data[1]) == 1:
+                    return re_error('/error/8')
+
+                curs.execute(db_change('select data from user_set where name = ? and data = ?'), [auto_data[0], auto_data[1]])
+                if curs.fetchall():
+                    return re_error('/error/6')
+                else:
+                    curs.execute(db_change('select data from user_set where name = ? and id = ?'), [auto_data[0], ip])
+                    if curs.fetchall():
+                        curs.execute(db_change("update user_set set data = ? where name = ? and id = ?"), [auto_data[1], auto_data[0], ip])
+                    else:
+                        curs.execute(db_change("insert into user_set (name, id, data) values (?, ?, ?)"), [auto_data[0], ip, auto_data[1]])
+
+                    if user_name != '':
+                        return redirect('/change/user_name/' + url_pas(user_name))
+                    else:
+                        return redirect('/change/user_name')
+            else:
+                user_name = ip
+
+                curs.execute(db_change("select data from user_set where id = ? and name = 'user_name'"), [ip])
+                db_data = curs.fetchall()
+                if db_data and db_data[0][0] != '':
+                    user_name = db_data[0][0]
+
+                return easy_minify(flask.render_template(skin_check(),
+                    imp = [load_lang('change_user_name'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                    data = '''
+                        <form method="post">
+                            <input name="new_user_name" placeholder="''' + load_lang('user_name') + '''" value="''' + html.escape(user_name) + '''">
+                            <hr class="main_hr">
+                            <button id="opennamu_save_button" type="submit">''' + load_lang('save') + '''</button>
+                        </form>
+                    ''',
+                    menu = [['change', load_lang('return')]]
+                ))
+        else:
+            return redirect('/login')