コード例 #1
0
ファイル: views.py プロジェクト: ruipacheco/fruitshow2
def new_thread():
    """ Used to create new threads for discussion. """
    
    if request.method == 'POST':
        form = ThreadForm(request.form)
        
        if form.validate():
            thread = form.populated_object()
            if current_user.is_active() and len(form.display_name.data) == 0:
                thread.user = current_user
                #TODO Put Role dropdown box in Python form
                role_display_hash = request.form['role']
                thread.role = Role.query.filter(Role.display_hash==role_display_hash).first()
            db.session.add(thread)
            db.session.commit()
            
            return redirect(url_for('thread', display_hash=thread.display_hash, title=thread.slug()))
            
    if request.method == 'GET':
        form = ThreadForm()
    
    if current_user.is_active():
        roles = current_user.roles
    else:
        roles = None
    
    return render_template('new_thread.html', form=form, roles=roles, action=url_for('new_thread'))
コード例 #2
0
ファイル: views.py プロジェクト: ruipacheco/fruitshow2
def thread(display_hash=None, title=None):
    """ Add comments to an existing thread. """
    
    if display_hash is None:
        abort(404)
    
    thread = Thread.query.filter(Thread.display_hash==display_hash).first()
    if not thread:
        abort(404)
    
    if not current_user.is_active() and thread.user is not None and \
    thread.role is not None and thread.role not in current_user.roles:
        abort(403)
    
    if request.method == 'POST':
        form = PostForm(request.form)
        
        if form.validate():
            post = form.populated_object()
            post.thread = thread
            thread.last_updated = post.date_created
            if current_user.is_active():
                post.user = current_user
                post.display_name = None
            db.session.add(post)
            db.session.commit()
            
            anchor = 'p' + str(post.display_hash)
            return redirect(url_for('thread', display_hash=thread.display_hash, title=thread.slug(), _anchor=anchor))
    
    if request.method == 'GET':
        form = PostForm()
    
    return render_template('thread.html', thread=thread, form=form)
コード例 #3
0
ファイル: views_my_account.py プロジェクト: warddr/MALMan
def index():
    if current_user and current_user.is_active() and current_user.active_member:
        # is an aproved member
        user = DB.User.query.get(current_user.id)
        return render_template('my_account/overview.html', user=user)
    elif current_user and current_user.is_active():
        # is logged in but not aproved yet
        return render_template('my_account/waiting_aproval.html')
    else:
        # is not logged in
        return redirect(url_for_security('login'))
コード例 #4
0
ファイル: views_my_account.py プロジェクト: Oddly/MALMan
def index():
    if current_user and current_user.is_active() and current_user.active_member:
        # is an aproved member
        user = DB.User.query.get(current_user.id)
        return render_template('my_account/overview.html', user=user)
    elif current_user and current_user.is_active():
        # is logged in but not aproved yet
        return render_template('my_account/waiting_aproval.html')
    else:
        # is not logged in
        return redirect(url_for_security('login'))
コード例 #5
0
def _is_admin():
    is_admin = False
    user_db = UserDB()
    if current_user.is_authenticated() and current_user.is_active():
        admin_group = user_db.get_group(mainApp.config['ADMIN_GROUP'])
        is_admin = user_db.in_group(current_user, admin_group)
    return is_admin
コード例 #6
0
ファイル: for_requests.py プロジェクト: gitex/dating
def get_data():
    event = request.json['event']
    # print request.headers

    if event == 'random_user':
        # Exclude me, my like users, users that don't show and my subscriptions
        if current_user.is_authenticated() and current_user.is_active():
            exclude_list = [current_user.login]
            exclude_list.extend(current_user.users_like)
            exclude_list.extend(current_user.following)

            fields = ['sid', 'login', 'birthday', 'description']

            fields_from_base = {field: '$' + field for field in fields}
            all_users = mongo.db.users.aggregate([
                {"$group": {"_id": fields_from_base}}
            ])

            clear_users = [user[u'_id'] for user in all_users['result'] if user[u'_id'][u'login'] not in exclude_list]
            random_user = random.choice(clear_users)
            random_user['age'] = age(random_user['birthday'])
            return jsonify(result='OK', user=random_user)
        else:
            return jsonify(result='None', data="User is not authenticated", event=event, user=str(_get_user()))
    return jsonify(status="No response", event=event)
