Răsfoiți Sursa

mod some func

2du 4 ani în urmă
părinte
comite
069c8c154b

+ 8 - 16
app.py

@@ -368,10 +368,6 @@ def list_please():
 def list_title_index():
     return list_title_index_2(conn)
 
-@app.route('/topic_record/<name>')
-def list_user_topic(name = 'test'):
-    return list_user_topic_2(conn, name)
-
 @app.route('/<regex("long_page"):tool>')
 @app.route('/<regex("short_page"):tool>')
 def list_long_page(tool = 'long_page'):
@@ -484,6 +480,14 @@ def recent_history_add(name = 'Test'):
 def recent_record_reset(name = 'Test'):
     return recent_record_reset_2(conn, name)
 
+@app.route('/record/topic/<name>')
+def recent_record_topic(name = 'Test'):
+    return recent_record_topic_2(conn, name)
+
+@app.route('/app_submit', methods = ['POST', 'GET'])
+def recent_app_submit():
+    return recent_app_submit_2(conn)
+
 # Func-search
 @app.route('/search', methods=['POST'])
 def search():
@@ -649,11 +653,9 @@ def login_register_email():
 def login_register_email_check():
     return login_register_email_check_2(conn)
 
-'''
 @app.route('/register/submit', methods = ['POST', 'GET'])
 def login_register_submit():
     return login_register_submit_2(conn)
-'''
 
 # 이 파트와 통일 예정
 @app.route('/<regex("need_email"):tool>', methods = ['POST', 'GET'])
@@ -670,16 +672,6 @@ def login_check_key(tool = 'check_pass_key'):
 def login_logout():
     return login_logout_2(conn)
 
-# Func-application
-# 이 파트는 register과 list로 쪼갤 예정
-@app.route('/application_submitted')
-def application_submitted():
-    return application_submitted_2(conn)
-
-@app.route('/applications', methods = ['POST', 'GET'])
-def applications():
-    return applications_2(conn)
-
 # Func-vote
 @app.route('/vote/<num>', methods = ['POST', 'GET'])
 def vote_select(num = '1'):

+ 0 - 10
route/application_submitted.py

@@ -1,10 +0,0 @@
-from .tool.func import *
-
-def application_submitted_2(conn):
-    curs = conn.cursor()
-
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('application_submitted'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-        data = '<p>' + load_lang('waiting_for_approval') + '</p>',
-        menu = [['user', load_lang('return')]]
-    ))

+ 0 - 1
route/login_register.py

@@ -95,7 +95,6 @@ def login_register_2(conn):
                     <input placeholder="''' + load_lang('password_confirm') + '''" name="pw2" type="password">
                     <hr class="main_hr">
                     
-                    ''' + approval_question + '''
                     ''' + captcha_get() + '''
                     
                     <!--

+ 1 - 1
route/login_register_email.py

@@ -29,7 +29,7 @@ def login_register_email_2(conn):
 
         curs.execute(db_change('select data from other where name = "email_text"'))
         sql_d = curs.fetchall()
-        if sql_d and sql_d[0][0] != ''
+        if sql_d and sql_d[0][0] != '':
             i_text = html.escape(sql_d[0][0]) + '\n\nKey : ' + flask.session['c_key']
         else:
             i_text = 'Key : ' + flask.session['c_key']

+ 0 - 2
route/login_register_email_check.py

@@ -7,8 +7,6 @@ def login_register_email_check_2(conn):
         return redirect('/register')
     
     if  flask.request.method == 'POST':
-        user_ip = ip_check()
-        user_agent = flask.request.headers.get('User-Agent', '')
         input_key = flask.request.form.get('key', '')
 
         if flask.session['reg_key'] != input_key:

+ 57 - 33
route/login_register_submit.py

@@ -1,37 +1,61 @@
 from .tool.func import *
 
-def login_register_submit_2(conn):
-    approval_question = ''
-
-    curs.execute(db_change('select data from other where name = "requires_approval"'))
-    requires_approval = curs.fetchall()
-    requires_approval = requires_approval and requires_approval[0][0] == 'on'
-    requires_approval = None if admin == 1 else requires_approval
-    if requires_approval:
-        curs.execute(db_change('select data from other where name = "approval_question"'))
-        data = curs.fetchall()
-        if data and data[0][0] != '':
-            approval_question = '''
-                <hr class="main_hr">
-                <span>''' + load_lang('approval_question') + ' : ' + data[0][0] + '''<span>
-                <hr class="main_hr">
-                <input placeholder="''' + load_lang('approval_question') + '''" name="approval_question_answer" type="text">
-                <hr class="main_hr">
-            '''
-
-    ans_q = flask.request.form.get('approval_question_answer', '')
+from .tool.func import *
 
