Esempio n. 1
0
def create_user_post():
    email = request.form.get('username')
    role = request.form.get('user_role')
    password1 = request.form.get('password1')
    password2 = request.form.get('password2')

    all_roles = get_all_role()

    if email and len(email)< 300 and check_email(email) and role:
        if role in all_roles:
            # password set
            if password1 and password2:
                if password1==password2:
                    if check_password_strength(password1):
                        password = password1
                    else:
                        return render_template("create_user.html", all_roles=all_roles, error="Incorrect Password", admin_level=True)
                else:
                    return render_template("create_user.html", all_roles=all_roles, error="Passwords don't match", admin_level=True)
            # generate password
            else:
                password = gen_password()

            if current_user.is_in_role('admin'):
                # edit user
                if r_serv_db.exists('user_metadata:{}'.format(email)):
                    if password1 and password2:
                        edit_user_db(email, password=password, role=role)
                        return redirect(url_for('settings.users_list', new_user=email, new_user_password=password, new_user_edited=True))
                    else:
                        edit_user_db(email, role=role)
                        return redirect(url_for('settings.users_list', new_user=email, new_user_password='******', new_user_edited=True))
                # create user
                else:
                    create_user_db(email, password, default=True, role=role)
                    return redirect(url_for('settings.users_list', new_user=email, new_user_password=password, new_user_edited=False))

        else:
            return render_template("create_user.html", all_roles=all_roles, admin_level=True)
    else:
        return render_template("create_user.html", all_roles=all_roles, error_mail=True, admin_level=True)
Esempio n. 2
0
config_loader = None

if __name__ == "__main__":

    # create role_list
    if not r_serv.exists('ail:all_role'):
        r_serv.zadd('ail:all_role', 1, 'admin')
        r_serv.zadd('ail:all_role', 2, 'analyst')
        r_serv.zadd('ail:all_role', 3, 'user')
        r_serv.zadd('ail:all_role', 4, 'user_no_api')
        r_serv.zadd('ail:all_role', 5, 'read_only')

    username = '******'
    password = gen_password()
    if r_serv.exists('user_metadata:[email protected]'):
        edit_user_db(username, password=password, role='admin')
    else:
        create_user_db(username, password, role='admin', default=True)
    token = get_default_admin_token()

    default_passwd_file = os.path.join(os.environ['AIL_HOME'],
                                       'DEFAULT_PASSWORD')
    to_write_str = '# Password Generated by default\n# This file is deleted after the first login\n#\[email protected]\npassword='******'\nAPI_Key=' + token + '\n'
    with open(default_passwd_file, 'w') as f:
        f.write(to_write_str)

    print('new user created: {}'.format(username))
    print('password: {}'.format(password))
    print('token: {}'.format(token))
Esempio n. 3
0
config_loader = ConfigLoader.ConfigLoader()
r_serv = config_loader.get_redis_conn("Redis_SERV")
config_loader = None
###  ###

if __name__ == "__main__":

    # create role_list
    if not r_serv.exists('d4:all_role'):
        role_dict = {'admin': 1, 'user': 2, 'sensor_register': 20}
        r_serv.zadd('d4:all_role', role_dict)

    username = '******'
    password = gen_password()
    if r_serv.exists('user_metadata:[email protected]'):
        edit_user_db(username, password=password, role='admin')
    else:
        create_user_db(username, password, role='admin', default=True)

    username2 = '*****@*****.**'
    password2 = gen_password()
    if r_serv.exists('user_metadata:[email protected]'):
        edit_user_db(username2, password=password2, role='sensor_register')
    else:
        create_user_db(username2,
                       password2,
                       role='sensor_register',
                       default=True)

    token = get_default_admin_token()