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