当前位置: 首页>>代码示例>>Python>>正文


Python users.User方法代码示例

本文整理汇总了Python中users.User方法的典型用法代码示例。如果您正苦于以下问题:Python users.User方法的具体用法?Python users.User怎么用?Python users.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在users的用法示例。


在下文中一共展示了users.User方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def login():
    if g.user is not None:
        return redirect(url_for('index'))

    form = LoginForm(request.form)

    if request.method == 'POST' and form.validate():
        user = users.User.query.filter_by(username=form.username.data).first()
        if user is None:
            flash(u'El usuario no existe')
        elif not user.checkpassword(form.password.data):
            flash(u'Contraseña incorrecta')
            app.logger.info('[%s] login failed', user)
        else:
            flash(u'Bienvenido de nuevo, %s'%user.username)
            session['user_id'] = user.id
            g.user = user
            app.logger.info('[%s] login succeeded', user)
            return level.autosolve(app) or redirect(url_for('index'))

    return redirect(url_for('index')) 
开发者ID:marcan,项目名称:hackit,代码行数:23,代码来源:app.py

示例2: _load

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def _load(self) -> UserData:
        """
        :return: Dict or None; the loaded information from Redis.
        """
        result = self.redis.get(self.redis_key.format(self.username))
        if not result:
            if self.create_if_not_found:
                logging.debug(
                    'Did not find existing user, loaded blank slate.'
                )
                return self._create_default_user_data()
            else:
                logging.debug('User not found, returning None.')
                raise UserDataNotFound()

        return json.loads(result.decode()) 
开发者ID:GrafeasGroup,项目名称:tor,代码行数:18,代码来源:users.py

示例3: setUp

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def setUp(self):
        try:
            g.rdb_conn = r.connect(
                host=app.config['DBHOST'], port=app.config['DBPORT'],
                auth_key=app.config['DBAUTHKEY'], db=app.config['DATABASE'])

            userdata = {
                'username': 'test@tester.com',
                'email': 'test@tester.com',
                'password': 'password456',
                'company': 'company',
                'contact': 'tester'
            }

            # Create test user
            user = User()
            user.config = app.config
            user.createUser(userdata, g.rdb_conn)

        except RqlDriverError:
            # If no connection possible throw 503 error
            abort(503, "No Database Connection Could be Established.") 
开发者ID:Runbook,项目名称:runbook,代码行数:24,代码来源:base.py

示例4: test_user_registration

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def test_user_registration(self):
        # Ensure user registration behaves correctly.
        with self.client:
            response = self.client.post('/signup', data=dict(
                email='test@user.com',
                company="test",
                contact="test",
                password='test_user',
                confirm='test_user'
            ), follow_redirects=True)
            self.assertEqual(response.status_code, 200)
            self.assertIn('Runbooks', response.data)
            user = User()
            user.config = app.config
            user = user.get('username', 'test@user.com', g.rdb_conn)
            self.assertTrue(user.email == 'test@user.com')
            self.assertTrue(user.status == 'active')
            self.assertFalse(user.confirmed)
            self.assertTrue(user.is_active('test@tester.com', g.rdb_conn)) 
开发者ID:Runbook,项目名称:runbook,代码行数:21,代码来源:test_user.py

示例5: test_user_registration_duplicates

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def test_user_registration_duplicates(self):
        # Ensure user registration behaves correctly for duplicates.
        with self.client:
            self.client.post('/signup', data=dict(
                email='test@user.com',
                company="test",
                contact="test",
                password='test_user',
                confirm='test_user'
            ), follow_redirects=True)
            response = self.client.post('/signup', data=dict(
                email='test@user.com',
                company="test",
                contact="test",
                password='test_user',
                confirm='test_user'
            ), follow_redirects=True)
            self.assertEqual(response.status_code, 200)
            self.assertIn('Sign up', response.data)
            self.assertIn('User already exists.', response.data) 
开发者ID:Runbook,项目名称:runbook,代码行数:22,代码来源:test_user.py