-    curs.execute(db_change('select data from other where name = "requires_approval"'))
-    requires_approval = curs.fetchall()
-    requires_approval = requires_approval and requires_approval[0][0] == 'on'
-    requires_approval = None if admin == 1 else requires_approval
-    if requires_approval:
-        curs.execute(db_change('select data from other where name = "approval_question"'))
-        approval_question = curs.fetchall()
-        approval_question = approval_question[0][0] if approval_question and approval_question[0][0] else ''
+def login_register_submit_2(conn):
+    curs = conn.cursor()
+    
+    if not 'submit_id' in flask.session:
+        return redirect('/register')
+    
+    curs.execute(db_change('select data from other where name = "approval_question"'))
+    sql_data = curs.fetchall()
+    if not sql_data:
+        return redirect('/register')
+    
+    data_que = sql_data[0][0]
+    
+    if flask.request.method == 'POST':
+        curs.execute(db_change('select data from other where name = "encode"'))
+        data_encode = curs.fetchall()
+        data_encode = data_encode[0][0]
+        
+        user_ip = ip_check()
+        user_agent = flask.request.headers.get('User-Agent', '')
+        
+        user_app_data = {}
+        user_app_data['id'] = flask.session['submit_id']
+        user_app_data['pw'] = pw_encode(flask.session['submit_pw'])
+        user_app_data['encode'] = data_encode
+        user_app_data['question'] = data_que
+        user_app_data['answer'] = flask.request.form.get('answer', '')
+        
+        if 'submit_email' in flask.session:
+            user_app_data['email'] = flask.session['submit_email']
+        else:
+            user_app_data['email'] = ''
+            
+        curs.execute(db_change(
+            "insert into user_set (id, name, data) values (?, ?, ?)"
+        ), [
+            flask.session['submit_id'],
+            'application',
+            json.dumps(user_app_data)
+        ])
+        conn.commit()
+        
+        return redirect('/app_submit')
     else:
-        approval_question = ''
-
-            if requires_approval:
-                flask.session['c_ans'] = flask.request.form.get('approval_question_answer', '')
-                flask.session['c_que'] = approval_question
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('approval_question'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+            data = '''
+                <form method="post">
+                    ''' + load_lang('approval_question') + ' : ' + data_que + '''
+                    <hr class="main_hr">
+                    <input placeholder="''' + load_lang('approval_question') + '''" name="answer">
+                    <hr class="main_hr">
+                    <button type="submit">''' + load_lang('save') + '''</button>
+                </form>
+            ''',
+            menu = [['user', load_lang('return')]]
+        ))

+ 2 - 2
route/main_manager.py

@@ -9,7 +9,7 @@ def main_manager_2(conn, num, r_ver):
         2 : [load_lang('file_name'), 'plus_file_filter', load_lang('file_filter_add')],
         3 : [0, 'admin', load_lang('authorize')],
         4 : [0, 'record', load_lang('edit_record')],
-        5 : [0, 'topic_record', load_lang('discussion_record')],
+        5 : [0, 'record/topic', load_lang('discussion_record')],
         6 : [load_lang('name'), 'admin_plus', load_lang('add_admin_group')],
         7 : [load_lang('name'), 'plus_edit_filter', load_lang('edit_filter_add')],
         8 : [load_lang('document_name'), 'search', load_lang('search')],
@@ -39,7 +39,7 @@ def main_manager_2(conn, num, r_ver):
                 <ul class="inside_ul">
                     <li><a href="/admin_group">''' + load_lang('admin_group_list') + '''</a></li>
                     <li><a href="/many_delete">''' + load_lang('many_delete') + '''</a></li>
-                    <li><a href="/applications">''' + load_lang('application_list') + '''</a></li>
+                    <li><a href="/app_submit">''' + load_lang('application_list') + '''</a></li>
                     <li><a href="/api/sitemap.xml">''' + load_lang('get_sitemap') + '''</a></li>
                     <li><a href="/register">''' + load_lang('add_user') + '''</a></li>
                     <li><a href="/setting">''' + load_lang('setting') + '''</a></li>

+ 16 - 50
route/applications.py → route/recent_app_submit.py

@@ -1,13 +1,10 @@
 from .tool.func import *
 
-def applications_2(conn):
+def recent_app_submit_2(conn):
     curs = conn.cursor()
 
     div = ''
 
-    if admin_check() != 1:
-        return re_error('/ban')
-
     curs.execute(db_change('select data from other where name = "requires_approval"'))
     requires_approval = curs.fetchall()
     if requires_approval and requires_approval[0][0] != 'on':
