Beispiel #1
0
def create_users():
    for u in (('matt', '*****@*****.**', 'password', ['admin'], True),
              ('joe', '*****@*****.**', 'password', ['editor'], True),
              ('jill', '*****@*****.**', 'password', ['author'], True),
              ('tiya', '*****@*****.**', 'password', [], False)):
        user_datastore.create_user(username=u[0], email=u[1], password=u[2],
                                   roles=u[3], active=u[4])
        user_datastore.commit()
def create_users():
    for u in (('matt', '*****@*****.**', 'password', ['admin'], True),
              ('jill', '*****@*****.**', 'password', ['author'], True),
              ('tiya', '*****@*****.**', 'password', [], False)): 
        user_datastore.create_user(email=u[1], password=encrypt_password(u[2]),
                                   roles=u[3], active=u[4], confirmed_at=datetime.datetime.now()
                                  )
        user_datastore.commit()
def create_users():
    for u in (('matt', '*****@*****.**', 'password', ['admin'],
               True), ('jill', '*****@*****.**', 'password', ['author'], True),
              ('tiya', '*****@*****.**', 'password', [], False)):
        user_datastore.create_user(email=u[1],
                                   password=encrypt_password(u[2]),
                                   roles=u[3],
                                   active=u[4],
                                   confirmed_at=datetime.datetime.now())
        user_datastore.commit()
Beispiel #4
0
def invite():
    """
    Invite a new person
    """
    form = InviteForm(request.form)
    if form.validate_on_submit():
        from flask_application import user_datastore, app, mail
        user = User.objects(id=current_user.get_id()).first()
        password = binascii.b2a_hex(os.urandom(15))
        # create an account
        user_datastore.create_user(username="******",
                                   email=form.email.data,
                                   password=encrypt_password(password),
                                   roles=['contributor'],
                                   active=True,
                                   invited_by=user)
        user_datastore.commit()
        invitee = User.objects(email=form.email.data).first()
        # set inviter data
        user.add_invitation(invitee)
        # send an email
        msg = Message("An invitation to %s" % app.config['SITE_NAME'],
                      sender=app.config['DEFAULT_MAIL_SENDER'],
                      recipients=[form.email.data])
        msg.body = '''
			You have been invited to %s by %s. 
			Your can log in with the following username/ password:
			%s
			%s
			You can change this random, complicated password after you have logged in.
			''' % (app.config['SITE_NAME'], user.email, form.email.data, password)
        mail.send(msg)
        # @todo: set invited and invited by
        flash(
            "An account has been created for %s and an email has been sent. You may want to let them know that it is coming."
            % form.email.data)
    return render_template('profiles/invite.html', register_user_form=form)
Beispiel #5
0
def invite():
    """
    Invite a new person
    """
    form = InviteForm(request.form)
    if form.validate_on_submit():
        from flask_application import user_datastore, app, mail
        user = User.objects(id=current_user.get_id()).first()
        password = binascii.b2a_hex(os.urandom(15))
        # create an account
        user_datastore.create_user(username="******",
                                   email=form.email.data,
                                   password=encrypt_password(password),
                                   roles=['contributor'],
                                   active=True,
                                   invited_by=user)
        user_datastore.commit()
        invitee = User.objects(email=form.email.data).first()
        # set inviter data
        user.add_invitation(invitee)
        # send an email
        msg = Message("An invitation to %s" % app.config['SITE_NAME'],
                      sender=app.config['DEFAULT_MAIL_SENDER'],
                      recipients=[form.email.data])
        msg.body = '''
			You have been invited to %s by %s. 
			Your can log in with the following username/ password:
			%s
			%s
			You can change this random, complicated password after you have logged in.
			''' % (app.config['SITE_NAME'], user.email, form.email.data, password)
        mail.send(msg)
        # @todo: set invited and invited by
        flash("An account has been created for %s and an email has been sent. You may want to let them know that it is coming." % form.email.data)
    return render_template('profiles/invite.html',
                           register_user_form=form)
Beispiel #6
0
def create_roles():
    for role in ('admin', 'editor', 'author'):
        user_datastore.create_role(name=role, description=role)
    user_datastore.commit()