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 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)
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 authorized(): github = GitHub(app) if 'code' in request.args: access_token = github._handle_response() else: access_token = github._handle_invalid_response() if not access_token: flash('Error getting access token.', 'warning') return redirect(url_for('public.home')) r = requests.get('https://api.github.com/user', params={"access_token": access_token}) user_details = json.loads(r.content) if not user_details: flash('Error getting user details.', 'warning') return redirect(url_for('public.home')) # if necessary, add user github_username = user_details["login"] email = user_details["email"] if not email: email = github_username user = User.query.filter_by(github_username=github_username).first() if user: login_user(user) flash('You have logged-in using GitHub.', 'success') if not user: user = User.create(username=github_username, email=email, github_username=github_username) login_user(user) flash('You have logged-in using GitHub for the first time.', 'success') return redirect(url_for('public.home'))
def load_user(user_id): """Load user by ID.""" return User.get_by_id(int(user_id))
def test_password_is_nullable(self): """Test null password.""" user = User(username='******', email='*****@*****.**') user.save() assert user.password is None
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)