def get_org_bookmarks(self, **options):
     if options['recipient_email'] and (options['ccg']
                                        or options['practice']):
         dummy_user = User(email=options['recipient_email'], id='dummyid')
         dummy_user.profile = Profile(key='dummykey')
         bookmarks = [
             OrgBookmark(user=dummy_user,
                         pct_id=options['ccg'],
                         practice_id=options['practice'])
         ]
         logger.info("Created a single test org bookmark")
     elif options['recipient_email'] or options['recipient_email_file']:
         recipients = []
         if options['recipient_email_file']:
             with open(options['recipient_email_file'], 'r') as f:
                 recipients = [x.strip() for x in f]
         else:
             recipients = [options['recipient_email']]
         bookmarks = OrgBookmark.objects.filter(approved=True,
                                                user__is_active=True,
                                                user__email__in=recipients)
         logger.info("Found %s matching org bookmarks" % bookmarks.count())
     else:
         bookmarks = OrgBookmark.objects.filter(approved=True,
                                                user__is_active=True)
         if options['skip_email_file']:
             with open(options['skip_email_file'], 'r') as f:
                 skip = [x.strip() for x in f]
             bookmarks = bookmarks.exclude(user__email__in=skip)
         logger.info("Found %s matching org bookmarks" % bookmarks.count())
     return bookmarks
Example #2
0
def register(request):
    if (request.method == "POST"):
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        phone = request.POST.get('phone')
        street = request.POST.get('street')
        city = request.POST.get('city')
        postcode = request.POST.get('postcode')
        password = request.POST.get('password')
        email = request.POST.get('email')

        user = User(first_name=first_name,
                    last_name=last_name,
                    phone=phone,
                    street=street,
                    city=city,
                    postcode=postcode,
                    password=password,
                    email=email,
                    type="user")

        user.save()

        return render(request,
                      'website/account.html',
                      context={
                          'status': "",
                          'message': 'Account is created successfully'
                      })
    raise Http404
def make_dummy_bookmark(email_address):
    """Make a dummy bookmark with this email address for testing purposes"""
    dummy_user = User(email=email_address, id="dummyid")
    dummy_user.profile = Profile(key="dummykey")
    return OrgBookmark(user=dummy_user,
                       pct_id=None,
                       practice_id=None,
                       pcn_id=None)
Example #4
0
def preview_bookmark(request, practice=None, pct=None, url=None, name=None):
    user = User(email='*****@*****.**')
    user.profile = Profile()
    if pct or practice:
        context = bookmark_utils.InterestingMeasureFinder(
            practice=practice, pct=pct).context_for_org_email()
        bookmark = OrgBookmark(practice=practice, pct=pct, user=user)
        msg = bookmark_utils.make_org_email(bookmark, context)
    else:
        bookmark = SearchBookmark(url=url, user=user, name=name)
        msg = bookmark_utils.make_search_email(bookmark)
    html = msg.alternatives[0][0]
    images = msg.attachments
    return HttpResponse(_convert_images_to_data_uris(html, images))
 def get_search_bookmarks(self, **options):
     if options['recipient_email'] and options['url']:
         dummy_user = User(email=options['recipient_email'], id='dummyid')
         dummy_user.profile = Profile(key='dummykey')
         bookmarks = [
             SearchBookmark(user=dummy_user,
                            url=options['url'],
                            name=options['search_name'])
         ]
     elif not options['recipient_email']:
         bookmarks = SearchBookmark.objects.filter(approved=True,
                                                   user__is_active=True)
     else:
         bookmarks = []
     return bookmarks
 def get_search_bookmarks(self, **options):
     if options['recipient_email'] and options['url']:
         dummy_user = User(email=options['recipient_email'], id='dummyid')
         dummy_user.profile = Profile(key='dummykey')
         bookmarks = [SearchBookmark(
             user=dummy_user,
             url=options['url'],
             name=options['search_name']
         )]
     elif not options['recipient_email']:
         bookmarks = SearchBookmark.objects.filter(
             approved=True,
             user__is_active=True)
     else:
         bookmarks = []
     return bookmarks
def snap_login():
    if current_user.is_authenticated:
        return redirect(url_for('dash.dashboard'))

    name = request.args.get('display_name')
    snapPic = request.args.get('snap_pic')
    if name is not None and snapPic is not None:
        request_response = requests.post(current_app.config['ENDPOINT_ROUTE'] +
                                         current_app.config['LOGIN_URL'],
                                         json={
                                             'isSnap': True,
                                             'display_name': name,
                                             'snap_pic': "undefined"
                                         })
        response = request_response.json()
        if response['status'] == 1:
            user = User(response['id'], response['name'], response['email'],
                        response['auth_token'])
            db.session.add(user)
            db.session.commit()
            login_user(user, remember=True)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('dash.dashboard'))
        else:
            flash(response['error'], 'danger')
    return redirect(url_for('common.login'))
