Ejemplo n.º 1
0
def create_users(account_ids):
    user_ids = {}
    for account_id in account_ids:
        res = requests.get('http://www.sofienetwork.com/account/%i/users' % account_id,\
                           headers={'Accept': 'application/json',\
                                    'Authorization': authorization})
        users = res.json()

        for user in users:
            try:
                spn_id = user['UserID']
                del user['RoleType']
                del user['UserID']
                usr = User(**user)
                usr.password = '******'
                usr.AccountID = account_ids[account_id]
                res = requests.get('http://www.sofienetwork.com/user/%i/avatar' % spn_id, headers={'Authorization': authorization})
                usr._avatar = res.content
                usr.save()
                print 'Creating User %s' % usr.UserID
                user_ids[spn_id] = usr.UserID
            except Exception as e:
                print str(e)
                print 'user insertion error'
                db.session.rollback()
    return user_ids
Ejemplo n.º 2
0
def new():
    redirect_url = request.args[
        "redirect_url"] if "redirect_url" in request.args else None
    redirect_url = "" if redirect_url == "/user/login" or redirect_url == "/user/logout" or redirect_url == "/user/new" else redirect_url
    user = User()
    if "account_id" in request.args:
        user.AccountID = int(request.args['account_id'])

    if not user.can_save(g.user.to_hash()):
        return Response(
            "You do not have the appropriate role type to update this record",
            403)
    return render_template("user/edit.html",
                           redirect_url=redirect_url,
                           user=json.dumps(user.to_hash()),
                           runninguser=json.dumps(g.user.to_hash()))