Esempio n. 1
0
def invite_user(email, password):
    """
    Creates new user (login=<email>) or updates its password
    """

    form = ConsoleRegisterForm(email=email, password=password)
    if form.validate():
        try:
            User.init(email, password, None, is_admin=True)
            print('Admin-user created (%s)') % email
        except Exception as e:
            print(e)
    else:
        print(form.errors)
Esempio n. 2
0
def find_or_create_user(email, password, is_admin=False):
    """ Find existing user or create new user """
    user = User.query.filter(User.email == email).first()
    if not user:
        user = User.init(
            email=email,
            password=password,
            active=True,
            is_admin=is_admin
        )

        db.session.add(user)
    return user
Esempio n. 3
0
def invite(invite_hash):
    print(request.form)

    if invite_hash:
        from app.models.Invite import Invite
        invite = Invite.query.filter_by(invite=invite_hash).filter_by(activated=False).first()
        if not invite:
            user = User.query.filter_by(email=invite.email).first()
            invite.update(activated=True)
            login_user(user)
        return redirect('/login')

    else:
        user = User.init(request.form['email'], invite=invite_hash, active=True)
        # return redirect(url_for('/admin', messages={"main":'Invite message to {0} successfully send'.format(user.email)}))
        return redirect(url_for('admin'))
Esempio n. 4
0
def invite(invite_hash):
    print(request.form)

    if invite_hash:
        from app.models.Invite import Invite
        invite = Invite.query.filter_by(invite=invite_hash).filter_by(
            activated=False).first()
        if not invite:
            user = User.query.filter_by(email=invite.email).first()
            invite.update(activated=True)
            login_user(user)
        return redirect('/login')

    else:
        user = User.init(request.form['email'],
                         invite=invite_hash,
                         active=True)
        # return redirect(url_for('/admin', messages={"main":'Invite message to {0} successfully send'.format(user.email)}))
        return redirect(url_for('admin'))
Esempio n. 5
0
def create_default_users():
    """
    Creates new default users
    """

    # Create all tables
    db.create_all()

    users = [
        ['*****@*****.**', 'qwe'],
        ['*****@*****.**', 'qwe']
    ]
    for item in users:
        email = item[0]
        password = item[1]
        user = User.query.filter(User.email == email).first()
        if not user:
            user = User.init(email=email, password=password, active=True, is_admin=True)
            db.session.add(user)

    # Save to DB
    db.session.commit()