コード例 #7
0
ファイル: test_account.py プロジェクト: euphoris/webpat
def test_sign_out(client):
    sign_up(username='******', password='******')
    with client:
        sign_in(username='******', password='******')
        logout_user()
        assert not current_user.is_active()
        assert current_user.is_anonymous()
コード例 #8
0
ファイル: test.py プロジェクト: fcs23800/flask-intro
    def test_correct_login(self):

        with self.client:
            response = self.client.post("/login", data=dict(username="******", password="******"), follow_redirects=True)
            self.assertIn(b"You were logged in", response.data)
            self.assertTrue(current_user.name == "admin")
            self.assertTrue(current_user.is_active())
コード例 #9
0
ファイル: test.py プロジェクト: wilcoxky/flask-intro
 def test_logout(self):
     with self.client:
         response = self.client.post(
             '/login', data=dict(username="******", password="******"), follow_redirects=True)
         response = self.client.get('/logout', follow_redirects=True)
         self.assertTrue(b'You were just logged out' in response.data)
         self.assertFalse(current_user.is_active())
コード例 #10
0
ファイル: users.py プロジェクト: hammygoonan/FlaskTemplate
 def test_can_login(self):
     """Test user can login."""
     with self.client:
         response = self.login()
         self.assertEqual(response.status_code, 200)
         self.assertTrue(current_user.is_active())
         self.assertTrue(current_user.email == self.email)
コード例 #11
0
ファイル: test_user.py プロジェクト: ddparker/lms
 def test_update_password(self):
     # Ensure update password behaves correctly.
     with self.client:
         self.client.post('/login',
                          data=dict(
                              email='*****@*****.**',
                              password='******',
                          ),
                          follow_redirects=True)
         self.client.post('/password',
                          data=dict(password='******',
                                    confirm='updated_student_password'),
                          follow_redirects=True)
         self.client.get('/logout', follow_redirects=True)
         response = self.client.post(
             '/login',
             data=dict(
                 email='*****@*****.**',
                 password='******',
             ),
             follow_redirects=True)
         self.assertIn(b'<h1>Welcome, <em>[email protected]</em>!</h1>',
                       response.data)
         self.assertTrue(current_user.email == '*****@*****.**')
         self.assertTrue(current_user.is_authenticated())
         self.assertTrue(current_user.is_active())
         self.assertFalse(current_user.is_anonymous())
         self.assertTrue(current_user.is_student())
         self.assertFalse(current_user.is_teacher())
         self.assertFalse(current_user.is_admin())
         self.assertEqual(response.status_code, 200)
コード例 #12
0
ファイル: test_user.py プロジェクト: ddparker/lms
 def test_update_password2(self):
     # Ensure update password behaves correctly.
     with self.client:
         self.client.post(
             '/login',
             data=dict(
                 email='*****@*****.**',
                 password='******',
             ),
             follow_redirects=True
         )
         response = self.client.post(
             '/password',
             data=dict(
                 password='******',
                 confirm='short'
             ),
             follow_redirects=True
         )
         self.assertIn(
             b'<h1>Update Password</h1>',
             response.data
         )
         self.assertIn(
             b'Field must be between 6 and 25 characters long.',
             response.data
         )
         self.assertTrue(current_user.email == '*****@*****.**')
         self.assertTrue(current_user.is_authenticated())
         self.assertTrue(current_user.is_active())
         self.assertFalse(current_user.is_anonymous())
         self.assertTrue(current_user.is_student())
         self.assertFalse(current_user.is_teacher())
         self.assertFalse(current_user.is_admin())
         self.assertEqual(response.status_code, 200)
