def get_user(self, *args, **kwargs): """Get user base on uidb64 :return: User """ uidb64 = kwargs.get('uidb64') uid = urlsafe_base64_decode(uidb64) return UserService.get_user(uid)
def edit(self, current, id, data): user = UserService.get_user(id) if not user: raise exceptions.NotFound() if permissions.allow_access_user(current, user=user): serializer = UserSerializer(instance=user, data=data) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data)
def validate(self, attrs): email = attrs.get('email') confirm_password = attrs.get('confirm_password') new_password = attrs.get('new_password') user_id = attrs.get('user_id') if (email or user_id) and confirm_password and new_password: if email: user = UserService.get_by_email(email) elif user_id: user = UserService.get_user(user_id) if user: user.set_password(new_password) user.save() attrs['user'] = user return attrs else: raise exceptions.ValidationError(_('User not found.')) else: raise exceptions.ValidationError(_('Must include password.'))
def get_user(self, id, **kwargs): user = UserService.get_user(id, **kwargs) if user is None: exceptions.NotFound() return user