def login():
    if current_user.is_authenticated:
        return redirect(url_for('dash.dashboard'))
    form = LoginForm()
    if form.validate_on_submit():
        request_response = requests.post(current_app.config['ENDPOINT_ROUTE'] +
                                         current_app.config['LOGIN_URL'],
                                         json={
                                             'email': form.email.data,
                                             'password': form.password.data,
                                         })
        response = request_response.json()
        if response['status'] == 1:
            user = User(response['id'], response['name'], response['email'],
                        response['gt_id'], response['auth_token'])
            db.session.add(user)
            db.session.commit()
            print(
                User.query.filter_by(user_id=response['id']).order_by(
                    User.id.desc()).first().auth_token)
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            if response['isMaster']:
                return redirect(next_page) if next_page else redirect(
                    url_for('dash.admin_dashboard'))
            elif response['isAdmin']:
                return redirect(next_page) if next_page else redirect(
                    url_for('dash.dashboard'))
            else:
                return redirect(next_page) if next_page else redirect(
                    url_for('dash.dashboard'))
        else:
            print("Unsuccessful")
            flash(response['error'], 'danger')
    return render_template('login.html', title='Login', form=form)
def preview_bookmark(request, practice=None, pct=None, url=None, name=None):
    user = User(email='*****@*****.**')
    user.profile = Profile()
    if pct or practice:
        context = bookmark_utils.InterestingMeasureFinder(
            practice=practice,
            pct=pct
        ).context_for_org_email()
        bookmark = OrgBookmark(practice=practice, pct=pct, user=user)
        msg = bookmark_utils.make_org_email(
            bookmark, context)
    else:
        bookmark = SearchBookmark(url=url, user=user, name=name)
        msg = bookmark_utils.make_search_email(bookmark)
    html = msg.alternatives[0][0]
    images = msg.attachments
    return HttpResponse(_convert_images_to_data_uris(html, images))
    def get_org_bookmarks(self, now_month, **options):
        """Get all OrgBookmarks for active users who have not been sent a
        message tagged with `now_month`

        """
        query = (
            Q(user__is_active=True)
            & ~Q(user__emailmessage__tags__contains=["measures", now_month])
            &
            # Only include bookmarks for either a practice or pct or PCN: when all
            # are NULL this indicates an All England bookmark
            (Q(practice__isnull=False) | Q(pct__isnull=False)
             | Q(pcn__isnull=False)))
        if options["recipient_email"] and (options["ccg"]
                                           or options["practice"]
                                           or options["pcn"]):
            dummy_user = User(email=options["recipient_email"], id="dummyid")
            dummy_user.profile = Profile(key="dummykey")
            bookmarks = [
                OrgBookmark(
                    user=dummy_user,
                    pct_id=options["ccg"],
                    practice_id=options["practice"],
                    pcn_id=options["pcn"],
                )
            ]
            logger.info("Created a single test org bookmark")
        elif options["recipient_email"] or options["recipient_email_file"]:
            recipients = []
            if options["recipient_email_file"]:
                with open(options["recipient_email_file"], "r") as f:
                    recipients = [x.strip() for x in f]
            else:
                recipients = [options["recipient_email"]]
            query = query & Q(user__email__in=recipients)
            bookmarks = OrgBookmark.objects.filter(query)
            logger.info("Found %s matching org bookmarks" % bookmarks.count())
        else:
            bookmarks = OrgBookmark.objects.filter(query)
            if options["skip_email_file"]:
                with open(options["skip_email_file"], "r") as f:
                    skip = [x.strip() for x in f]
                bookmarks = bookmarks.exclude(user__email__in=skip)
            logger.info("Found %s matching org bookmarks" % bookmarks.count())
        return bookmarks
 def get_org_bookmarks(self, **options):
     if options['recipient_email'] and (options['ccg']
                                        or options['practice']):
         dummy_user = User(email=options['recipient_email'], id='dummyid')
         dummy_user.profile = Profile(key='dummykey')
         bookmarks = [
             OrgBookmark(user=dummy_user,
                         pct_id=options['ccg'],
                         practice_id=options['practice'])
         ]
     elif not options['recipient_email']:
         # Perhaps add a constraint here to ensure we don't send two
         # emails for one month?
         bookmarks = OrgBookmark.objects.filter(approved=True,
                                                user__is_active=True)
     else:
         bookmarks = []
     return bookmarks
 def get_org_bookmarks(self, **options):
     if options['recipient_email'] and (
             options['ccg'] or options['practice']):
         dummy_user = User(email=options['recipient_email'], id='dummyid')
         dummy_user.profile = Profile(key='dummykey')
         bookmarks = [OrgBookmark(
             user=dummy_user,
             pct_id=options['ccg'],
             practice_id=options['practice']
         )]
     elif not options['recipient_email']:
         # Perhaps add a constraint here to ensure we don't send two
         # emails for one month?
         bookmarks = OrgBookmark.objects.filter(
             approved=True,
             user__is_active=True)
     else:
         bookmarks = []
     return bookmarks