コード例 #13
0
ファイル: test.py プロジェクト: fcs23800/flask-intro
    def test_logout(self):

        with self.client:
            self.client.post("/login", data=dict(username="******", password="******"), follow_redirects=True)
            response = self.client.get("/logout", follow_redirects=True)
            self.assertIn(b"You were logged out", response.data)
            self.assertFalse(current_user.is_active())
コード例 #14
0
ファイル: test_account.py プロジェクト: euphoris/webpat
def test_sign_out(client):
    sign_up(username='******', password='******')
    with client:
        sign_in(username='******', password='******')
        logout_user()
        assert not current_user.is_active()
        assert current_user.is_anonymous()
コード例 #15
0
ファイル: test_user.py プロジェクト: ar-qun/Flask-Landing
 def test_logout_behaves_correctly(self):
     # Ensure logout behaves correctly, regarding the session
     with self.client:
         self.client.post("/login", data=dict(email="*****@*****.**", password="******"), follow_redirects=True)
         response = self.client.get("/logout", follow_redirects=True)
         self.assertIn("You were logged out. Bye!", response.data)
         self.assertFalse(current_user.is_active())
コード例 #16
0
ファイル: utils.py プロジェクト: criswell/noink
 def decorated_function(*args, **kwargs):
     s = get_state()
     if mainApp.config['REQUIRE_LOGIN_FOR_DYNAMIC'] and not s.icebox:
         if not current_user.is_authenticated() or not \
                 current_user.is_active():
             return redirect(url_for('login.login_page', next=request.url))
     return f(*args, **kwargs)
コード例 #17
0
def get_data():
    event = request.json['event']
    # print request.headers

    if event == 'random_user':
        # Exclude me, my like users, users that don't show and my subscriptions
        if current_user.is_authenticated() and current_user.is_active():
            exclude_list = [current_user.login]
            exclude_list.extend(current_user.users_like)
            exclude_list.extend(current_user.following)

            fields = ['sid', 'login', 'birthday', 'description']

            fields_from_base = {field: '$' + field for field in fields}
            all_users = mongo.db.users.aggregate([{
                "$group": {
                    "_id": fields_from_base
                }
            }])

            clear_users = [
                user[u'_id'] for user in all_users['result']
                if user[u'_id'][u'login'] not in exclude_list
            ]
            random_user = random.choice(clear_users)
            random_user['age'] = age(random_user['birthday'])
            return jsonify(result='OK', user=random_user)
        else:
            return jsonify(result='None',
                           data="User is not authenticated",
                           event=event,
                           user=str(_get_user()))
    return jsonify(status="No response", event=event)
コード例 #18
0
def _social_authorized(provider, data):
    if provider not in social.providers:
        abort(404)

    if data is None:
        flash('You denied the request to sign in.')
        return redirect(url_for('login'))

    token = data.get('access_token', data.get('oauth_token', ''))
    secret = data.get('oauth_token_secret', '')

    setattr(g, '%s_token' % provider, token)
    setattr(g, '%s_secret' % provider, secret)

    if current_user.is_active():
        getattr(current_user, 'link_%s' % provider)(data)
        flash('%s has been linked with your account!' % provider)
        return redirect(url_for('my_apps'))

    user = getattr(User, 'from_%s' % provider)(data)
    if user:
        login_user(user)
        flash('You were signed in!')

    # FIXME: redirect to wherever the user was
    return redirect(url_for('home'))
コード例 #19
0
 def test_user_registration_error(self):
     # Ensure registration behaves correctly.
     token = stripe.Token.create(
         card={
             'number': '4242424242424242',
             'exp_month': '06',
             'exp_year': str(datetime.datetime.today().year + 1),
             'cvc': '123',
         }
     )
     with self.client:
         response = self.client.post(
             '/register',
             data=dict(
                 email="*****@*****.**",
                 password="******",
                 confirm="testing",
                 card_number="4242424242424242",
                 cvc="123",
                 expiration_month="01",
                 expiration_year="2015",
                 stripeToken=token.id,
             ),
             follow_redirects=True
         )
         user = User.query.filter_by(email='*****@*****.**').first()
         self.assertEqual(user.email, '*****@*****.**')
         self.assertTrue(user.paid)
         self.assertIn('Thanks for paying!', response.data)
         self.assertTrue(current_user.email == "*****@*****.**")
         self.assertTrue(current_user.is_active())
         self.assertEqual(response.status_code, 200)
