def update_fb_follows(self, fb_ids, send_notifications=True): accounts = User.objects.filter(facebook_id__in = fb_ids) for acc in accounts: uuf, created = UserToUserFollow.objects.get_or_create(followed = acc, follower = self) if created: uuf.is_following = True uuf.save() cache.bust_on_handle(acc, acc.username) if acc.enable_followed_notification and send_notifications: from mailer.notification_tasks import send_notification, EmailTypes send_notification(type=EmailTypes.FOLLOW, user=acc, entity=self)
def update_fb_follows(self, fb_ids, send_notifications=True): accounts = User.objects.filter(facebook_id__in=fb_ids) for acc in accounts: uuf, created = UserToUserFollow.objects.get_or_create( followed=acc, follower=self) if created: uuf.is_following = True uuf.save() cache.bust_on_handle(acc, acc.username) if acc.enable_followed_notification and send_notifications: from mailer.notification_tasks import send_notification, EmailTypes send_notification(type=EmailTypes.FOLLOW, user=acc, entity=self)
def follow(request, user_id): followed = get_object_or_404(User, pk=user_id) follow_instance, created = UserToUserFollow.objects.get_or_create(follower=request.user, followed=followed) if not follow_instance.is_following: follow_instance.is_following = True follow_instance.save() if created: send_notification(type=EmailTypes.FOLLOW, user=followed, entity=request.user) cache.bust(followed) if request.is_ajax(): button = render_inclusiontag(request, "follow_button followed", "users_tags", {'followed': followed}) return json_response({'button': button}) else: return redirect(followed)
def forgot_password(request): email = request.POST['email'].strip() try: u = User.objects.get(email = email, is_active=True) except: return json_error(INVALID_EMAIL_ERROR, 'No user at that email address.') pr = PasswordResetRequest() pr.user = u pr.uid = str(uuid4().hex) pr.save() p = PasswordResetRequest.objects.all() send_notification(type=EmailTypes.RESET_PASSWORD, user=u, entity=u, password_reset_id=pr.uid) return json_response({'response' : 1})
def forgot_password(request): email = request.POST['email'].strip() try: u = User.objects.get(email=email, is_active=True) except: return json_error(INVALID_EMAIL_ERROR, 'No user at that email address.') pr = PasswordResetRequest() pr.user = u pr.uid = str(uuid4().hex) pr.save() p = PasswordResetRequest.objects.all() send_notification(type=EmailTypes.RESET_PASSWORD, user=u, entity=u, password_reset_id=pr.uid) return json_response({'response': 1})
def follow(request, user_id): followed = get_object_or_404(User, pk=user_id) follow_instance, created = UserToUserFollow.objects.get_or_create( follower=request.user, followed=followed) if not follow_instance.is_following: follow_instance.is_following = True follow_instance.save() if created: send_notification(type=EmailTypes.FOLLOW, user=followed, entity=request.user) cache.bust(followed) if request.is_ajax(): button = render_inclusiontag(request, "follow_button followed", "users_tags", {'followed': followed}) return json_response({'button': button}) else: return redirect(followed)
def forgot_password(request): error = None if request.method == 'POST': if 'email' in request.POST: try: u = User.objects.get(email=request.POST['email'].strip(), is_active=True) pr = PasswordResetRequest() pr.user = u pr.uid = str(uuid4().hex) pr.save() send_notification(type=EmailTypes.RESET_PASSWORD, user=u, entity=u, password_reset_id=pr.uid) return render(request, 'user/forgot_password_confirm.html', {}) except User.DoesNotExist: error = "Sorry, this user account does not exist." except Exception: logging.exception("Error In Forgot Password Post") error = "Sorry, an unknown error has occurred." return render(request, 'user/forgot_password.html', {'error': error})
def forgot_password(request): error = None if request.method == 'POST': if 'email' in request.POST: try: u = User.objects.get(email = request.POST['email'].strip(), is_active=True) pr = PasswordResetRequest() pr.user = u pr.uid = str(uuid4().hex) pr.save() send_notification(type=EmailTypes.RESET_PASSWORD, user=u, entity=u, password_reset_id=pr.uid) return render(request, 'user/forgot_password_confirm.html', {}) except User.DoesNotExist: error = "Sorry, this user account does not exist." except Exception: logging.exception("Error In Forgot Password Post") error = "Sorry, an unknown error has occurred." return render(request, 'user/forgot_password.html', { 'error' : error })
else: ent = User.objects.get(mongo_id=item) f, created = UserToUserFollow.objects.get_or_create( follower=request.user, followed=ent) if action == 'follow': f.is_following = True else: f.is_following = False f.stopped_following = datetime.now() f.save() request.user.refresh_users_following() ent.refresh_followers() if created: #FeedStream.post_new_follow(request.user, ent) send_notification(type=EmailTypes.FOLLOW, user=ent, entity=request.user) except Exception, inst: log(inst) if not ent: continue else: cache.bust(ent) return json_response({'result': 1}) @AccountRequired @PostOnly def remove_user(request):
ent = User.objects.get(id = item) else: ent = User.objects.get(mongo_id = item) f, created = UserToUserFollow.objects.get_or_create(follower = request.user, followed = ent) if action == 'follow': f.is_following = True else: f.is_following = False f.stopped_following = datetime.now() f.save() request.user.refresh_users_following() ent.refresh_followers() if created: #FeedStream.post_new_follow(request.user, ent) send_notification(type=EmailTypes.FOLLOW, user=ent, entity=request.user) except Exception, inst: log(inst) if not ent: continue else: cache.bust(ent) return json_response({'result' : 1}) @AccountRequired @PostOnly def remove_user(request): request.user.is_active = False