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 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)
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