示例6: test_get_by_id

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def test_get_by_id(self):
        # Ensure id is correct for the current/logged in user
        with self.client:
            response = self.client.post('/login', data=dict(
                email='test@tester.com', password='password456'
            ), follow_redirects=True)
            print response
            logged_in_user_id = verifyLogin(
                app.config['SECRET_KEY'],
                app.config['COOKIE_TIMEOUT'],
                request.cookies
            )
            user = User()
            user.config = app.config
            user_id = user.getUID('test@tester.com', g.rdb_conn)
            self.assertTrue(logged_in_user_id == user_id) 
开发者ID:Runbook,项目名称:runbook,代码行数:18,代码来源:test_user.py

示例7: test_validate_confirmation_token

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def test_validate_confirmation_token(self):
        # Ensure valid token can be successfully confirmed in the views
        timestamp = time.time()
        token = generate_confirmation_token(
            'test@tester.com', 1, timestamp)
        with self.client:
            self.client.post('/login', data=dict(
                email='test@tester.com', password='password456'
            ), follow_redirects=True)
            response = self.client.get(
                '/confirm/'+str(token), follow_redirects=True)
            user = User()
            user.config = app.config
            user = user.get('username', 'test@tester.com', g.rdb_conn)
            self.assertTrue(user.confirmed)
            self.assertEqual(response.status_code, 200)
            self.assertIn('Runbooks', response.data)
            self.assertIn('You have confirmed your account. Thanks!',
                          response.data) 
开发者ID:Runbook,项目名称:runbook,代码行数:21,代码来源:test_user.py

示例8: test_validate_confirmation_token_invalid_email

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def test_validate_confirmation_token_invalid_email(self):
        # Ensure invalid email cannot be successfully confirmed in the views
        timestamp = time.time()
        token = generate_confirmation_token(
            'incorrect@email.com', 1, timestamp)
        with self.client:
            self.client.post('/login', data=dict(
                email='test@tester.com', password='password456'
            ), follow_redirects=True)
            response = self.client.get(
                '/confirm/'+str(token), follow_redirects=True)
            user = User()
            user.config = app.config
            user = user.get('username', 'test@tester.com', g.rdb_conn)
            self.assertFalse(user.confirmed)
            self.assertEqual(response.status_code, 200)
            self.assertIn('Login', response.data)
            self.assertIn('The confirmation link is invalid',
                          response.data) 
开发者ID:Runbook,项目名称:runbook,代码行数:21,代码来源:test_user.py

示例9: test_validate_confirmation_token_invalid

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def test_validate_confirmation_token_invalid(self):
        # Ensure invalid token cannot be successfully confirmed in the views
        with self.client:
            self.client.post('/login', data=dict(
                email='test@tester.com', password='password456'
            ), follow_redirects=True)
            response = self.client.get(
                '/confirm/incorrect', follow_redirects=True)
            user = User()
            user.config = app.config
            user = user.get('username', 'test@tester.com', g.rdb_conn)
            self.assertFalse(user.confirmed)
            self.assertEqual(response.status_code, 200)
            self.assertIn('Login', response.data)
            self.assertIn('The confirmation link is invalid or has expired.',
                          response.data) 
开发者ID:Runbook,项目名称:runbook,代码行数:18,代码来源:test_user.py

示例10: page_not_found

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def page_not_found(e):
    return render_template('notfound.html'), 404

# ====== User management ====== 
开发者ID:marcan,项目名称:hackit,代码行数:6,代码来源:app.py

