コード例 #1
0
ファイル: __init__.py プロジェクト: Ratler/eduid-dashboard
 def _verify_action(self, data_id, post_data):
     if 'code' in post_data:
         code_sent = post_data['code']
         verification_code = get_verification_code(self.request,
                                                   self.data_attribute,
                                                   obj_id=data_id,
                                                   user=self.user)
         if verification_code:
             if code_sent == verification_code['code']:
                 if verification_code['expired']:
                     log.debug("User {!r} verification code has expired".format(self.user))
                     return {
                         'result': 'error',
                         'message': self.verify_messages['expired'],
                     }
                 else:
                     verificate_code(self.request, self.data_attribute,
                                     code_sent)
                     return {
                         'result': 'ok',
                         'message': self.verify_messages['ok'],
                     }
             else:
                 log.debug("Incorrect code for user {!r}: {!r}".format(self.user, code_sent))
         return {
             'result': 'error',
             'message': self.verify_messages['error'],
         }
     else:
         message = self.verify_messages['request'].format(data=data_id)
         return {
             'result': 'getcode',
             'message': message,
             'placeholder': self.verify_messages['placeholder'],
         }
コード例 #2
0
def verifications(context, request):
    model_name = request.matchdict['model']
    code = request.matchdict['code']

    verification = get_verification_code(request, model_name, code=code)
    if verification and verification['expired']:
        log.debug("Verification code is expired: {!r}".format(verification))
        raise HTTPNotFound()  # the code is expired

    if code not in request.session.get('verifications', []):
        log.debug("Code {!r} not found in active sessions verifications: {!r}".format(
            code, request.session.get('verifications', [])))
        raise HTTPNotFound(_("Can't locate the code in the active session"))
    try:
        obj_id = verify_code(request, model_name, code)
    except UserOutOfSync:
        msg = _('Your user profile is out of sync. Please '
                'reload the page and try again.')
        msg = get_localizer(request).translate(msg)
        request.session.flash(msg),
        raise HTTPFound(request.context.route_url('profile-editor'))

    if obj_id is not None:
        request.stats.count('verification_{!s}_ok'.format(model_name))
        return HTTPFound(location=request.route_url('home'))
    else:
        log.debug("Incorrect verification code {!r} for model {!r}".format(code, model_name))
        request.stats.count('verification_{!s}_fail'.format(model_name))
        raise HTTPNotFound()
コード例 #3
0
def verifications(context, request):
    model_name = request.matchdict['model']
    code = request.matchdict['code']

    verification = get_verification_code(request, model_name, code=code)
    if verification and verification['expired']:
        log.debug("Verification code is expired: {!r}".format(verification))
        raise HTTPNotFound()  # the code is expired

    if code not in request.session.get('verifications', []):
        log.debug("Code {!r} not found in active sessions verifications: {!r}".
                  format(code, request.session.get('verifications', [])))
        raise HTTPNotFound(_("Can't locate the code in the active session"))
    try:
        obj_id = verify_code(request, model_name, code)
    except UserOutOfSync:
        msg = _('Your user profile is out of sync. Please '
                'reload the page and try again.')
        msg = get_localizer(request).translate(msg)
        request.session.flash(msg),
        raise HTTPFound(request.context.route_url('profile-editor'))

    if obj_id is not None:
        request.stats.count('verification_{!s}_ok'.format(model_name))
        return HTTPFound(location=request.route_url('home'))
    else:
        log.debug("Incorrect verification code {!r} for model {!r}".format(
            code, model_name))
        request.stats.count('verification_{!s}_fail'.format(model_name))
        raise HTTPNotFound()
コード例 #4
0
 def _verify_action(self, data_id, post_data):
     if 'code' in post_data:
         code_sent = post_data['code']
         verification_code = get_verification_code(self.request,
                                                   self.data_attribute,
                                                   obj_id=data_id,
                                                   code=code_sent,
                                                   user=self.user)
         if verification_code:
             if code_sent == verification_code['code']:
                 if verification_code['expired']:
                     log.debug(
                         "User {!r} verification code has expired".format(
                             self.user))
                     return {
                         'result': 'error',
                         'message': self.verify_messages['expired'],
                     }
                 else:
                     try:
                         verify_code(self.request, self.data_attribute,
                                     code_sent)
                     except UserOutOfSync:
                         self.sync_user()
                         return {
                             'result': 'out_of_sync',
                             'message': self.verify_messages['out_of_sync'],
                         }
                 return {
                     'result': 'success',
                     'message': self.verify_messages['success'],
                 }
             else:
                 log.debug("Incorrect code for user {!r}: {!r}".format(
                     self.user, code_sent))
         return {
             'result': 'error',
             'message': self.verify_messages['error'],
         }
     else:
         message = self.verify_messages['request'].format(data=data_id)
         return {
             'result': 'getcode',
             'message': message,
             'placeholder': self.verify_messages['placeholder'],
         }
コード例 #5
0
def verifications(context, request):
    model_name = request.matchdict['model']
    code = request.matchdict['code']

    verification = get_verification_code(request, model_name, code=code)
    if verification and verification['expired']:
        log.debug("Verification code is expired: {!r}".format(verification))
        raise HTTPNotFound()  # the code is expired

    if code not in request.session.get('verifications', []):
        log.debug("Code {!r} not found in active sessions verifications: {!r}".format(
            code, request.session.get('verifications', [])))
        raise HTTPNotFound(_("Can't locate the code in the active session"))

    obj_id = verificate_code(request, model_name, code)

    if obj_id is not None:
        return HTTPFound(location=request.route_url('home'))
    else:
        log.debug("Incorrect verification code")
        raise HTTPNotFound()