def save_config(): if not check_csrf(request, 'json'): abort(403) dictionary = {} user_name = utils.secure_filename(request.json['user_name']) user_password = request.json['user_password'] config = configparser.ConfigParser() config.read(conf) config['setup']['initial_setup'] = 'false' config['auth']['method'] = request.json['mode'] config['ldap']['server'] = request.json['ldap_address'] config['ldap']['port'] = request.json['ldap_port'] config['ldap']['base_dn'] = request.json['ldap_basedn'] config['redpen']['java_home'] = request.json['java_home'] config['redpen']['conf'] = request.json['redpen_conf_path'] f = open(conf, 'w') config.write(f) f.close() con = sqlite3.connect(db) cur = con.cursor() sql = 'UPDATE user SET username=(?), password=(?) WHERE username="******"' cur.execute(sql, (user_name, generate(user_password),)) con.commit() cur.close() con.close() session.pop('username', None) session.pop('cwd', None) dictionary['result'] = 'Success' return jsonify(ResultSet=json.dumps(dictionary))
def register_user(): if not check_csrf(request, 'json'): abort(403) dictionary = {} username = request.json['username'] password = request.json['password'] con = sqlite3.connect(db) cur = con.cursor() sql = 'SELECT username FROM user WHERE username=(?)' cur.execute(sql, (username, )) fetched = cur.fetchone() if fetched is not None: dictionary['result'] = 'Failure' dictionary['cause'] = 'Your specified user is already exists.' return jsonify(ResultSet=json.dumps(dictionary)) sql = 'INSERT INTO user(username, password) VALUES (?, ?)' cur.execute(sql, ( username, generate(password), )) con.commit() cur.close() con.close() dictionary['result'] = 'Success' return jsonify(ResultSet=json.dumps(dictionary))
def register_user(): if not check_csrf(request, 'json'): abort(403) dictionary = {} username = request.json['username'] password = request.json['password'] con = sqlite3.connect(db) cur = con.cursor() sql = 'SELECT username FROM user WHERE username=(?)' cur.execute(sql, (username,)) fetched = cur.fetchone() if fetched is not None: dictionary['result'] = 'Failure' dictionary['cause'] = 'Your specified user is already exists.' return jsonify(ResultSet=json.dumps(dictionary)) sql = 'INSERT INTO user(username, password) VALUES (?, ?)' cur.execute(sql, (username, generate(password),)) con.commit() cur.close() con.close() dictionary['result'] = 'Success' return jsonify(ResultSet=json.dumps(dictionary))
def save_config(): if not check_csrf(request, 'json'): abort(403) dictionary = {} user_name = utils.secure_filename(request.json['user_name']) user_password = request.json['user_password'] config = configparser.ConfigParser() config.read(conf) config['setup']['initial_setup'] = 'false' config['auth']['method'] = request.json['mode'] config['ldap']['server'] = request.json['ldap_address'] config['ldap']['port'] = request.json['ldap_port'] config['ldap']['base_dn'] = request.json['ldap_basedn'] config['redpen']['java_home'] = request.json['java_home'] config['redpen']['conf'] = request.json['redpen_conf_path'] f = open(conf, 'w') config.write(f) f.close() con = sqlite3.connect(db) cur = con.cursor() sql = 'UPDATE user SET username=(?), password=(?) WHERE username="******"' cur.execute(sql, ( user_name, generate(user_password), )) con.commit() cur.close() con.close() session.pop('username', None) session.pop('cwd', None) dictionary['result'] = 'Success' return jsonify(ResultSet=json.dumps(dictionary))