示例#1
0
def _add_user(form):
    user = User(username=form.username.data,
                email=form.email.data,
                password=form.password.data)
    db.session.add(user)

    try:
        db.session.commit()
    except sqlalchemy.exc.IntegrityError as e:
        if 'email is not unique' in e.message:
            form.email.errors.append(
                "This email address is already registered: please use another."
            )
        if 'username is not unique' in e.message:
            form.username.errors.append(
                "This username is taken: please use another.")
        return False

    # Fallthrough: all's gone well.
    return True
示例#2
0
    while not email:
        email = raw_input("Admin email: ").strip()

    password = ''
    while not password:
        password = getpass("Admin password: "******"Primary consumer key [annotateit]: ").strip()
    if not ckey:
        ckey = 'annotateit'

    with annotator.app.test_request_context():

        print("\nCreating admin user... ", end="")

        u = User(username, email, password)

        annotator.db.session.add(u)
        annotator.db.session.commit()

        print("done.")

        print("Creating primary consumer... ", end="")

        c = Consumer(ckey)
        c.user_id = u.id

        annotator.db.session.add(c)
        annotator.db.session.commit()

        print("done.\n")
示例#3
0
 def test_null_password(self):
     u = User('joe', '*****@*****.**')
     h.assert_false(u.check_password('foo'))
示例#4
0
 def test_password(self):
     u = User('joe', '*****@*****.**')
     u.password = '******'
     h.assert_is_not_none(u.password_hash)
     h.assert_true(u.check_password('foo'))
示例#5
0
 def test_constructor(self):
     u = User('joe', '*****@*****.**')
     h.assert_equal(u.username, 'joe')
     h.assert_equal(u.email, '*****@*****.**')
示例#6
0
 def test_null_password(self):
     u = User('joe', '*****@*****.**')
     h.assert_false(u.check_password('foo'))
示例#7
0
 def test_password(self):
     u = User('joe', '*****@*****.**')
     u.password = '******'
     h.assert_is_not_none(u.password_hash)
     h.assert_true(u.check_password('foo'))