def run(self):
     email = prompt('email')
     admin_role = user_datastore.find_or_create_role('ADMIN')
     user = User.objects.filter(email=email).first()
     if not user:
         print("No user found for email:", email)
     else:
         user_datastore.add_role_to_user(user, admin_role)
示例#2
0
 def run(self):
     email = prompt('email')
     admin_role = user_datastore.find_or_create_role('ADMIN')
     user = User.objects.filter(email=email).first()
     if not user:
         print("No user found for email:", email)
     else:
         user_datastore.add_role_to_user(user, admin_role)
示例#3
0
def add_user():
    from application.extensions import user_datastore

    email = request.form["email"]
    full_name = request.form["full-name"]
    if not User.objects.filter(email=email).first():
        password = encrypt_password("password")
        user = user_datastore.create_user(email=email, password=password, full_name=full_name)
        user_role = user_datastore.find_or_create_role("USER")
        user_datastore.add_role_to_user(user, user_role)
        user.save()

    flash("Saved user " + email)
    return redirect(url_for("hatch.open"))
示例#4
0
def add_user():
    from application.extensions import user_datastore
    email = request.form['email']
    full_name = request.form['full-name']
    if not User.objects.filter(email=email).first():
        password = encrypt_password('password')
        user = user_datastore.create_user(email=email,
                                          password=password,
                                          full_name=full_name)
        user_role = user_datastore.find_or_create_role('USER')
        user_datastore.add_role_to_user(user, user_role)
        user.save()

    flash("Saved user " + email)
    return redirect(url_for('hatch.open'))
示例#5
0
 def run(self):
     from flask_security.utils import encrypt_password
     email = prompt('email')
     full_name = prompt('full name')
     password = prompt_pass('password')
     if not User.objects.filter(email=email).first():
         user = user_datastore.create_user(
             email=email,
             password=encrypt_password(password),
             full_name=full_name)
         user_role = user_datastore.find_or_create_role('USER')
         user_datastore.add_role_to_user(user, user_role)
         user.save()
     else:
         print("User with email:", email, "already exists")
 def run(self):
     from flask_security.utils import encrypt_password
     email = prompt('email')
     full_name = prompt('full name')
     password = prompt_pass('password')
     if not User.objects.filter(email=email).first():
         user = user_datastore.create_user(
             email=email,
             password=encrypt_password(password),
             full_name=full_name)
         user_role = user_datastore.find_or_create_role('USER')
         user_datastore.add_role_to_user(user, user_role)
         email_domain = app.config.get('EMAIL_DOMAIN')
         user_name = email.split('@')[0]
         user.inbox_email = "%s@%s" % (user_name, email_domain)
         user.save()
     else:
         print("User with email:", email, "already exists")
示例#7
0
    def run(self):
        email = prompt('email')
        full_name = prompt('full name')
        password = prompt_pass('password')

        if not User.objects.filter(email=email):
            self.create_auth0_user(full_name, email, password)
            user = self.create_app_user(full_name, email)

            user_role = user_datastore.find_or_create_role('USER')
            user_datastore.add_role_to_user(user, user_role)

            user.update(inbox_email="{username}@{domain}".format(
                username=email.split('@')[0],
                domain=current_app.config.get('EMAIL_DOMAIN')))

        else:
            print("User with email:", email, "already exists")
    def run(self):
        email = prompt('email')
        full_name = prompt('full name')
        password = prompt_pass('password')

        if not User.objects.filter(email=email):
            self.create_auth0_user(full_name, email, password)
            user = self.create_app_user(full_name, email)

            user_role = user_datastore.find_or_create_role('USER')
            user_datastore.add_role_to_user(user, user_role)

            user.update(
                inbox_email="{username}@{domain}".format(
                    username=email.split('@')[0],
                    domain=current_app.config.get('EMAIL_DOMAIN')))

        else:
            print("User with email:", email, "already exists")
示例#9
0
    def run(self):
        password = '******'  # toy password for all users for now
        with open('./users.txt') as users_file:
            users = users_file.readlines()
            for user_details in users:
                email, name = user_details.strip().split(',')
                user = User.objects.filter(email=email).first()
                if not user:
                    print("No user found for email:", email, "so create")
                    user = user_datastore.create_user(
                        email=email,
                        password=encrypt_password(password),
                        full_name=name)
                    admin_role = user_datastore.find_or_create_role('ADMIN')
                    user_datastore.add_role_to_user(user, admin_role)
                    user.save()

                else:
                    print("User with email:", email, "already created")
def oidc_callback():
    auth_code = request.args.get('code')
    provider = session['provider']

    try:
        user_info = current_app.oidc_client.authenticate(
            provider,
            auth_code,
            url_for('.oidc_callback', _external=True))

    except Exception as e:
        flash('Login failed: {}: {}'.format(e.__class__.__name__, e), 'error')
        return redirect(url_for('frontend.index'))

    user = user_datastore.get_user(user_info['email'])

    if not user:
        # query identity mapping service for linked identities that may already
        # have an account
        for uid in mapped_ids(user_info['email'])['ids']:
            user = user_datastore.get_user(uid)
            if user:
                break

        if not user:
            # user has successfully logged in or registered on IdP
            # so create an account
            user = user_datastore.create_user(
                email=user_info['email'],
                inbox_email=make_inbox_email(user_info['email']),
                full_name=user_info.get('nickname', user_info.get('name')))
            user_role = user_datastore.find_or_create_role('USER')
            user_datastore.add_role_to_user(user, user_role)

    login_user(user)

    publish_login(user)

    if 'next' in request.args:
        return redirect(request.args['next'])

    return redirect(url_for('frontend.index'))
示例#11
0
def oidc_callback():
    auth_code = request.args.get('code')
    provider = session['provider']

    try:
        user_info = current_app.oidc_client.authenticate(
            provider, auth_code, url_for('.oidc_callback', _external=True))

    except Exception as e:
        flash('Login failed: {}: {}'.format(e.__class__.__name__, e), 'error')
        return redirect(url_for('frontend.index'))

    user = user_datastore.get_user(user_info['email'])

    if not user:
        # query identity mapping service for linked identities that may already
        # have an account
        for uid in mapped_ids(user_info['email'])['ids']:
            user = user_datastore.get_user(uid)
            if user:
                break

        if not user:
            # user has successfully logged in or registered on IdP
            # so create an account
            user = user_datastore.create_user(
                email=user_info['email'],
                inbox_email=make_inbox_email(user_info['email']),
                full_name=user_info.get('nickname', user_info.get('name')))
            user_role = user_datastore.find_or_create_role('USER')
            user_datastore.add_role_to_user(user, user_role)

    login_user(user)

    publish_login(user)

    if 'next' in request.args:
        return redirect(request.args['next'])

    return redirect(url_for('frontend.index'))