예제 #1
0
    def __call__(self, node, value):

        request = node.bindings.get('request')
        user = request.context.user
        user_mobiles = [m['mobile'] for m in user.get_mobiles()]
        mobile = {'mobile': value}
        convert_to_e_164(request, mobile)

        if 'add' in request.POST:
            if mobile['mobile'] in user_mobiles:
                raise colander.Invalid(node,
                                       _("This mobile phone was already registered"))
예제 #2
0
    def add_success(self, mobileform):
        mobile = self.schema.serialize(mobileform)
        convert_to_e_164(self.request, mobile)
        mobile_number = mobile['mobile']
        mobile['verified'] = False
        mobile['primary'] = False

        self.user.add_mobile(mobile)
        self.user.save(self.request)

        send_verification_code(self.request, self.user, mobile_number)

        self.request.session.flash(_('Changes saved'),
                                   queue='forms')
        msg = _('A confirmation code has been sent to your mobile phone. '
                'Please click on the "Pending confirmation" link below and enter your confirmation code.')
        msg = get_localizer(self.request).translate(msg)
        self.request.session.flash(msg,
                                   queue='forms')