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


Python User.authenticate方法代码示例

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


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

示例1: login

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

    form = LoginForm()

    if form.validate_on_submit():

        session['remember_me'] = form.remember_me.data
        #user = User.query.filter_by(name=form.name.data.lower()).first()
        user, auth = User.authenticate(form.name.data, form.password.data)
        if user and auth:
            current_app.logger.info(
                form.name.data + ' checked in with data: ' + str(form.remember_me.data))
            session['username'] = form.name.data
            session['log in'] = True
            session['uid'] = str(user.id)
            session['sid'] = hashlib.md5(
                str(user.id).encode('utf-8')).hexdigest()
            login_user(user, remember=session['remember_me'])
            # current_app.logger.info(str(session))
            return redirect(url_for('frontend.index', s_id=session['sid']))
        else:
            current_app.logger.warning(
                'user ' + form.name.data + ' failed with authentication')
            return render_template('login.html', form=form, failed_auth=True)

    return render_template('login.html', form=form), 200
开发者ID:rtx3,项目名称:Salt-MWDS,代码行数:30,代码来源:views.py

示例2: login

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import authenticate [as 别名]
def login():
    if request.method == 'POST':
        user = User(name=request.form.get('username'))
        if user.id and user.authenticate(request.form.get('password')):

            if request.form.get('remember_me'):
                user.login(remember=True)
            else:
                user.login(remember=False)

            if user.is_active():
                flash(messages.logged_in, 'message')
            else:
                flash(messages.user_not_activated, 'message')
                return redirect(url_for('public_index'))

            if request.args.get('next'):
                return redirect(request.args['next'])

            return redirect(url_for('index'))
        else:
            flash(messages.invalid_credentials, 'error')

    next = request.args.get('next')
    return render_template(get_template('login.html'), next=next)
开发者ID:davidnieder,项目名称:blackboard,代码行数:27,代码来源:views.py

示例3: authenticate_user

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import authenticate [as 别名]
 def authenticate_user(self):
     username = self.login_user_name.text()
     password = self.login_password.text()
     if User.authenticate(username, password):
         self._message_box("User Authenticated", 
                           "User {} authenticated".format(username))
     else:
         self._message_box("User Declined", 
                           "User {} declined".format(username))
开发者ID:28Althea,项目名称:op-introduction-to-security,代码行数:11,代码来源:passwords.py

示例4: login_view

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import authenticate [as 别名]
def login_view(request):  
  session = request.session
  if 'user' in session:
    session.flash("you are already logged in.")
    return HTTPFound(location=request.route_url('home'))
    

  if request.method == "POST":
    user = User(request.POST.get("email"))
    if user.authenticate(request.POST.get("password")):
      session["user"] = user
      return HTTPFound(location=request.route_url('home'))
      
  return {'title': 'Login','session': session}
开发者ID:lastk,项目名称:interview,代码行数:16,代码来源:login.py

示例5: show_favorites

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import authenticate [as 别名]
def show_favorites():
    """
    User's favorite channels list
    :return:
    """
    api = API()
    user = User()
    is_authenticated = user.authenticate()

    if is_authenticated:
        favorites = api.get_favorites(user.username, user.token)
        if len(favorites) > 0:
            for item in favorites:
                # list item:
                li = ListItem(u'{0} {1}'.format(item['title'].replace('CALM RADIO -', '').title(),
                                                '(VIP)' if 'free' not in item['streams'] else '',
                                                item['description']),
                              iconImage='{0}/{1}'.format(config['urls']['calm_arts_host'], item['image']),
                              thumbnailImage='{0}/{1}'.format(config['urls']['calm_arts_host'], item['image']))
                li.setArt({
                    'fanart': '{0}{1}'.format(config['urls']['calm_blurred_arts_host'], item['image'])
                })
                li.addContextMenuItems(
                        [(ADDON.getLocalizedString(32301), 'RunPlugin(plugin://{0}/favorites/remove/{1})'
                          .format(ADDON_ID, item['id']))]
                )
                # directory item:
                addDirectoryItem(
                        PLUGIN.handle,
                        PLUGIN.url_for(play_channel,
                                       category_id=item['category'],
                                       channel_id=item['id']),
                        li
                )
            # set the content of the directory
            setContent(ADDON_HANDLE, 'songs')
            # end of directory:
            endOfDirectory(PLUGIN.handle)
            executebuiltin('Container.SetViewMode({0})'.format(
                    config['viewmodes']['thumbnail'][getSkinDir()
                    if getSkinDir() in config['viewmodes']['thumbnail'] else 'skin.confluence']
            ))
        # favorites list is empty:
        else:
            executebuiltin('Notification("{0}", "{1}")'
                           .format(ADDON.getLocalizedString(30000), ADDON.getLocalizedString(32306)))
    # user is not authenticated:
    else:
        executebuiltin('Notification("{0}", "{1}")'
                       .format(ADDON.getLocalizedString(30000), ADDON.getLocalizedString(32110)))