コード例 #20
0
 def test_user_registration(self):
     # Ensure registration behaves correctly.
     with self.client:
         response = self.client.post(
             '/auth/register',
             data=dict(
                 email='*****@*****.**',
                 username='******',
                 password='******',
                 confirm='testing'
             ),
             follow_redirects=True
         )
         self.assertIn(b'Thank you for registering.\n', response.data)
         self.assertIn(
             b'<li><a href="/auth/logout">Logout</a></li>\n',
             response.data
         )
         self.assertNotIn(
             b'<li><a href="/auth/login"><span class="glyphicon glyphicon-user"></span>&nbsp;Register/Login</a></li>\n',
             response.data
         )
         self.assertTrue(current_user.email == '*****@*****.**')
         self.assertTrue(current_user.is_active())
         self.assertEqual(response.status_code, 200)
コード例 #21
0
ファイル: users.py プロジェクト: hammygoonan/link-shortener
 def test_logout(self):
     """Test user can logout."""
     with self.client:
         self.login()
         response = self.client.get('/users/logout', follow_redirects=True)
         self.assertIn(b'You were logged out', response.data)
         self.assertFalse(current_user.is_active())
コード例 #22
0
ファイル: __init__.py プロジェクト: carbonblack/cb-2fa-login
    def is_accessible(self):
        if not current_user.is_active() or not current_user.is_authenticated():
            return False

        if current_user.has_role('admin'):
            return True

        return False
コード例 #23
0
ファイル: users.py プロジェクト: hammygoonan/FalconCSM
 def test_can_login(self):
     """Test user can login."""
     with self.client:
         response = self.login()
         self.assertEqual(response.status_code, 200)
         self.assertIn(b'You are now logged in.', response.data)
         self.assertTrue(current_user.is_active())
         self.assertTrue(current_user.email == '*****@*****.**')
コード例 #24
0
ファイル: root.py プロジェクト: strayduy/upvotebay
def index(reddit=None):
    if current_user.is_active():
        if current_user.has_confirmed_signup:
            return home()

        return redirect(url_for('root.signup'))

    return landing(reddit)
コード例 #25
0
ファイル: models.py プロジェクト: ivangsm/calepin
 def is_available(cls, username):
     blog = cls.query.filter_by(username=username).first()
     available = blog is None
     if current_user.is_active() and not available:
         # It's available if the user asking owns it
         available = current_user.id == blog.id
     # But not if it's been added to reserved list
     return available and not username in RESERVED_SLUGS
コード例 #26
0
    def is_accessible(self):
        if not current_user.is_active() or not current_user.is_authenticated():
            return False

        if current_user.username == "test":
            return True

        return False
コード例 #27
0
 def test_logout(self):
     with self.client:
         self.client.post('/login',
                          data=dict(username="******", password="******"),
                          follow_redirects=True)
         response = self.client.get('/logout', follow_redirects=True)
         self.assertIn(b'You were logged out', response.data)
         self.assertFalse(current_user.is_active())
コード例 #28
0
 def test_logout(self):
     """ Ensure logout behaves correctly """
     data = {"password" : "admin", "email" : "*****@*****.**"}
     with self.client:
         self.client.post('/api/v1/sessions',data=data)
         resp = self.client.delete('/api/v1/sessions')
         self.assertIn(b'You were logged out', resp.data)
         self.assertFalse(current_user.is_active())
コード例 #29
0
ファイル: models.py プロジェクト: Git-Host/calepin
 def is_available(cls, username):
     blog = cls.query.filter_by(username=username).first()
     available = blog is None
     if current_user.is_active() and not available:
         # It's available if the user asking owns it
         available = current_user.id == blog.id
     # But not if it's been added to reserved list
     return available and not username in RESERVED_SLUGS
