Example #1
0
    def test_get_by_id(self):
        """Get user by ID."""
        user = User('foo', '*****@*****.**')
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
Example #2
0
    def test_get_by_id(self):
        """Get user by ID."""
        user = User('foo', '*****@*****.**')
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
def create_user():
    request_data = request.get_json()
    User.create(id=request_data['id'],
                username=request_data['username'],
                email=request_data['email'],
                password=request_data['password'],
                active=True)
    return jsonify(msg="posted")
Example #4
0
def register():
    """Register new user."""
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        User.create(username=form.username.data, email=form.email.data, password=form.password.data, active=True)
        flash('Thank you for registering. You can now log in.', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
Example #5
0
def register():
    """Register new user."""
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        User.create(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data,
                    active=True)
        flash('Thank you for registering. You can now log in.', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
Example #6
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username="******",
                        email="*****@*****.**",
                        password="******")
     assert user.check_password("foobarbaz123") is True
     assert user.check_password("barfoobaz") is False
Example #7
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username='******',
                        email='*****@*****.**',
                        password='******')
     assert user.check_password('foobarbaz123') is True
     assert user.check_password('barfoobaz') is False
Example #8
0
 def run(user):
     user = User.create(username="******",
                        email="*****@*****.**",
                        password="******",
                        active=True,
                        first_name="admin",
                        last_name="admin",
                        admin=True,
                        confirmed=True,
                        confirmed_on=datetime.datetime.now())
     user.save()
Example #9
0
def confirm_email(token):
    if not current_user.is_anonymous:
        if current_user.email_confirmed:
            flash('You have already verified your email address.', 'info')
            return redirect(url_for('public.home'))
    user = User.verify_confirmation_token(token)
    if not user:
        return redirect(url_for('public.home'))
    user.confirm_email()
    user.active = True
    db.session.commit()
    flash('Your email has been confirmed.', 'success')
    return redirect(url_for('public.home'))
Example #10
0
def reset_password(token):
    if current_user.is_authenticated:
        flash('You are already logged in.', 'info')
        return redirect(url_for('public.home'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('public.home'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('user.login'))
    return render_template('reset_password.html', form=form)
Example #11
0
def registerapi():
    json_data = request.json
    user = User(
        username=json_data['username'],
        email=json_data['email'],
        password=json_data['password']
    )
    try:
        db.session.add(user)
        db.session.commit()
        status = 'success'
    except:
        status = 'this user is already registered'
    db.session.close()
    return jsonify({'result': status})
Example #12
0
def register():
    """Register new user."""
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        user = User.create(username=form.username.data,
                           email=form.email.data,
                           password=form.password.data,
                           active=False)
        flash(
            'Thank you for registering. Please validate your email '
            'address before logging in.', 'success')
        send_confirm_email(user)
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('register.html', form=form)
Example #13
0
def register():
    """Register new user."""
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        user = User.create(username=form.username.data, email=form.email.data, password=form.password.data,
                    first_name=form.firstname.data, last_name=form.lastname.data, active=True, confirmed=False)
        email = form.email.data
        token = generate_confirmation_token(email)
        confirm_url = url_for('public.confirm_email', token=token, _external=True)
        html = render_template('public/email_templates/confirm.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_mailgun_email(email, subject, html)

        login_user(user)

        flash('Thank you for registering, a confirmation email has been sent', 'success')
        return redirect(url_for('public.unconfirmed'))

    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
Example #14
0
 def run(self, username, email, password, new_password, **options):
     if password is None:
         password = uuid.uuid4().__str__().replace('-', '')
     logger.info("User created: %s, %s. With password: %s" %
                 (username, email, password))
     query_set = User.query.filter(User.email == email)
     if query_set.count() is 0:
         user = User.create(username=username,
                            email=email,
                            password=password,
                            active=True,
                            first_name=options.get('firstname',
                                                   email.split('@')[0]),
                            last_name=options.get('lastname',
                                                  email.split('@')[0]))
     else:
         if new_password is False:
             raise ValueError("User Exists")
         user = query_set.first()
         user.set_password(password)
         user.save()
         logger.info("User password renewed")
Example #15
0
    def test_email_confirmation(self, db, testapp):
        """Confirm a user's email address"""
        # Goes to registration page
        with mail.record_messages() as outbox:
            res = testapp.get(url_for('user.register'))

            form = res.forms['registerForm']
            form['username'] = '******'
            form['email'] = '*****@*****.**'
            form['password'] = '******'
            form['confirm'] = 'secret'

            res = form.submit()

            body_html = outbox[0].html

        groups = re.search('<a href=\"http://localhost(.*)\">', body_html)
        confirmation_url = groups[1]

        res = testapp.get(confirmation_url)

        assert User.get_by_id(1).email_confirmed is True
 def test_password_is_nullable(self):
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert user.password is None
Example #17
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username='******', email='*****@*****.**',
                        password='******')
     assert user.check_password('foobarbaz123') is True
     assert user.check_password('barfoobaz') is False
 def test_created_at_defaults_to_datetime(self):
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert bool(user.created_at)
     assert isinstance(user.created_at, dt.datetime)
Example #19
0
def load_user(user_id):
    """Load user by ID."""
    return User.get_by_id(int(user_id))
Example #20
0
 def test_password_is_nullable(self):
     """Test null password."""
     user = User(username="******", email="*****@*****.**")
     user.save()
     assert user.password is None
Example #21
0
def load_user(user_id):
    """Load user by ID."""
    return User.get_by_id(int(user_id))
Example #22
0
 def test_password_is_nullable(self):
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert user.password is None
Example #23
0
 def test_created_at_defaults_to_datetime(self):
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert bool(user.created_at)
     assert isinstance(user.created_at, dt.datetime)
 def test_check_password(self):
     user = User.create(username="******", email="*****@*****.**",
                 password="******")
     assert user.check_password('foobarbaz123') is True
     assert user.check_password("barfoobaz") is False
Example #25
0
 def test_created_at_defaults_to_datetime(self):
     """Test creation date."""
     user = User(username="******", email="*****@*****.**")
     user.save()
     assert bool(user.created_at)
     assert isinstance(user.created_at, dt.datetime)
Example #26
0
def load_user(id):
    return User.get_by_id(int(id))
Example #27
0
def load_user(id):
    return User.get_by_id(int(id))