give_auth.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from .tool.func import *
  2. def give_auth(name):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. ip = ip_check()
  6. owner_auth = admin_check()
  7. admin_auth = admin_check(7)
  8. curs.execute(db_change("select data from user_set where id = ? and name = 'acl'"), [name])
  9. user_acl = curs.fetchall()
  10. if not user_acl:
  11. return re_error('/error/2')
  12. else:
  13. user_acl = user_acl[0][0]
  14. if owner_auth != 1:
  15. curs.execute(db_change('select name from alist where name = ? and acl = "owner"'), [user_acl])
  16. if curs.fetchall():
  17. return re_error('/error/3')
  18. if ip == name:
  19. return re_error('/error/3')
  20. if flask.request.method == 'POST':
  21. if admin_check(7, 'admin (' + name + ')') != 1:
  22. return re_error('/error/3')
  23. select_data = flask.request.form.get('select', 'X')
  24. if select_data == 'X':
  25. select_data = 'user'
  26. curs.execute(db_change('select name from alist where name = ? and acl = "owner"'), [select_data])
  27. if owner_auth != 1 and curs.fetchall():
  28. return re_error('/error/3')
  29. curs.execute(db_change("update user_set set data = ? where id = ? and name = 'acl'"), [select_data, name])
  30. curs.execute(db_change('delete from user_set where name = "auth_date" and id = ?'), [name])
  31. time_limit = flask.request.form.get('date', '')
  32. if re.search(r'^[0-9]{4}-[0-9]{2}-[0-9]{2}$', time_limit):
  33. curs.execute(db_change("insert into user_set (id, name, data) values (?, 'auth_date', ?)"), [name, time_limit])
  34. else:
  35. time_limit = ''
  36. add_alarm(name, ip, 'Auth change to ' + select_data + (' (' + time_limit + ')' if time_limit != '' else ''))
  37. conn.commit()
  38. return redirect('/auth/give/' + url_pas(name))
  39. else:
  40. if admin_auth != 1:
  41. return re_error('/error/3')
  42. div = '<option value="X">' + load_lang('normal') + '</option>'
  43. div += '<option value="ban">' + load_lang('ban') + '</option>'
  44. curs.execute(db_change('select distinct name from alist order by name asc'))
  45. for data in curs.fetchall():
  46. if user_acl == data[0]:
  47. div = '<option value="' + data[0] + '">' + data[0] + '</option>' + div
  48. else:
  49. div += '<option value="' + data[0] + '">' + data[0] + '</option>'
  50. date_value = ''
  51. curs.execute(db_change('select data from user_set where name = "auth_date" and id = ?'), [name])
  52. db_data = curs.fetchall()
  53. if db_data:
  54. date_value = db_data[0][0]
  55. return easy_minify(flask.render_template(skin_check(),
  56. imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('authorize') + ')', 0])],
  57. data = '''
  58. <form method="post">
  59. <div id="opennamu_get_user_info">''' + html.escape(name) + '''</div>
  60. <hr class="main_hr">
  61. <select name="select">''' + div + '''</select>
  62. <hr class="main_hr">
  63. <input type="date" value="''' + date_value + '''" name="date" pattern="\\d{4}-\\d{2}-\\d{2}">
  64. <hr class="main_hr">
  65. <button type="submit">''' + load_lang('save') + '''</button>
  66. </form>
  67. ''',
  68. menu = [['manager', load_lang('return')]]
  69. ))