コード例 #30
0
 def test_user_registeration(self):
     with self.client:
         response = self.client.post('/register', data=dict(username='******', email='*****@*****.**', password='******', confirm='password'), follow_redirects=True)
         self.assertIn(b'Congrats on your new account!', response.data)
         self.assertTrue(current_user.name == "Testname")
         self.assertTrue(current_user.is_active())
         user = User.query.filter_by(email='*****@*****.**').first()
         self.assertTrue(str(user) == '<name> Testname')
コード例 #31
0
ファイル: ctf.py プロジェクト: AndreaOm/CTF
    def is_accessible(self):
        if not current_user.is_active() or not current_user.is_authenticated():
            return False

        if current_user.username == "test":
            return True

        return False
コード例 #32
0
ファイル: test_users.py プロジェクト: jreiher2003/Wiki
 def test_user_signup(self):
     with self.client:
         response = self.client.post("/signup", data=dict(username="******", email="*****@*****.**", password="******", confirm="password"), follow_redirects=True)
         self.assertIn(b"You just added user <strong>Testname</strong>", response.data)
         self.assertTrue(current_user.name == "Testname")
         self.assertTrue(current_user.is_active())
         user = User.query.filter_by(email="*****@*****.**").first()
         self.assertTrue(str(user) == "<name> Testname")
コード例 #33
0
 def test_correct_login(self):
     with self.client:
         response = self.client.post(
             '/login',
             data=dict(username="******", password="******"),
             follow_redirects=True
         )
         self.assertIn(b'Hi, admin!', response.data)
         self.assertTrue(current_user.is_active())
コード例 #34
0
 def test_user_registeration(self):
     with self.client:
         response = self.client.post('register/', data = dict(
             username = '******', email = '*****@*****.**',
             password = '******', confirm = 'python'
         ), follow_redirects = True)
         self.assertIn(b'Welcome to Flask!', response.data)
         self.assertTrue(current_user.name == "Michael")
         self.assertTrue(current_user.is_active())
コード例 #35
0
ファイル: api.py プロジェクト: DBeath/push-tester
    def serialize_date(self, date):
        if date:
            if current_user.is_active():
                utc = pytz.utc.localize(date)
                localized = utc.astimezone(current_user.get_tz())
                return localized.isoformat()
            return date.isoformat()

        return None
コード例 #36
0
ファイル: test_users.py プロジェクト: kevlab/discover_flask
 def test_logout_works(self):
     with self.client:
         self.client.post(
             '/login',
             data=dict(username='******', password='******'),
             follow_redirects=True)
         response = self.client.get('/logout', follow_redirects=True)
         self.assertIn('You were just logged out', response.data)
         self.assertFalse(current_user.is_active())
コード例 #37
0
 def test_user_registeration(self):
     with self.client:
         response = self.client.post('register/', data=dict(
             username='******', email='*****@*****.**',
             password='******', confirm='python'
         ), follow_redirects=True)
         self.assertIn(b'Welcome to Flask!', response.data)
         self.assertTrue(current_user.name == "Michael")
         self.assertTrue(current_user.is_active())
コード例 #38
0
 def test_correct_login(self):
     with self.client:
         response = self.client.post('/login', data=dict(
             email="*****@*****.**", password="******"
         ), follow_redirects=True)
         self.assertIn(b'Welcome', response.data)
         self.assertTrue(current_user.email = "*****@*****.**")
         self.assertTrue(current_user.is_active())
         self.assertTrue(response.status_code == 200)
コード例 #39
0
ファイル: decorators.py プロジェクト: wilrona/Gesacom
    def decorated_view(*args, **kwargs):
        if not current_user.is_authenticated() or not session.get('user_id'):
            return redirect(url_for('home.index'))

        if current_user.is_authenticated() and not current_user.is_active():
            flash('Votre compte est desactive. Contactez votre administrateur', 'danger')
            return redirect(url_for('user.logout'))

        return func(*args, **kwargs)
