Example #1
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,
                                                   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'],
         }
Example #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"))

    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()