示例11: register

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def register():
    if g.user is not None:
        return redirect(url_for('index'))

    form = RegistrationForm(request.form)

    if request.method == 'POST' and form.validate():
        if form.username.data in app.config['BANNED_USERNAMES']:
            form.username.errors.append(u'Buen intento ;)')
            return render_template('register.html', form=form)
        if app.config['USE_SEAT']:
            seat = form.seat.data
        else:
            seat = None
        newuser = users.User(form.username.data, form.password.data,
            form.pubname.data, form.email.data, seat)
        try:
            users.db.session.add(newuser)
            users.db.session.commit()
        except sqlalchemy.exc.IntegrityError:
            form.username.errors.append(u'Ya existe un usuario con ese nombre')
        else:
            flash(u'Te has registrado con éxito. ¡Comienza el desafío!')
            session['user_id'] = newuser.id
            g.user = newuser
            app.logger.info('[%s] Registered %r,%r,%r', g.user, g.user.pubname, g.user.email, g.user.seat)
            return level.autosolve(app) or redirect(url_for('index'))

    return render_template('register.html', form=form) 
开发者ID:marcan,项目名称:hackit,代码行数:31,代码来源:app.py

示例12: setup_tasks

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def setup_tasks():
    if request.method == 'POST':
        if ('csrf_token' not in session or (
            ('csrf_token' not in request.form or
                request.form['csrf_token'] != session['csrf_token'])
            and ('X-CSRF' not in request.headers or
                 request.headers['X-CSRF'] != session['csrf_token']))):
            flash(u'Error de token CSRF')
            return redirect(url_for('index'))

    if 'csrf_token' not in session:
        session['csrf_token'] = os.urandom(8).encode('hex')

    g.user = None

    if 'user_id' in session and not request.path.startswith('/static/'):
        g.user = users.User.query.filter_by(id=session['user_id']).first()
        if g.user is None:
            del session['user_id']

    g.sb_routes = []
    for r in level.routes:
        lv = []
        for l in r.levels:
            lv.append(l)
        g.sb_routes.append((r, lv))

# ====== Built-in server ====== 
开发者ID:marcan,项目名称:hackit,代码行数:30,代码来源:app.py

示例13: register

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User(name=form.name.data, email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        return 'register successed!'
    return render_template('chapter4/section2/register.html', form=form) 
开发者ID:dongweiming,项目名称:web_develop,代码行数:11,代码来源:app_wtf.py

示例14: users

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def users():
    username = request.form.get('name')

    user = User(username)
    print 'User ID: {}'.format(user.id)
    db.session.add(user)
    db.session.commit()

    return jsonify({'id': user.id}) 
开发者ID:dongweiming,项目名称:web_develop,代码行数:11,代码来源:app_with_sqlalchemy.py

示例15: got_reply_on_cron

# 需要导入模块: import users [as 别名]
# 或者: from users import User [as 别名]
def got_reply_on_cron(message):
    message_text = message.text
    # get money in pocket from firefly
    current_balance = firefly.getCurrentBalance(message.from_user.username, users)

    # get number
    message_number = re.findall('\d+', message_text)[0]
    message_text = message_text.replace(message_number,'')

    if not message_number:
        bot.reply_to(message, MESSAGES["excuses_for_bothering"])
        bot.send_message(users.getMasterId(), "User @"+message.from_user.username+" ignores me!")
        pass
    else:
        try:
            message_integer = int(message_number)
            balance_diff = message_integer-current_balance
            if message_integer > current_balance:
                # get balances and incomes from firefly
                balances = firefly.getBalances(message.from_user.username, users)
                balances.extend(firefly.getIncomes(message.from_user.username, users))

                markup = telebot.types.ReplyKeyboardMarkup()
                for balance in balances:
                    markup.row(telebot.types.KeyboardButton('took '+str(abs(balance_diff))+' from '+str(balance)))
                bot.reply_to(message, MESSAGES["where_did_you_get_money"], reply_markup=markup)
            elif message_integer < current_balance:
                bot.send_message(message.chat.id, "You have spent "+str(abs(balance_diff))+".")
                _talk_about_spent_money(message, message_number=str(abs(balance_diff)))
            else:
                bot.send_message(message.chat.id, "Nothing changed. Thanks for info!")
        except Exception as err:
            print(err)


# Adding money to user's balance from another balance
# Works with messages:
# - took 1231 from balance1
# - took 1231 
开发者ID:may-cat,项目名称:firefly-iii-telegram-bot,代码行数:41,代码来源:bot.py


注:本文中的users.User方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。