def create_invited_user(self, inviter_id, username, name, sex, email, password, site, send_email=False): """ add by cyb: Create a new, active ``User``, generate a ``Profile`` and email the register success information to ``User`` . Unlike function create_inactive_user, no activation email, only the success email will be sent. """ new_user = User.objects.create_user(username, email, password) new_user.is_active = True new_user.save() user_profile = Profile() user_profile.name = name user_profile.user_id = new_user.pk user_profile.sex = sex user_profile.is_active = True user_profile.invite_num = 10 user_profile.save() #Due to syncronization issue between database master and slave, return both to prevent inconsistency # in querying new_profile.user return_value ={} return_value['user_profile'] = user_profile return_value['new_user'] = new_user return return_value
def activate_user(self, activation_key): """ Validate an activation key and activate the corresponding ``User`` if valid. If the key is valid and has not expired, return the ``User`` after activating. If the key is not valid or has expired, return ``False``. If the key is valid but the ``User`` is already active, return ``False``. To prevent reactivation of an account which has been deactivated by site administrators, the activation key is reset to the string constant ``RegistrationProfile.ACTIVATED`` after successful activation. """ # Make sure the key we're trying conforms to the pattern of a # SHA1 hash; if it doesn't, no point trying to look it up in # the database. if SHA1_RE.search(activation_key): try: profile = self.get(activation_key=activation_key) except self.model.DoesNotExist: return False if not profile.activation_key_expired(): user = profile.user user.is_active = True user.save() profile.activation_key = self.model.ACTIVATED profile.save() user_profile = Profile(name=user.username) user_profile.user_id = user.pk user_profile.save() return user return False