def register(self, request, **kwargs): username, password, phone = kwargs['username'], kwargs['password1'], kwargs['mobile_number'] if Site._meta.installed: site = Site.objects.get_current() else: site = RequestSite(request) new_user = RegistrationProfile.objects.create_inactive_user(username=username, email='', password=password, site=site, send_email=False) profile, created = ApplicantProfile.objects.get_or_create(user=new_user) profile.mobile_number = phone profile.save() self.setup_default_data(new_user, profile) signals.user_registered.send(sender=self.__class__, user=new_user, request=request) # Send a confirmation text to the applicant's phone # so we can confirm that it is a real phone number # TODO: Move this to somewhere else so it can be # triggered by the user_registered signal above # (Otherwise, we block until the SMS request is # send to Twilio.) sms = SMS.send(applicant=profile, phone_number=profile.mobile_number, message='Welcome to txt2wrk! To verify your phone number, reply with "OK". If you did not sign up with txt2wrk, reply with "STOP" to be removed from our system.', message_type=REQ_NUMBER_CONFIRMATION) return new_user
def receive_sms(request, template=None, form_class=ReceiveSMSForm): if request.method == 'POST': fields = request.POST else: fields = request.GET form = form_class(fields) context = {} if form.is_valid(): profile = None try: profile = ApplicantProfile.objects.get(mobile_number=form.cleaned_data['From']) except ApplicantProfile.DoesNotExist: pass message = form.cleaned_data['Body'] response, message_type = SMS.get_message_type(message, profile) context['response'] = response sms = SMS(applicant=profile, sent_by_us=False, message=form.cleaned_data['Body'], sms_sid=form.cleaned_data['SmsSid'], phone_number=form.cleaned_data['From'], message_type=message_type) sms.save() if profile is not None: if message_type == RES_NUMBER_CONFIRMATION: profile.confirmed_phone = True profile.save() if message_type == RES_UNSUBSCRIBE: profile.confirmed_phone = False profile.save() additional_context, template = handle_ack(response, message_type, profile) context.update(additional_context) return render_to_response(template, context, context_instance=RequestContext(request))
def sms_add(): mobiles = ['709394', '178902'] sms = SMS(date_send=arrow.now().datetime, mobiles=json.dumps(mobiles), content=u'死肥仔', returned_value=0, user_id=3) db.session.add(sms) db.session.commit() print sms.id
def register(self, request, **kwargs): """ Given a username, email address and password, register a new user account, which will initially be inactive. Along with the new ``User`` object, a new ``registration.models.RegistrationProfile`` will be created, tied to that ``User``, containing the activation key which will be used for this account. An email will be sent to the supplied email address; this email should contain an activation link. The email will be rendered using two templates. See the documentation for ``RegistrationProfile.send_activation_email()`` for information about these templates and the contexts provided to them. After the ``User`` and ``RegistrationProfile`` are created and the activation email is sent, the signal ``registration.signals.user_registered`` will be sent, with the new ``User`` as the keyword argument ``user`` and the class of this backend as the sender. """ username, email, password, phone = kwargs['username'], kwargs['email'], kwargs['password1'], kwargs['mobile_number'] first_name, last_name = kwargs['first_name'], kwargs['last_name'] new_user = User.objects.create_user(username, email, password) new_user.first_name = first_name new_user.last_name = last_name new_user.save() profile, created = ApplicantProfile.objects.get_or_create(user=new_user) profile.mobile_number = phone profile.save() auth_user = authenticate(username=phone, password=password) login(request, auth_user) signals.user_registered.send(sender=self.__class__, user=auth_user, request=request) # Send a confirmation text to the applicant's phone # so we can confirm that it is a real phone number # TODO: Move this to somewhere else so it can be # triggered by the user_registered signal above # (Otherwise, we block until the SMS request is # send to Twilio.) sms = SMS.send(applicant=profile, phone_number=profile.mobile_number, message='Welcome to txt2wrk! To verify your phone number, reply with "OK". If you did not sign up with txt2wrk, reply with "STOP" to be removed from our system.', message_type=REQ_NUMBER_CONFIRMATION) return auth_user