コード例 #40
0
ファイル: tests.py プロジェクト: jpirih/Flask-Blog
 def test_correct_login(self):
     with self.client:
         response = self.client.post('/login',
                                     data=dict(username='******',
                                               password='******'),
                                     follow_redirects=True)
         self.assertIn(b'You were just logged in :)', response.data)
         self.assertTrue(current_user.name == 'admin')
         self.assertTrue(current_user.is_active())
コード例 #41
0
ファイル: api.py プロジェクト: s2100/flask-starter
    def serialize_date(self, date):
        if date:
            if current_user.is_active():
                utc = pytz.utc.localize(date)
                localized = utc.astimezone(current_user.get_tz())
                return localized.isoformat()
            return date.isoformat()

        return None
コード例 #42
0
 def test_predict_case(self):
     with self.client:
         response = self.client.post('/pressao',
                                     data=dict(batimentos=80, calorias=60),
                                     follow_redirects=True)
         self.assertIn(b'Welcome to Flask!', response.data)
         self.assertTrue(current_user.name == "Michael")
         self.assertTrue(current_user.is_active())
         user = User.query.filter_by(email='*****@*****.**').first()
         self.assertTrue(str(user) == '<name - Michael>')
コード例 #43
0
    def decorated_view(*args, **kwargs):
        if not current_user.is_authenticated() or not session.get('user_id'):
            return redirect(url_for('home.index'))

        if current_user.is_authenticated() and not current_user.is_active():
            flash('Votre compte est desactive. Contactez votre administrateur',
                  'danger')
            return redirect(url_for('user.logout'))

        return func(*args, **kwargs)
コード例 #44
0
 def test_logout_behaves_correctly(self):
     # Ensure logout behaves correctly, regarding the session
     with self.client:
         self.client.post('/login',
                          data=dict(email="*****@*****.**",
                                    password="******"),
                          follow_redirects=True)
         response = self.client.get('/logout', follow_redirects=True)
         self.assertIn('You were logged out. Bye!', response.data)
         self.assertFalse(current_user.is_active())
コード例 #45
0
 def test_correct_login(self):
     # Ensure login behaves correctly with correct credentials.
     with self.client:
         response = self.client.post('/login',
                                     data=dict(email="*****@*****.**",
                                               password="******"),
                                     follow_redirects=True)
         self.assertTrue(current_user.email == "*****@*****.**")
         self.assertTrue(current_user.is_active())
         self.assertEqual(response.status_code, 200)
コード例 #46
0
 def test_user_registeration(self):
     """ Ensure user can register """
     data = {"password" : "password", "invite" : "invite", "email" : "*****@*****.**"}
     with self.client:
         resp = self.client.post("/api/v1/users", data=data)
         self.assertEqual(resp.status_code,  201)
         self.assertEqual(current_user.email, data["email"])
         self.assertTrue(current_user.is_active())
         user = User.query.filter_by(email=data["email"]).first()
         self.assertTrue(user.email == data["email"])
コード例 #47
0
ファイル: test_account.py プロジェクト: euphoris/webpat
def test_sign_in(client):
    with pytest.raises(NoResultFound) as exc:
        sign_in(username='******', password='******')

    sign_up(username='******', password='******')
    with client:
        sign_in(username='******', password='******')
        assert current_user.is_active()
        assert not current_user.is_anonymous()
        assert current_user.username == 'testuser'
