from dddp.api import API, Collection, Publication from JON import models class Program(Collection): model = models.Program class Project(Collection): model = models.Project class Programs(Publication): queries = [ models.Program.objects.all(), ] class Projects(Publication): queries = [ models.Project.objects.all(), ] API.register([ Program, Project, Programs, Projects, ])
from __future__ import absolute_import, unicode_literals from dddp.api import API, Collection, Publication from django_ddp_app import models class Notification(Collection): model = models.Notification class Notifications(Publication): queries = [ models.Notification.objects.all().reverse(), ] API.register([ Notification, Notifications, ]);
from __future__ import absolute_import, unicode_literals from dddp.api import API, Collection, Publication from django_todos import models class Task(Collection): model = models.Task class Tasks(Publication): queries = [ models.Task.objects.all(), ] API.register([ Task, Tasks, ])
days_valid = HASH_DAYS_VALID[HashPurpose.PASSWORD_RESET] token = get_user_token( user=user, purpose=HashPurpose.PASSWORD_RESET, days_valid=days_valid, ) forgot_password.send( sender=__name__, user=user, token=token, request=this.request, expiry_date=calc_expiry_time(days_valid), ) @api_endpoint('resetPassword') def reset_password(self, token, new_password): """Reset password using a token received in email then logs user in.""" user = self.validated_user( token, purpose=HashPurpose.PASSWORD_RESET, days_valid=HASH_DAYS_VALID[HashPurpose.PASSWORD_RESET], ) user.set_password(new_password) user.save() self.do_login(user) return {"userId": this.user_ddp_id} API.register([Users, LoginServiceConfiguration, LoggedInUser, Auth])
from dddp import THREAD_LOCAL as this from dddp.api import API, Publication from dddp.logging import LOGS_NAME from django.contrib import auth class Logs(Publication): name = LOGS_NAME users = auth.get_user_model() def get_queries(self): user_pk = getattr(this, 'user_id', False) if user_pk: if self.users.objects.filter( pk=user_pk, is_active=True, is_superuser=True, ).exists(): return [] raise ValueError('User not permitted.') API.register([Logs])
from dddp.api import API, Publication from dddp.logging import LOGS_NAME class ClientVersions(Publication): """Publication for `meteor_autoupdate_clientVersions`.""" name = 'meteor_autoupdate_clientVersions' queries = [] class Logs(Publication): name = LOGS_NAME users = auth.get_user_model() def get_queries(self): user_pk = getattr(THREAD_LOCAL, 'user_id', False) if user_pk: if self.users.objects.filter( pk=user_pk, is_active=True, is_superuser=True, ).exists(): return [] raise ValueError('User not permitted.') API.register([ClientVersions, Logs])
from dddp import THREAD_LOCAL as this from dddp.api import API, Publication from django.contrib import auth class Logs(Publication): users = auth.get_user_model() def get_queries(self): user_pk = getattr(this, "user_id", False) if user_pk: if self.users.objects.filter(pk=user_pk, is_active=True, is_superuser=True).exists(): return [] raise ValueError("User not permitted.") API.register([Logs])
from __future__ import absolute_import, unicode_literals from dddp.api import API, Collection, Publication from django_todos import models class Task(Collection): model = models.Task class Tasks(Publication): queries = [ models.Task.objects.all(), ] API.register([ Task, Tasks, ])
self.auth_failed() minutes_valid = HASH_MINUTES_VALID[HashPurpose.PASSWORD_RESET] token = get_user_token( user=user, purpose=HashPurpose.PASSWORD_RESET, minutes_valid=minutes_valid, ) forgot_password.send( sender=__name__, user=user, token=token, request=this.request, expiry_date=calc_expiry_time(minutes_valid), ) @api_endpoint('resetPassword') def reset_password(self, token, new_password): """Reset password using a token received in email then logs user in.""" user = self.validated_user( token, purpose=HashPurpose.PASSWORD_RESET, minutes_valid=HASH_MINUTES_VALID[HashPurpose.PASSWORD_RESET], ) user.set_password(new_password) user.save() self.do_login(user) return {"userId": this.user_ddp_id} API.register([Users, LoginServiceConfiguration, LoggedInUser, Auth])
from dddp.api import API, Publication from dddp.logging import LOGS_NAME class ClientVersions(Publication): """Publication for `meteor_autoupdate_clientVersions`.""" name = 'meteor_autoupdate_clientVersions' queries = [] class Logs(Publication): name = LOGS_NAME users = auth.get_user_model() def get_queries(self): user_pk = getattr(THREAD_LOCAL, 'user_id', False) if user_pk: if self.users.objects.filter( pk=user_pk, is_active=True, is_superuser=True, ).exists(): return [] raise ValueError('User not permitted.') API.register([ClientVersions, Logs])
@api_endpoint('remove') def remove(self, params): obj = models.Todos.objects.get(aid=params['_id']) obj.delete() class publicLists(Publication): queries = [ models.List.objects.all(), ] class privateLists(Publication): queries = [] class todos(Publication): def get_queries(self, listId): return [ models.Todos.objects.filter(listId=listId) ] API.register([ Lists, Todos, publicLists, privateLists, todos, ])
from dddp.api import API,DDP, Collection, Publication from .models import Task1 class TaskCollection(Collection): model = Task1 class TaskPub(Publication): queries = [ Task1.objects.all(), ] API.register([ TaskCollection, TaskPub, ])
'room__participant__user', ] class Message(Collection): model = chat.Message user_rel = [ 'room__participant__user', ] class PublicRooms(Publication): queries = [ chat.Room.objects.filter(public=True), ] class RoomRelated(Publication): @staticmethod def get_queries(room_slug): yield chat.Room.objects.filter(slug=room_slug) yield auth.User.objects.filter(participant__room__slug=room_slug) yield chat.Participant.objects.filter(room__slug=room_slug) yield chat.Message.objects.filter(room__slug=room_slug) API.register([ Room, User, Participant, Message, PublicRooms, RoomRelated, ])
expiry_date = this.request.session.get_expiry_date() token = self.get_user_token( user=user, session_key=this.request.session.session_key, expiry_date=expiry_date, purpose=HashPurpose.PASSWORD_RESET, ) forgot_password.send( sender=__name__, user=user, token=token, request=this.request, expiry_date=expiry_date, ) @api_endpoint('resetPassword') def reset_password(self, token, new_password): """Reset password using a token received in email then logs user in.""" user, _ = self.validated_user_and_session( token, purpose=HashPurpose.PASSWORD_RESET, ) user.set_password(new_password) user.save() auth.login(this.request, user) self.update_subs(user.pk) return {"userId": get_meteor_id(this.request.user)}; API.register([Users, LoginPublication, Auth])