예제 #1
0
 def alert_user():
     user_email = ''
     user_name = ''
     for user in sql_tables['users'].list(
         {'user_id': user_id}):
         user_email = user['email']
         user_name = user['name']
         break
     send_email(email_client, user_email, user_name)
예제 #2
0
파일: post.py 프로젝트: weicheny/rematch
 def disable_stale_posts():
     app.logger.info('Running stale post scheduler.')
     stale_posts, _, _ = Post.get_posts(active_only=True, stale=True)
     app.logger.info('Found stale posts: %s', stale_posts)
     for post in stale_posts:
         app.logger.info('Setting post %s to inactive.', post['id'])
         Post.update_post(post['id'], is_active=False)
         send_email(post['contact_email'],
                    'Your research listing has expired',
                    'Just to let you know!')
예제 #3
0
파일: auth.py 프로젝트: imfht/flaskapps
def email_reset_password():
    if not app.config['ENABLE_MAIL']:
        raise NotImplementedEndpoint()
    json_data = request.json
    email = json_data['email'].lower()
    user = User.query.filter_by(email=email).first_or_404()
    token = URLSafeTimedSerializer(app.config["SECRET_KEY"]).dumps(
        user.email, salt=RESET_PASSWORD_SALT)
    password_reset_url = url_for('home.reset_password',
                                 token=token,
                                 _external=True)

    message = render_template_string(FORGOT_PASSWORD,
                                     password_reset_url=password_reset_url)
    send_email(mail, [user.email], 'Reset your Gobo password', message)
    return jsonify({'statusText': 'Email sent'})
예제 #4
0
def email_scores(assignment_id, score_tags, subject, body,
                 reply_to=None, dry_run=False):
    log = jobs.get_job_logger()
    job_creator = jobs.get_current_job().user

    assign = Assignment.query.get(assignment_id)

    students = [e.user for e in (Enrollment.query
                        .options(db.joinedload('user'))
                        .filter(Enrollment.role == STUDENT_ROLE,
                                Enrollment.course == assign.course)
                        .all())]

    email_counter = 0
    seen_ids = set()
    for student in students:
        if student.id in seen_ids:
            continue
        user_ids = assign.active_user_ids(student.id)
        seen_ids |= user_ids
        scores = [s for s in assign.scores(user_ids) if s.kind in score_tags]
        if scores:
            users = User.query.filter(User.id.in_(user_ids))
            primary, cc = users[0].email, [u.email for u in users[1:]]
            if dry_run:
                primary, cc = job_creator.email, []

            result = send_email(primary,
                subject, body,
                cc=cc,
                template='email/scores.html',
                title=subject,
                from_name=assign.course.display_name,
                scores=scores,
                reply_to=reply_to,
                link_text="View on okpy.org",
                link="https://okpy.org/" + assign.name, # Don't have url_for
                assignment=assign.display_name)

            if result:
                log.info("Sent to {}".format(', '.join([primary] + cc)))
                email_counter += 1

        # Send a few emails in dry run mode.
        if dry_run and email_counter >= 2:
            message = "Run with dry run mode"
            log.info(message)
            return message

    message = "Sent {} emails".format(email_counter)
    log.info(message)
    return message
예제 #5
0
def group_respond(name):
    assignment = get_assignment(name)
    action = request.form.get('action')
    target = request.form.get('email')
    if not action or action not in ['accept', 'decline', 'revoke']:
        abort(400)
    group = Group.lookup(current_user, assignment)
    if not group:
        flash("You are not in a group")
    else:
        try:

            if action == "accept":
                group.accept(current_user)
                subject = "{0} has accepted the invitation to join your group".format(
                    current_user.email)
                body = "Your group for {0} now has {1} members".format(
                    assignment.display_name, len(group.members))
                group_action_email(group.members, subject, body)
            elif action == "decline":
                members = [m.user.email for m in group.members]
                group.decline(current_user)
                subject = "{0} declined an invite to join the group".format(
                    current_user.email)
                body = "{0} declined to join the group for {1}".format(
                    current_user.email, assignment.display_name)
                send_email(members, subject, body)
            elif action == "revoke":
                members = [m.user.email for m in group.members]
                group.decline(current_user)
                subject = "{0} invitation for {1} revoked".format(
                    assignment.display_name, target)
                body = "{0} has revoked the invitation for {1}".format(
                    current_user.email, target)
                send_email(members, subject, body)

        except BadRequest as e:
            flash(e.description, 'danger')
    return redirect(url_for('.assignment', name=assignment.name))
예제 #6
0
파일: student.py 프로젝트: kvakil/ok
def group_remove(name):
    assignment = get_assignment(name)
    target = User.lookup(request.form['email'])
    group = Group.lookup(current_user, assignment)
    if not target:
        flash("{0} is not enrolled".format(request.form['email']), 'warning')
    elif not group:
        flash("You are not in a group", 'warning')
    else:
        try:
            members = [m.user.email for m in group.members]
            group.remove(current_user, target)
            subject = "{0} has been removed from your {1} group".format(target.email,
                                                                        assignment.display_name)
            if target.email == current_user.email:
                descriptor = "themselves"
            else:
                descriptor = target.email
            body = "{0} removed {1} from the group.".format(current_user.email, descriptor)
            send_email(members, subject, body)
        except BadRequest as e:
            flash(e.description, 'danger')
    return redirect(url_for('.assignment', name=assignment.name))
예제 #7
0
def group_respond(name):
    assignment = get_assignment(name)
    action = request.form.get('action')
    target = request.form.get('email')
    if not action or action not in ['accept', 'decline', 'revoke']:
        abort(400)
    group = Group.lookup(current_user, assignment)
    if not group:
        flash("You are not in a group")
    else:
        try:

            if action == "accept":
                group.accept(current_user)
                subject = "{0} has accepted the invitation to join your group".format(current_user.email)
                body = "Your group for {0} now has {1} members".format(assignment.display_name,
                                                                       len(group.members))
                group_action_email(group.members, subject, body)
            elif action == "decline":
                members = [m.user.email for m in group.members]
                group.decline(current_user)
                subject = "{0} declined an invite to join the group".format(current_user.email)
                body = "{0} declined to join the group for {1}".format(current_user.email,
                                                                       assignment.display_name)
                send_email(members, subject, body)
            elif action == "revoke":
                members = [m.user.email for m in group.members]
                group.decline(current_user)
                subject = "{0} invitation for {1} revoked".format(assignment.display_name,
                                                                  target)
                body = "{0} has revoked the invitation for {1}".format(current_user.email,
                                                                       target)
                send_email(members, subject, body)

        except BadRequest as e:
            flash(e.description, 'danger')
    return redirect(url_for('.assignment', name=assignment.name))