コード例 #48
0
    def test_logout_behaves_correctly(self):
        with self.client:
            self.client.post('/login', data=dict(
                email="*****@*****.**", password="******"
            ), follow_redirects=True)
            response = self.client.get('/logout', follow_redirects=True)
            self.assertIn(b'You were logged out.', response.data)
            self.assertFalse(current_user.is_active()

if __name__ == '__main__':
    unittest.main()
コード例 #49
0
 def test_correct_login(self):
     """ Ensure login behaves correctly with correct credentials """
     data = {"password" : "admin", "email" : "*****@*****.**"}
     with self.client:
         resp = self.client.post(
             '/api/v1/sessions',
             data=data)
         self.assertEquals(201, resp.status_code)
         self.assertIn(b'You were logged in', resp.data)
         self.assertTrue(current_user.email == "*****@*****.**")
         self.assertTrue(current_user.is_active())
コード例 #50
0
ファイル: decorators.py プロジェクト: wilrona/Apps-BtoB-Onl
    def decorated_view(*args, **kwargs):

        if current_user.is_active() is False:
            flash('SVP confirmez votre compte!', 'warning')
            return redirect(url_for('user_param.unconfirmed'))

        if not current_user.is_authenticated() or not session.get('user_id'):
            flash('Connectez-vous SVP.', 'danger')
            return redirect(url_for('user.logout'))

        if not current_user.is_authenticated() and session.get('user_id'):
            flash('Connectez-vous SVP.', 'danger')
            return redirect(url_for('user.logout'))

        if current_user.is_authenticated() and not current_user.is_active():
            flash('Votre compte est desactive. Contactez votre administrateur',
                  'danger')
            return redirect(url_for('user.logout'))

        return func(*args, **kwargs)
コード例 #51
0
 def test_user_registration(self):
     # Ensure registration behaves correctlys.
     with self.client:
         response = self.client.post('/register',
                                     data=dict(email="*****@*****.**",
                                               password="******",
                                               confirm="testing"),
                                     follow_redirects=True)
         self.assertIn(b'Welcome', response.data)
         self.assertTrue(current_user.email == "*****@*****.**")
         self.assertTrue(current_user.is_active())
         self.assertEqual(response.status_code, 200)
コード例 #52
0
ファイル: test_users.py プロジェクト: DennisMatveyev/Discover
 def test_user_registration(self):
     with self.client:
         response = self.client.post('/register',
                                     data=dict(username='******',
                                               email='*****@*****.**',
                                               password='******',
                                               confirm='python'),
                                     follow_redirects=True)
         self.assertIn(b'Welcome!', response.data)
         self.assertTrue(current_user.name == "Dennis")
         self.assertTrue(current_user.is_active())
         user = User.query.filter_by(email='*****@*****.**').first()
         self.assertTrue(str(user) == '<name - Dennis>')
コード例 #53
0
ファイル: tests.py プロジェクト: Nickyzj/flask-intro
 def test_user_registration(self):
     with self.client:
         response = self.client.post('/register',
                                     data=dict(
                                         username="******",
                                         email="*****@*****.**",
                                         password="******",
                                         confirm='admin1'),
                                     follow_redirects=True)
         # print response.data
         self.assertIn(b'Welcome to Flask!', response.data)
         self.assertTrue(current_user.name == "michael")
         self.assertTrue(current_user.is_active())
コード例 #54
0
def save_timezone():
    if current_user and current_user.is_active():
        timezone = unicode(request.form.get("timezone")).strip()
        if timezone in pytz.country_timezones("US"):
            current_user.timezone = timezone
            current_user.save()
            return jsonify({'message': 'Timezone updated.'})
        else:
            return jsonify(
                {'message': 'Unrecognized timezone, please try again.'})
    else:
        return jsonify(
            {'message': 'Error updating timezone, please try again.'})
コード例 #55
0
 def test_correct_login(self):
     # Ensure login behaves correctly with correct credentials.
     with self.client:
         response = self.client.post(
             '/login',
             data=dict(email="*****@*****.**", password="******"),
             follow_redirects=True
         )
         self.assertIn('Welcome', response.data)
         self.assertIn('Logout', response.data)
         self.assertIn('Members', response.data)
         self.assertTrue(current_user.email == "*****@*****.**")
         self.assertTrue(current_user.is_active())
         self.assertEqual(response.status_code, 200)
コード例 #56
0
ファイル: views.py プロジェクト: JSteunou/comimoc-back
 def index(self):
     """
     Index of admin panel
     Show welcome message or redirect to login or register if no user yet
     """
     # no user? redirect to register
     if not User.objects.first():
         return redirect(url_for('.register'))
     # no user logged in? redirect to login
     if not current_user.is_authenticated():
         return redirect(url_for('.login'))
     # default = index.html
     return self.render("index.html",
                        login=current_user.login,
                        active=current_user.is_active())