コード例 #1
0
    def create(self, validated_data):
        created_by = validated_data.get('created_by')
        random_password = ''.join(
            random.SystemRandom().choice(string.ascii_uppercase +
                                         string.digits) for _ in range(8))
        email = validated_data.pop('email')

        #create user
        password = validated_data.pop('password')

        user = User.objects.create_user(email=email,
                                        password=password,
                                        **validated_data)

        if created_by:
            password = random_password
            #send email here . default gateway is gmail
            email_message = "Welcome %s . Please use %s as your password. Make sure you change it later. " % (
                user.first_name, password)
            Message.create_email(message=email_message,
                                 recipient_address=user.email,
                                 subject="Registration")
            user.set_password(password)
        else:
            user.is_password_changed = True  #creted by himself. doenot need to change password on login

        user.save()
        return user
コード例 #2
0
 def send_email(self, message, recipient, template_id=None, subject=None):
     return Message.create_email(message=message,
                                 recipient_address=recipient,
                                 template_id=template_id,
                                 subject=subject)