Exemplo n.º 1
0
def add_pubkey():
    if request.method == 'GET':
        return render_template('/add_pubkey.html')

    title = request.form['title']
    pkey = request.form['pkey']

    pubkey = RSAKey.get_by_user_id(g.user.id)
    if pubkey:
        flash(u'已经存在一枚key了,只能添加一枚哦', 'error')
        return render_template('/add_pubkey.html')

    RSAKey.create(g.user.id, title, pkey)
    return redirect(url_for('ui.pubkeys'))
Exemplo n.º 2
0
def delete_pubkey():
    keyfp = request.form['keyfp']
    pubkey = RSAKey.get_by_fingerprint(keyfp)
    if pubkey:
        pubkey.delete()
    else:
        return jsonify({'message': 'pub key does not exist'}), 200
    return jsonify({'message': 'ok'}), 200
Exemplo n.º 3
0
def delete_user():
    user_id = request.form['user_id']
    user = User.get(user_id)
    if not user:
        return jsonify({'message': 'not found'}), 404

    pubkey = RSAKey.get_by_user_id(user_id)
    if pubkey:
        pubkey.delete()
    user.delete()

    return jsonify({'message': 'ok'}), 200
Exemplo n.º 4
0
def pubkeys():
    pubkey = RSAKey.get_by_user_id(g.user.id)
    return render_template('/pubkeys.html', pubkey=pubkey)
Exemplo n.º 5
0
def refresh_token():
    pubkey = RSAKey.get_by_user_id(g.user.id)
    if pubkey:
        pubkey.delete()
    g.user.refresh_token()
    return jsonify({'message': g.user.token}), 200