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


Python User.get_by_activation方法代码示例

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


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

示例1: activate

# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import get_by_activation [as 别名]
    def activate(self):
        """
        Handle a request for a user activation link.

        Checks if the activation code passed is valid, and (as a safety check)
        that it is an activation for the passed user id. If all is well,
        activate the user and redirect them to the stream.
        """
        code = self.request.matchdict.get("code")
        id_ = self.request.matchdict.get("id")

        if code is None or id_ is None:
            return httpexceptions.HTTPNotFound()

        try:
            id_ = int(id_)
        except ValueError:
            return httpexceptions.HTTPNotFound()

        activation = Activation.get_by_code(code)
        if activation is None:
            return httpexceptions.HTTPNotFound()

        user = User.get_by_activation(activation)
        if user is None or user.id != id_:
            return httpexceptions.HTTPNotFound()

        # Activate the user (by deleting the activation)
        self.request.db.delete(activation)

        self.request.session.flash(_("Your e-mail address has been verified. " "Thank you!"), "success")
        self.request.registry.notify(ActivationEvent(self.request, user))

        return httpexceptions.HTTPFound(location=self.request.route_url("index"))
开发者ID:stuk88,项目名称:h,代码行数:36,代码来源:views.py

示例2: get_when_not_logged_in

# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import get_by_activation [as 别名]
    def get_when_not_logged_in(self):
        """
        Handle a request for a user activation link.

        Checks if the activation code passed is valid, and (as a safety check)
        that it is an activation for the passed user id. If all is well,
        activate the user and redirect them to the stream.
        """
        code = self.request.matchdict.get('code')
        id_ = self.request.matchdict.get('id')

        try:
            id_ = int(id_)
        except ValueError:
            raise httpexceptions.HTTPNotFound()

        activation = Activation.get_by_code(self.request.db, code)
        if activation is None:
            self.request.session.flash(jinja2.Markup(_(
                "We didn't recognize that activation link. "
                "Perhaps you've already activated your account? "
                'If so, try <a href="{url}">logging in</a> using the username '
                'and password that you provided.').format(
                    url=self.request.route_url('login'))),
                'error')
            return httpexceptions.HTTPFound(
                location=self.request.route_url('index'))

        user = User.get_by_activation(self.request.db, activation)
        if user is None or user.id != id_:
            raise httpexceptions.HTTPNotFound()

        user.activate()

        self.request.session.flash(jinja2.Markup(_(
            'Your account has been activated! '
            'You can now <a href="{url}">log in</a> using the password you '
            'provided.').format(url=self.request.route_url('login'))),
            'success')

        self.request.registry.notify(ActivationEvent(self.request, user))

        return httpexceptions.HTTPFound(
            location=self.request.route_url('index'))
开发者ID:pombredanne,项目名称:h,代码行数:46,代码来源:views.py

示例3: activate

# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import get_by_activation [as 别名]
    def activate(self):
        """
        Handle a request for a user activation link.

        Checks if the activation code passed is valid, and (as a safety check)
        that it is an activation for the passed user id. If all is well,
        activate the user and redirect them to the stream.
        """
        code = self.request.matchdict.get("code")
        id_ = self.request.matchdict.get("id")

        if code is None or id_ is None:
            return httpexceptions.HTTPNotFound()

        try:
            id_ = int(id_)
        except ValueError:
            return httpexceptions.HTTPNotFound()

        activation = Activation.get_by_code(code)
        if activation is None:
            return httpexceptions.HTTPNotFound()

        user = User.get_by_activation(activation)
        if user is None or user.id != id_:
            return httpexceptions.HTTPNotFound()

        # Activate the user (by deleting the activation)
        self.request.db.delete(activation)

        self.request.session.flash(
            jinja2.Markup(
                _(
                    "Your account has been activated! "
                    'You can now <a href="{url}">login</a> using the password you '
                    "provided."
                ).format(url=self.request.route_url("login"))
            ),
            "success",
        )
        self.request.registry.notify(ActivationEvent(self.request, user))

        return httpexceptions.HTTPFound(location=self.request.route_url("index"))
开发者ID:openbizgit,项目名称:h,代码行数:45,代码来源:views.py

示例4: reset_password

# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import get_by_activation [as 别名]
    def reset_password(self):
        """
        Handle submission of the reset password form.

        This function checks that the activation code (i.e. reset token)
        provided by the form is valid, retrieves the user associated with the
        activation code, and resets their password.
        """
        schema = schemas.ResetPasswordSchema().bind(request=self.request)
        form = deform.Form(schema)

        code = self.request.matchdict.get('code')
        if code is None:
            return httpexceptions.HTTPNotFound()

        activation = Activation.get_by_code(self.request, code)
        if activation is None:
            return httpexceptions.HTTPNotFound()

        user = User.get_by_activation(self.request, activation)
        if user is None:
            return httpexceptions.HTTPNotFound()

        if self.request.method != 'POST':
            return httpexceptions.HTTPMethodNotAllowed()

        err, appstruct = validate_form(form, self.request.POST.items())
        if err is not None:
            return err

        user.password = appstruct['password']
        db = get_session(self.request)
        db.delete(activation)

        self.request.session.flash(_('Your password has been reset!'),
                                   'success')
        self.request.registry.notify(PasswordResetEvent(self.request, user))

        return httpexceptions.HTTPFound(location=self.reset_password_redirect)
开发者ID:juli-so,项目名称:h,代码行数:41,代码来源:views.py


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