def save(self, profile_callback=None): username = self.cleaned_data['username'] new_password = self.cleaned_data.get('new_password', None) old_password = self.cleaned_data.get('old_password', None) email = self.cleaned_data.get('email', None) custom_css = self.cleaned_data.get('custom_css', None) custom_js = self.cleaned_data.get('custom_js', None) if username and self.user.username != username: change_password(self.user, self.user.username, username) self.user.username = username self.user.save() social_profile = MSocialProfile.get_user(self.user.pk) social_profile.username = username social_profile.save() if self.user.email != email: self.user.email = email self.user.save() if old_password or new_password: change_password(self.user, old_password, new_password) MCustomStyling.save_user(self.user.pk, custom_css, custom_js)
def save(self, profile_callback=None): username = self.cleaned_data['username'] new_password = self.cleaned_data.get('new_password', None) old_password = self.cleaned_data.get('old_password', None) email = self.cleaned_data.get('email', None) custom_css = self.cleaned_data.get('custom_css', None) custom_js = self.cleaned_data.get('custom_js', None) if username and self.user.username != username: change_password(self.user, self.user.username, username) self.user.username = username self.user.save() social_profile = MSocialProfile.get_user(self.user.pk) social_profile.username = username social_profile.save() if self.user.email != email: self.user.email = email self.user.save() sp = MSocialProfile.get_user(self.user.pk) sp.email = email sp.save() if old_password or new_password: change_password(self.user, old_password, new_password) MCustomStyling.save_user(self.user.pk, custom_css, custom_js)
def clean(self): username = self.cleaned_data.get("username", "") new_password = self.cleaned_data.get("new_password", "") old_password = self.cleaned_data.get("old_password", "") email = self.cleaned_data.get("email", None) if username and self.user.username != username: try: User.objects.get(username__iexact=username) except User.DoesNotExist: pass else: raise forms.ValidationError("This username is already taken. Try something different.") if self.user.email != email: if email and User.objects.filter(email__iexact=email).count(): raise forms.ValidationError( "This email is already being used by another account. Try something different." ) if old_password or new_password: code = change_password(self.user, old_password, new_password, only_check=True) if code <= 0: raise forms.ValidationError("Your old password is incorrect.") return self.cleaned_data
def set_account_settings(request): code = 1 message = '' settings = request.POST if settings['username'] and request.user.username != settings['username']: try: User.objects.get(username__iexact=settings['username']) except User.DoesNotExist: request.user.username = settings['username'] request.user.save() else: code = -1 message = "This username is already taken. Try something different." if request.user.email != settings['email']: if not User.objects.filter(email=settings['email']).count(): request.user.email = settings['email'] request.user.save() else: code = -2 message = "This email is already being used by another account. Try something different." if code != -1 and (settings['old_password'] or settings['new_password']): code = change_password(request.user, settings['old_password'], settings['new_password']) if code == -3: message = "Your old password is incorrect." payload = { "username": request.user.username, "email": request.user.email, } return dict(code=code, message=message, payload=payload)
def set_preference(request): code = 1 message = '' new_preferences = request.POST preferences = json.decode(request.user.profile.preferences) for preference_name, preference_value in new_preferences.items(): if preference_name in SINGLE_FIELD_PREFS: setattr(request.user.profile, preference_name, preference_value) elif preference_name in SPECIAL_PREFERENCES: if (preference_name == 'old_password' and (new_preferences['old_password'] or new_preferences['new_password'])): code = change_password(request.user, new_preferences['old_password'], new_preferences['new_password']) if code == -1: message = "Your old password is incorrect." else: if preference_value in ["true", "false"]: preference_value = True if preference_value == "true" else False preferences[preference_name] = preference_value request.user.profile.preferences = json.encode(preferences) request.user.profile.save() response = dict(code=code, message=message, new_preferences=new_preferences) return response
def clean(self): username = self.cleaned_data.get('username', '') new_password = self.cleaned_data.get('new_password', '') old_password = self.cleaned_data.get('old_password', '') email = self.cleaned_data.get('email', None) if username and self.user.username != username: try: User.objects.get(username__iexact=username) except User.DoesNotExist: pass else: raise forms.ValidationError("此用户名已被使用,请尝试其他用户名。") if self.user.email != email: if email and User.objects.filter(email__iexact=email).count(): raise forms.ValidationError("此邮件地址已被其他帐户使用,请尝试其他邮件地址。") if old_password or new_password: code = change_password(self.user, old_password, new_password, only_check=True) if code <= 0: raise forms.ValidationError("你的旧密码不正确。") return self.cleaned_data
def clean(self): username = self.cleaned_data.get('username', '') new_password = self.cleaned_data.get('new_password', '') old_password = self.cleaned_data.get('old_password', '') email = self.cleaned_data.get('email', None) if username and self.user.username != username: try: User.objects.get(username__iexact=username) except User.DoesNotExist: pass else: raise forms.ValidationError( "This username is already taken. Try something different.") if self.user.email != email: if email and User.objects.filter(email__iexact=email).count(): raise forms.ValidationError( "This email is already being used by another account. Try something different." ) if old_password or new_password: code = change_password(self.user, old_password, new_password, only_check=True) if code <= 0: raise forms.ValidationError("Your old password is incorrect.") return self.cleaned_data
def save(self, profile_callback=None): username = self.cleaned_data["username"] new_password = self.cleaned_data.get("new_password", None) old_password = self.cleaned_data.get("old_password", None) email = self.cleaned_data.get("email", None) if username and self.user.username != username: change_password(self.user, self.user.username, username) self.user.username = username self.user.save() social_profile = MSocialProfile.get_user(self.user.pk) social_profile.username = username social_profile.save() if self.user.email != email: self.user.email = email self.user.save() if old_password or new_password: change_password(self.user, old_password, new_password)
def set_account_settings(request): code = 1 message = "" post_settings = request.POST if post_settings["username"] and request.user.username != post_settings["username"]: try: User.objects.get(username__iexact=post_settings["username"]) except User.DoesNotExist: request.user.username = post_settings["username"] request.user.save() social_profile = MSocialProfile.get_user(request.user.pk) social_profile.username = post_settings["username"] social_profile.save() else: code = -1 message = "This username is already taken. Try something different." if request.user.email != post_settings["email"]: if not post_settings["email"] or not User.objects.filter(email=post_settings["email"]).count(): request.user.email = post_settings["email"] request.user.save() else: code = -2 message = "This email is already being used by another account. Try something different." if code != -1 and (post_settings["old_password"] or post_settings["new_password"]): code = change_password(request.user, post_settings["old_password"], post_settings["new_password"]) if code == -3: message = "Your old password is incorrect." payload = { "username": request.user.username, "email": request.user.email, "social_profile": MSocialProfile.profile(request.user.pk), } return dict(code=code, message=message, payload=payload)