开发者ID:gedisony,项目名称:repo-plugins,代码行数:52,代码来源:addon.py

示例6: add_to_favorites

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import authenticate [as 别名]
def add_to_favorites(channel_id):
    """
    Adds a channels to user's favorites list
    :param channel_id: Channel ID
    :return:
    """
    api = API()
    user = User()
    is_authenticated = user.authenticate()
    if is_authenticated:
        api.add_to_favorites(user.username, user.token, channel_id)
        executebuiltin('Notification("{0}", "{1}"'.format(ADDON.getLocalizedString(30000),
                                                          ADDON.getLocalizedString(32302)))
    else:
        executebuiltin('Notification("{0}", "{1}")'.format(ADDON.getLocalizedString(30000),
                                                           ADDON.getLocalizedString(32110)))
开发者ID:gedisony,项目名称:repo-plugins,代码行数:18,代码来源:addon.py

示例7: play_channel

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import authenticate [as 别名]
def play_channel(category_id, channel_id):
    """
    Plays selected song
    :param category_id: Selected category ID
    :param channel_id: Selected channel ID
    :return:
    """
    api = API()
    user = User()
    is_authenticated = user.authenticate()
    recent_tracks_url = ''
    channel = [item for item in api.get_channels(int(category_id))
               if item['id'] == int(channel_id)][0]
    url = api.get_streaming_url(channel['streams'],
                                user.username,
                                user.token,
                                user.is_authenticated())

    if is_authenticated:
        recent_tracks_url = channel['recent_tracks']['vip']
    elif 'free' in channel['recent_tracks']:
        recent_tracks_url = channel['recent_tracks']['free']

    # is there a valid URL for channel?
    if url:
        url = quote(url, safe=':/[email protected]')
        li = ListItem(channel['title'], channel['description'], channel['image'])
        li.setArt({'thumb': '{0}/{1}'.format(config['urls']['calm_arts_host'], channel['image']),
                   'fanart': '{0}{1}'.format(config['urls']['calm_blurred_arts_host'], channel['image'])})
        li.setInfo('music', {'Title': channel['title'].replace('CALM RADIO -', '').title(),
                             'Artist': channel['description']})
        li.setProperty('mimetype', 'audio/mpeg')
        li.setProperty('IsPlayable', 'true')
        li.setInfo('music', {
            'Title': channel['title'].replace('CALM RADIO -', '').title()
        })
        Player().play(item=url, listitem=li)

        log('Playing url: {0}'.format(url))
        update_artwork(channel, recent_tracks_url)
    else:
        # members only access
        dialog = Dialog()
        ret = dialog.yesno(ADDON.getLocalizedString(32200), ADDON.getLocalizedString(32201))
        if ret == 1:
            ADDON.openSettings()
开发者ID:gedisony,项目名称:repo-plugins,代码行数:48,代码来源:addon.py

示例8: remove_from_favorites

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import authenticate [as 别名]
def remove_from_favorites(channel_id):
    """
    Removes a channels from user's favorites list
    :param channel_id: Channel ID
    :return:
    """
    api = API()
    user = User()
    is_authenticated = user.authenticate()
    if is_authenticated:
        result = api.remove_from_favorites(user.username, user.token, channel_id)
        executebuiltin('Container.Refresh')
        executebuiltin('Notification("{0}", "{1}")'.format(
                ADDON.getLocalizedString(30000),
                ADDON.getLocalizedString(32303) if result else ADDON.getLocalizedString(32305)
        ))
    else:
        executebuiltin('Notification("{0}", "{1}")'.format(
                ADDON.getLocalizedString(30000),
                ADDON.getLocalizedString(32110)
        ))
开发者ID:gedisony,项目名称:repo-plugins,代码行数:23,代码来源:addon.py


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