def settings(): conf = data.get_conf() if 'user' not in conf: info = requests.post(sync.root + "/sign_up", { "name": platform.node() }).json() conf['user'] = info['user'] conf['secret'] = info['secret'] conf['friends'] = conf.get('friends', []) conf['dir'] = data.default_dir if not os.path.exists(conf['dir']): os.mkdir(conf['dir']) conf['email'] = "" data.save_conf(conf) if flask.request.method == 'GET': args = copy.copy(conf) args['msg'] = flask.request.args.get('msg', None) return templ8("ui.html", args) elif flask.request.method == 'POST': conf['dir'] = flask.request.form.get('dir') conf['email'] = flask.request.form.get('email') sync.postjson('/set_email', { "user": conf['user'], "secret": conf['secret'], "email": conf['email'] }) data.save_conf(conf) return flask.redirect('/ui?msg=Saved') return "Saved!"
def restore(user, secret): conf = data.get_conf() conf['user'] = user conf['secret'] = secret conf['friends'] = [] postjson('/restore', {"user": conf['user'], "secret": conf['secret']}) data.save_conf(conf) return flask.redirect('/ui?msg=Now%20pick%20a%20folder%20and%20wait%20for%20your%20files:')
def settings(): conf = data.get_conf() if 'user' not in conf: info = requests.post(sync.root+"/sign_up").json() conf['user'] = info['user'] conf['secret'] = info['secret'] data.save_conf(conf) if flask.request.method=='GET': return templ8("settings.html", conf) elif flask.request.method=='POST': friends = flask.request.form.get('friends').split('\n') friends = [f for f in friends if len(f)>0] conf['friends'] = friends dir = flask.request.form.get('dir') conf['dir'] = dir data.save_conf(conf) return "Saved!"
def add(id): conf = data.get_conf() conf['friends'] = list(set(conf.get('friends', []) + [id])) data.save_conf(conf) return flask.redirect('/ui?msg=Added.')