@@ -27,13 +24,12 @@ def applications_2(conn):
             div += '''
                 <table id="main_table_set">
                     <tr id="main_table_top_tr">
-                        <td id="main_table_width">''' + load_lang('id') + '''</td>
-                        <td id="main_table_width">''' + load_lang('email') + '''</td>
-                        <td id="main_table_width">''' + load_lang('application_time') + '''</td>
+                        <td id="main_table_width_half">''' + load_lang('id') + '''</td>
+                        <td id="main_table_width_half">''' + load_lang('email') + '''</td>
                     </tr>
                     <tr id="main_table_top_tr">
                         <td>''' + load_lang('approval_question') + '''</td>
-                        <td colspan="2">''' + load_lang('answer') + '''</td>
+                        <td>''' + load_lang('answer') + '''</td>
                     </tr>                        
             '''
 
@@ -64,11 +60,10 @@ def applications_2(conn):
                         <tr>
                             <td>''' + application['id'] + '''</td>
                             <td>''' + email + '''</td>
-                            <td>''' + application['date'] + '''</td>
                         </tr>
                         <tr>
                             <td>''' + question + '''</td>
-                            <td colspan="2">''' + answer + '''</td>
+                            <td>''' + answer + '''</td>
                         </tr>
                         <tr>
                             <td colspan="3">
@@ -98,6 +93,9 @@ def applications_2(conn):
             menu = [['other', load_lang('return')]]
         ))
     else:
+        if admin_check(None, 'app submit') != 1:
+            return re_error('/ban')
+        
         if flask.request.form.get('approve', '') != '':
             curs.execute(db_change(
                 'select data from user_set where id = ? and name = "application"'
@@ -110,29 +108,13 @@ def applications_2(conn):
             else:
                 application = json.loads(application[0][0])
             
-            curs.execute(db_change(
-                "insert into user_set (id, name, data) values (?, 'pw', ?)"
-            ), [
-                application['id'],
-                application['pw']
-            ])
-            curs.execute(db_change(
-                "insert into user_set (id, name, data) values (?, 'acl', 'user')"
-            ), [
-                application['id']
-            ])
-            curs.execute(db_change(
-                "insert into user_set (id, name, data) values (?, 'date', ?)"
-            ), [
-                application['id'],
-                application['date']
-            ])
-            curs.execute(db_change(
-                "insert into user_set (id, name, data) values (?, 'encode', ?)"
-            ), [
-                application['id'],
+            add_user(
+                application['id'], 
+                application['pw'],
+                application['email'],
                 application['encode']
-            ])
+            )
+
             curs.execute(db_change(
                 "insert into user_set (name, id, data) values ('approval_question', ?, ?)"
             ), [
@@ -140,28 +122,12 @@ def applications_2(conn):
                 application['question']
             ])
             curs.execute(db_change(
-                "insert into user_set (name, id, data) " + \
-                "values ('approval_question_answer', ?, ?)"
+                "insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"
             ), [
                 application['id'], 
                 application['answer']
             ])
             
-            ua_plus(
-                application['id'], 
-                application['ip'], 
-                application['ua'], 
-                application['date']
-            )
-            
-            if application['email'] != '':
-                curs.execute(db_change(
-                    "insert into user_set (name, id, data) values ('email', ?, ?)"
-                ), [
-                    application['id'], 
-                    application['email']
-                ])
-            
             curs.execute(db_change(
                 'delete from user_set where id = ? and name = "application"'
             ), [
@@ -176,4 +142,4 @@ def applications_2(conn):
             ])
             conn.commit()
 
-        return redirect('/applications')
+        return redirect('/app_submit')

+ 1 - 4
route/recent_change.py

@@ -60,8 +60,6 @@ def recent_change_2(conn, name, tool):
                     <td id="main_table_width">''' + load_lang('time') + '''</td>
                 '''
 
-                div = '<a href="/topic_record/' + url_pas(name) + '">(' + load_lang('discussion') + ')</a><hr class=\"main_hr\">' + div
-
                 curs.execute(db_change('' + \
                     'select id, title, date, ip, send, leng, hide from history ' + \
                     "where ip = ? order by date desc limit ?, 50" + \
@@ -178,8 +176,7 @@ def recent_change_2(conn, name, tool):
                 title = load_lang('edit_record')
                 menu = [
                     ['other', load_lang('other')], 
-                    ['user', load_lang('user')], 
-                    ['count/' + url_pas(name), load_lang('count')],
+                    ['user', load_lang('user')],
                     ['record/reset/' + url_pas(name), load_lang('record_reset')]
                 ]
                 div += next_fix('/record/' + url_pas(name) + '?num=', num, data_list)

+ 10 - 19
route/list_user_topic.py → route/recent_record_topic.py

@@ -1,22 +1,18 @@
 from .tool.func import *
 
-def list_user_topic_2(conn, name):
+def recent_record_topic_2(conn, name):
     curs = conn.cursor()
 
     num = int(number_check(flask.request.args.get('num', '1')))
-    if num * 50 > 0:
-        sql_num = num * 50 - 50
-    else:
-        sql_num = 0
+    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
     div = '''
         <table id="main_table_set">
-            <tbody>
-                <tr>
-                    <td id="main_table_width">''' + load_lang('discussion_name') + '''</td>
-                    <td id="main_table_width">''' + load_lang('writer') + '''</td>
-                    <td id="main_table_width">''' + load_lang('time') + '''</td>
-                </tr>
+            <tr id="main_table_top_tr">
+                <td id="main_table_width">''' + load_lang('discussion_name') + '''</td>
+                <td id="main_table_width">''' + load_lang('writer') + '''</td>
+                <td id="main_table_width">''' + load_lang('time') + '''</td>
+            </tr>
     '''
     sub = '(' + html.escape(name) + ')'
     pas_name = ip_pas(name)
@@ -39,19 +35,14 @@ def list_user_topic_2(conn, name):
             '</tr>' + \
         ''
 
-    div += '' + \
-            '</tbody>' + \
-        '</table>' + \
-    ''
-    div += next_fix('/topic_record/' + url_pas(name) + '?num=', num, data_list)
+    div += '</table>'
+    div += next_fix('/record/topic/' + url_pas(name) + '?num=', num, data_list)
     
     return easy_minify(flask.render_template(skin_check(),
         imp = [load_lang('discussion_record'), wiki_set(), wiki_custom(), wiki_css([sub, 0])],
         data = div,
         menu = [
             ['other', load_lang('other')], 
-            ['user', load_lang('user')], 
-            ['count/' + url_pas(name), load_lang('count')], 
-            ['record/' + url_pas(name), load_lang('record')]
+            ['user', load_lang('user')]
         ]
     ))

+ 10 - 14
route/tool/func.py

@@ -1406,18 +1406,16 @@ def add_alarm(who, context):
         'insert into alarm (name, data, date) values (?, ?, ?)'
     ), [who, context, get_time()])
     
-def add_user(user_name, user_pw, user_email = ''):
-    curs.execute(db_change("select id from user_set where id = ? limit 1"), [
-        user_name
-    ])
-    if curs.fetchall():
-        return 0
-    
-    user_pw_hash = pw_encode(user_pw)
-    
-    curs.execute(db_change('select data from other where name = "encode"'))
-    data_encode = curs.fetchall()
-    data_encode = data_encode[0][0]
+def add_user(user_name, user_pw, user_email = '', user_encode = ''):    
+    if user_encode == '':
+        user_pw_hash = pw_encode(user_pw)
+
+        curs.execute(db_change('select data from other where name = "encode"'))
+        data_encode = curs.fetchall()
+        data_encode = data_encode[0][0]
+    else:
+        user_pw_hash = user_pw
+        data_encode = user_encode
 
     curs.execute(db_change("select id from user_set limit 1"))
     if not curs.fetchall():
@@ -1449,8 +1447,6 @@ def add_user(user_name, user_pw, user_email = ''):
         ])
         
     conn.commit()
-        
-    return 1
     
 def ua_plus(u_id, u_ip, u_agent, time):
     curs.execute(db_change("select data from other where name = 'ua_get'"))

+ 1 - 1
route/user_count_edit.py

@@ -27,7 +27,7 @@ def user_count_edit_2(conn, name):
         data = '''
             <ul class="inside_ul">
                 <li><a href="/record/''' + url_pas(that) + '''">''' + load_lang('edit_record') + '''</a> : ''' + str(data) + '''</li>
-                <li><a href="/topic_record/''' + url_pas(that) + '''">''' + load_lang('discussion_record') + '''</a> : ''' + str(t_data) + '''</a></li>
+                <li><a href="/record/topic/''' + url_pas(that) + '''">''' + load_lang('discussion_record') + '''</a> : ''' + str(t_data) + '''</a></li>
             </ul>
         ''',
         menu = [['user', load_lang('return')]]

+ 1 - 0
route/user_tool.py

@@ -7,6 +7,7 @@ def user_tool_2(conn, name):
         <h2>''' + load_lang('tool') + '''</h2>
         <ul class="inside_ul">
             <li><a href="/record/''' + url_pas(name) + '''">''' + load_lang('record') + '''</a></li>
+            <li><a href="/record/topic/''' + url_pas(name) + '''">''' + load_lang('discussion_record') + '''</a></li>
             <li><a href="/topic/user:''' + url_pas(name) + '''">''' + load_lang('user_discussion') + '''</a></li>
         </ul>
     '''