give_user_fix.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from .tool.func import *
  2. def give_user_fix(user_name = ''):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. curs.execute(db_change("select data from user_set where id = ? and name = 'pw'"), [user_name])
  6. if not curs.fetchall():
  7. return re_error('/error/2')
  8. if admin_check() != 1:
  9. return re_error('/error/3')
  10. if flask.request.method == 'POST':
  11. select = flask.request.form.get('select', '')
  12. admin_check(None, 'user_fix (' + user_name + ') (' + select + ')')
  13. if select == 'password_change':
  14. password = flask.request.form.get('new_password', '')
  15. check_password = flask.request.form.get('password_check', '')
  16. if password == check_password:
  17. hashed = pw_encode(password)
  18. curs.execute(db_change("update user_set set data = ? where id = ? and name = 'pw'"), [
  19. hashed,
  20. user_name
  21. ])
  22. else:
  23. return re_error('/error/20')
  24. elif select == '2fa_password_change':
  25. password = flask.request.form.get('new_password', '')
  26. check_password = flask.request.form.get('password_check', '')
  27. if password == check_password:
  28. hashed = pw_encode(password)
  29. curs.execute(db_change('select data from user_set where name = "2fa_pw" and id = ?'), [user_name])
  30. if curs.fetchall():
  31. curs.execute(db_change("update user_set set data = ? where name = '2fa_pw' and id = ?"), [hashed, user_name])
  32. else:
  33. curs.execute(db_change("insert into user_set (name, id, data) values ('2fa_pw', ?, ?)"), [user_name, hashed])
  34. else:
  35. return re_error('/error/20')
  36. elif select == '2fa_off':
  37. curs.execute(db_change('select data from user_set where name = "2fa" and id = ?'), [user_name])
  38. if curs.fetchall():
  39. curs.execute(db_change("update user_set set data = '' where name = '2fa' and id = ?"), [user_name])
  40. conn.commit()
  41. return redirect('/user/' + url_pas(user_name))
  42. else:
  43. return easy_minify(flask.render_template(skin_check(),
  44. imp = [load_lang('user_fix'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  45. data = '''
  46. <form method="post">
  47. <div id="opennamu_get_user_info">''' + html.escape(user_name) + '''</div>
  48. <hr class="main_hr">
  49. <a href="/change/user_name/''' + url_pas(user_name) + '''">(''' + load_lang('change_user_name') + ''')</a>
  50. <hr class="main_hr">
  51. <select name="select">
  52. <option value="password_change">''' + load_lang('password_change') + '''</option>
  53. <option value="2fa_password_change">''' + load_lang('2fa_password_change') + '''</option>
  54. <option value="2fa_off">''' + load_lang('2fa_off') + '''</option>
  55. </select>
  56. <hr class="main_hr">
  57. ''' + load_lang('password_change') + ''' | ''' + load_lang('2fa_password_change') + '''
  58. <hr class="main_hr">
  59. <input placeholder="''' + load_lang('new_password') + '''" name="new_password" type="password">
  60. <hr class="main_hr">
  61. <input placeholder="''' + load_lang('password_confirm') + '''" name="password_check" type="password">
  62. <hr class="main_hr">
  63. <button type="submit">''' + load_lang('go') + '''</button>
  64. </form>
  65. ''',
  66. menu = [['manager', load_lang('return')]]
  67. ))