Example #13
0
    def get_org_bookmarks(self, now_month, **options):
        """Get approved OrgBookmarks for active users who have not been sent a
        message tagged with `now_month`

        """
        query = (
            Q(approved=True, user__is_active=True) &
            ~Q(user__emailmessage__tags__contains=['measures', now_month]) &
            # Only include bookmarks for either a practice or pct: when both
            # are NULL this indicates an All England bookmark
            (Q(practice__isnull=False) | Q(pct__isnull=False))
        )
        if options['recipient_email'] and (
                options['ccg'] or options['practice']):
            dummy_user = User(email=options['recipient_email'], id='dummyid')
            dummy_user.profile = Profile(key='dummykey')
            bookmarks = [OrgBookmark(
                user=dummy_user,
                pct_id=options['ccg'],
                practice_id=options['practice']
            )]
            logger.info("Created a single test org bookmark")
        elif options['recipient_email'] or options['recipient_email_file']:
            recipients = []
            if options['recipient_email_file']:
                with open(options['recipient_email_file'], 'r') as f:
                    recipients = [x.strip() for x in f]
            else:
                recipients = [options['recipient_email']]
            query = query & Q(user__email__in=recipients)
            bookmarks = OrgBookmark.objects.filter(query)
            logger.info("Found %s matching org bookmarks" % bookmarks.count())
        else:
            bookmarks = OrgBookmark.objects.filter(query)
            if options['skip_email_file']:
                with open(options['skip_email_file'], 'r') as f:
                    skip = [x.strip() for x in f]
                bookmarks = bookmarks.exclude(user__email__in=skip)
            logger.info("Found %s matching org bookmarks" % bookmarks.count())
        return bookmarks
 def get_search_bookmarks(self, now_month, **options):
     query = Q(approved=True, user__is_active=True) & ~Q(
         user__emailmessage__tags__contains=["analyse", now_month])
     if options["recipient_email"] and options["url"]:
         dummy_user = User(email=options["recipient_email"], id="dummyid")
         dummy_user.profile = Profile(key="dummykey")
         bookmarks = [
             SearchBookmark(user=dummy_user,
                            url=options["url"],
                            name=options["search_name"])
         ]
         logger.info("Created a single test search bookmark")
     elif not options["recipient_email"]:
         bookmarks = SearchBookmark.objects.filter(query)
         logger.info("Found %s matching search bookmarks" %
                     bookmarks.count())
     else:
         query = query & Q(user__email=options["recipient_email"])
         bookmarks = SearchBookmark.objects.filter(query)
         logger.info("Found %s matching search bookmarks" %
                     bookmarks.count())
     return bookmarks
 def get_search_bookmarks(self, **options):
     if options['recipient_email'] and options['url']:
         dummy_user = User(email=options['recipient_email'], id='dummyid')
         dummy_user.profile = Profile(key='dummykey')
         bookmarks = [
             SearchBookmark(user=dummy_user,
                            url=options['url'],
                            name=options['search_name'])
         ]
         logger.info("Created a single test search bookmark")
     elif not options['recipient_email']:
         bookmarks = SearchBookmark.objects.filter(approved=True,
                                                   user__is_active=True)
         logger.info("Found %s matching search bookmarks" %
                     bookmarks.count())
     else:
         bookmarks = SearchBookmark.objects.filter(
             approved=True,
             user__is_active=True,
             user__email=options['recipient_email'])
         logger.info("Found %s matching search bookmarks" %
                     bookmarks.count())
     return bookmarks
Example #16
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = registrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Your account has been created!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Example #17
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("project"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash("Your account has been created! You are now able to login!",
              "success")
        return redirect(url_for("login"))
    return render_template("register.html", title="Register", form=form)
Example #18
0
def register(request):
    """
    user register api
    :param request:
    :return:
    """
    data = request.data
    mobile = data["mobile"]
    code = data["verify_code"]
    password = data["password"]
    #
    # sms_code = SmsCode.objects.filter(code=code).first()
    #
    # expired_date = sms_code.expired_date
    now = datetime.datetime.now()
    # # delta = datetime.timedelta(minutes=5)
    # if sms_code.verified > 0 or expired_date < now:

    res = SmsCode.objects.filter(code=code,
                                 mobile=mobile,
                                 expired_date__lt=now).update(verified=1)

    if res == 0:
        return Response(
            json.dumps(
                Result(status=common.SMS_CODE_EXPIRED,
                       error="code has been expired")))

    user = User()
    user.user_id = gen_user_id(mobile)
    user.mobile = mobile
    user.password = encode_passwd(mobile, user.user_id, password)
    # datetime.datetime.now().date()
    user.birthday = datetime.datetime.now().date()
    user.created_at = datetime.datetime.now()
    user.save()

    # User.objects
    return Response({})
Example #19
0
def make_dummy_bookmark(email_address):
    '''Make a dummy bookmark with this email address for testing purposes'''
    dummy_user = User(email=email_address, id='dummyid')
    dummy_user.profile = Profile(key='dummykey')
    return OrgBookmark(user=dummy_user, pct_id=None, practice_id=None)