Exemplo n.º 1
0
def ga(uid: Union[str, UUID4], category: str, action: str):
    """
    I'm only tracking interesting server-side events right now (no cookies), I want to see what features
    are being used and important bits like sign-ups & book-thumbs. user-id is obfuscated
    https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event
    """
    # actually don't care about uid, just need a unique identifier. Note this is
    # a 1-way hash (right?), so I can't even decrypt - just want unique per-feature track
    uid_ = str(uid).encode()  # to bytes
    uid_ = hashlib.sha256(uid_).hexdigest()
    url = "https://ssl.google-analytics.com/"
    url += "debug/collect" if DEBUG else "collect"
    res = requests.post(url,
                        params=dict(v=1,
                                    tid=vars.GA,
                                    cid=uid_,
                                    t='event',
                                    ec=category,
                                    ea=action))
    # if DEBUG: print(res.json())

    if action in ('register', 'like', 'dislike', 'therapist', 'notes'):
        with session() as sess:
            if sess.execute(
                    text("""
            select is_superuser su from users where id=:uid
            """), dict(uid=uid)).fetchone().su:
                # don't notify of my own or Lisa's entries
                return
        send_mail('*****@*****.**', 'action',
                  dict(category=category, action=action))
Exemplo n.º 2
0
def token_mail():
    mail = current_user.useremail
    token = generate_confirmation_token(mail)
    confirm_url = url_for('confirm_email', token=token, _external=True)
    html = render_template('meldingen.html', confirm_url=confirm_url)
    send_mail(mail, html) 
    flash('En bekreftelseslink har blitt sendt via mail', 'success')
Exemplo n.º 3
0
def change_info():
    info_form = ChangeinfoForm()
    passwd_form = EditPasswordForm()
    summary_form = SummaryForm()
    pay_form = PayForm()
    if request.method == 'POST':
        if info_form.validate_on_submit():
            old_email = current_user.email
            current_user.update(username=info_form.username.data,
                                email=info_form.email.data,
                                phone=info_form.phone.data,
                                unit=info_form.unit.data)
            if info_form.email.data != old_email:
                token = current_user.generate_confirmation_token()
                send_mail(info_form.email.data,
                          'Confirm Your Account',
                          'auth/confirm',
                          user=current_user,
                          token=token)
                flash(u'似乎您已经改变邮箱地址,一封新的确认邮件已经发送到您的新邮箱地址请注意查收.', 'success')
            flash('hi {}, 已经更新邮箱地址.'.format(info_form.username.data),
                  'success')
            return redirect(url_for('users.members'))
        flash_errors(info_form)

    return render_template('user/update.html',
                           info_form=info_form,
                           passwd_form=passwd_form,
                           summary_form=summary_form,
                           pay_form=pay_form)
Exemplo n.º 4
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).count()
        if not user:
            user_add = User(name=form.name.data,
                            email=form.email.data,
                            password=form.password.data)
            db.session.add(user_add)
            db.session.commit()
            send_mail("用户注册提示",
                      current_app.config["GRADUATION_MAIL_SENDER"],
                      [current_app.config["GRADUATION_MAIL_ADMIN"]],
                      "auth/remind_admin/remind_admin",
                      user=user_add)
            token = user_add.generate_confirmed_token()
            send_mail("账户确认",
                      current_app.config["GRADUATION_MAIL_SENDER"],
                      [user_add.email],
                      "auth/confirm_auth/confirm",
                      token=token,
                      user=user_add)
            flash("注册成功!有一封邮件已发送至您的邮箱请前往确认!")
            return redirect(url_for("auth.login"))
        else:
            flash("邮箱已被注册!")
            return redirect(url_for("auth.register"))
    return render_template("auth/register.html", form=form)
Exemplo n.º 5
0
def run_snp_variations(group_info, user):
    group_name = group_info.keys()
    groupA = group_info[group_name[0]]
    groupB = group_info[group_name[1]]
    create_group_info(groupA, groupB, filename='vs'.join(group_name))

    cmd = "python {script} -i {input} -o {output} -g {group} -d {depth}".format(
        script=os.path.join(SNP_SCRIPT_DIR, SCRIPT_FILE),
        input=INPUT_TABLE,
        output=os.path.join(basedir, 'app', 'static', 'variation_results',
                            'vs'.join(group_name) + '_table'),
        group=os.path.join(SNP_SCRIPT_DIR, 'vs'.join(group_name)),
        depth='5')
    subprocess.call(cmd, shell=True)
    os.chdir(os.path.join(basedir, 'app', 'static', 'variation_results'))
    zip_cmd = 'zip {0} {1}'.format('vs'.join(group_name) + '_table.zip',
                                   'vs'.join(group_name) + '_table')
    subprocess.call(zip_cmd, shell=True)
    '''
    rm_cmd = 'rm -rf {0}'.format(
        'vs'.join(group_name) + '_table'
    )
    subprocess.call(rm_cmd, shell=True)
    '''
    db = DB()
    results = db.execute(
        "select email from user where username='******'".format(user))
    if results[0][0]:
        to = results[0][0]
        send_mail(to,
                  'Snp Variation Results',
                  'mail/variation_results',
                  user=user,
                  filename='vs'.join(group_name) + '_table')
    return 'done'
Exemplo n.º 6
0
def request_reset():
    """
    request rest page
    """
    if request.method == "POST":
        # get email from form
        email = request.form["email"]
        # query user by emeail
        user = User.query.filter_by(email=email).first()
        # check if user has been found
        if user is None:
            # alert user
            flash("invalid credentials")
            # return to reset page
            return render_template("reset.html")
        # prepare email
        subject = "password reset requested"
        # generate token
        token = ts.dumps(user.email, salt="recover-key")
        # build recover url
        recover_url = url_for("auth.reset_with_token",
                              token=token,
                              _external=True)
        # send the email
        send_mail(subject, current_app.config["MAIL_USERNAME"], [email],
                  recover_url)
        # alert user
        flash("reset link sent")
        # redirect to home
        return redirect(url_for("base.home")), 302
    return render_template("reset.html")
Exemplo n.º 7
0
def on_after_register(user: M.FU_UserDB, request: Request):
    ga(user.id, 'user', 'register')
    with db():
        t = M.Tag(user_id=user.id, main=True, selected=True, name='Main')
        db.session.add(t)
        db.session.commit()
    send_mail(user.email, "welcome", {})
Exemplo n.º 8
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        # 根据表单数据创建User对象
        u = User(
            username=form.username.data,
            password=form.password.data,
            sex=form.sex.data,
            age=form.age.data,
            email=form.email.data,
            idCard=form.idCard.data,
            phonenumber=form.phonenumber.data,
        )

        # 然后保存到数据库中
        db.session.add(u)
        # 此时还没有提交,所以新用户没有id值,需要手动提交
        db.session.commit()
        # 准备token
        # 发送激活邮件
        token = u.generate_activate_token()
        url = url_for('user.activate', token=token, _external=True)
        send_mail(form.email.data,
                  '账户激活',
                  'activate',
                  username=form.username.data,
                  url=url)
        flash('激活邮件已发送至您的邮箱,请点击连接以完成激活')
        return redirect(url_for('main.index'))
    return render_template('user/register.html', form=form)
Exemplo n.º 9
0
def send_log(receiver):
    log_path = os.path.join(BASE_DIR, 'app/DBexcel/log')
    tomorrow = getYesterday()
    log_file_path = os.path.join(log_path, tomorrow.strftime("%Y-%m-%d.log"))
    with open(log_file_path, 'r') as f:
        context = f.read()
    subject = tomorrow.strftime("%Y-%m-%d") + ' - DBexcel日志文件'
    send_mail(receiver, subject, context, 'plain')
Exemplo n.º 10
0
def resend_mail():
    token = current_user.generate_confirmed_token()
    send_mail(current_app.config["GRADUATION_MAIL_SUBJECT_PREFIX"] + "Confirm account",
              current_app.config["GRADUATION_MAIL_SENDER"],
              [current_user.email],
              "auth/confirm_auth/confirm",
              token=token,
              user=current_user)
    return redirect(url_for("foreground.index"))
Exemplo n.º 11
0
def resend_confirmation():
    token = current_user.generate_confirmation_token()
    send_mail(current_user.email,
              'Confirm Your Account',
              'auth/confirm',
              user=current_user,
              token=token)
    flash(u'一封新的确认邮件已经发送到您的邮箱.', 'success')
    return redirect(url_for('main.home'))
Exemplo n.º 12
0
def resend_confirmation():
    token = current_user.generate_confirmation_token()
    send_mail(current_user.email,
              'Confirm Your Account',
              'mail/confirm',
              user=current_user,
              token=token)
    flash('A new confirmation email has been sent to you by email.', 'success')
    return redirect(url_for('main.index'))
Exemplo n.º 13
0
def resend_confirmation():
    email = current_user.email
    token = current_user.generate_confirmation_token()
    mail.send_mail(email,
                   '确认账户',
                   'auth/mail/confirm_account',
                   user=current_user,
                   token=token)
    flash('账户确认邮件已经重新发送')
    return redirect(url_for('main.index'))
Exemplo n.º 14
0
def create_user(app):  # pylint: disable=inconsistent-return-statements
    """
    create admin user

    params:
        - app: flask app
        - User: db user model
        - db: sqlalchemy session
    """
    # with app context
    with app.app_context():
        # create user
        # find user
        user = User.query.filter_by(email=app.config["USER_EMAIL"]).first()
        # check email has been found
        if user is not None:
            # check password
            if user.check_password(app.config["USER_PASSWORD"]):
                pass
            else:
                # update password
                user.set_password(app.config["USER_PASSWORD"])
                # save changes
                db.session.commit()
        else:
            # initialize user
            user = User(email=app.config["USER_EMAIL"],
                        password=app.config["USER_PASSWORD"])
            # add to session
            db.session.add(user)
            db.session.commit()
            # assert user properly created
            assert user.id is not None
        # disable email confirmation by default (change in config.ppy)
        if app.config["USER_CONFIRMED"]:
            user.confirmed = True
            db.session.add(user)
            db.session.commit()
        else:
            # send confirmation email
            if user.confirmed is False:
                # prepare email
                subject = "confirm account"
                # generate token
                token = ts.dumps(user.email, salt="email-confirm-key")
                # build recover url
                confirm_url = url_for("auth.confirm_email",
                                      token=token,
                                      _external=True)
                # alert user
                print("account confirmation sent or use link below: ")
                print(confirm_url)
                # send the emails
                send_mail(subject, app.config["MAIL_USERNAME"], [user.email],
                          confirm_url)
Exemplo n.º 15
0
def send_password_reset_mail(user):
    token = user.password_reset_token
    send_mail('[SPA-Base] Reset Your Password',
              sender=current_app.config['SERVER_EMAIL'],
              recipients=[str(user.email)],
              text_body=render_template('auth/email/password_reset.txt',
                                        user=user,
                                        token=token),
              html_body=render_template('auth/email/password_reset.html',
                                        user=user,
                                        token=token))
Exemplo n.º 16
0
def send_email_verification_mail(user, email):
    token = email.verification_token
    send_mail('[SPA-Base] Please Verify Your Email',
              sender=current_app.config['SERVER_EMAIL'],
              recipients=[str(email)],
              text_body=render_template('auth/email/email_verification.txt',
                                        user=user,
                                        token=token),
              html_body=render_template('auth/email/email_verification.html',
                                        user=user,
                                        token=token))
Exemplo n.º 17
0
def send_mail(email):
    """
   envoie un mail de test à l'adresse mentionnée
    """
    from app import mail
    from flask import current_app
    with current_app.test_request_context("localhost.com"):
        mail.send_mail("Testing mail sending",
                       email,
                       'testing.html',
                       url="google.com")
        print("mail successfully sent to " + email)
Exemplo n.º 18
0
def send_register_mail(user):
    """
    send a registration mail
    :param user: user to send
    """
    from app import mail

    mail.send_mail("Confirmation inscription",
                   user.email,
                   "registerMail.html",
                   user=user,
                   url=request.url_root)
Exemplo n.º 19
0
def get_captcha():
    """
    获取邮箱验证码
    """
    username = request.json.get('username') or "同学"
    email = request.json.get('email')
    user = User.query.filter_by(email=email).first()

    if user is None:
        return jsonify({}), 404
    captcha = '%04d' % random.randrange(0, 9999)
    send_mail(email, '木犀通行证验证码', 'mail/reset', username=username, captcha=captcha)
    user.reset_t = user.generate_reset_token(captcha)
    return jsonify({}), 200
Exemplo n.º 20
0
def get_captcha():
    """
    获取邮箱验证码
    """
    username = request.json.get('username') or "同学"
    email = request.json.get('email')
    user = User.query.filter_by(email=email).first()

    if user is None:
        return jsonify({}), 404
    captcha = '%04d' % random.randrange(0, 9999)
    send_mail(email,
              '木犀通行证验证码',
              'mail/reset',
              username=username,
              captcha=captcha)
    user.reset_t = user.generate_reset_token(captcha)
    return jsonify({}), 200
Exemplo n.º 21
0
def change_info():
    info_form = ChangeinfoForm()
    passwd_form = EditPasswordForm()
    if request.method == 'POST':
        if info_form.validate_on_submit():
            old_email = current_user.email
            current_user.update(username=info_form.username.data,
                                email=info_form.email.data)
            if info_form.email.data != old_email:
                token = current_user.generate_confirmation_token()
                send_mail(info_form.email.data, 'Confirm Your Account',
                          'auth/confirm', user=current_user, token=token)
                flash('Seems you change your email. A confirmation email has been sent to you by email. \
                        note: open verify email better on your pc browser', 'success')
            flash('hi {}, Already update your infomation.'.format(info_form.username.data), 'success')
            return redirect(url_for('users.members'))
        else:
            flash_errors(info_form)
            return render_template('user/update.html', info_form=info_form, passwd_form=passwd_form)
Exemplo n.º 22
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        user.save()
        token = user.generate_confirmation_token()
        send_mail(user.email,
                  'Confirm Your Account',
                  'mail/confirm',
                  user=user,
                  token=token)
        flash(
            'Thanks your register. A confirm email has been sent to your email',
            'success')
        login_user(user)
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form=form)
Exemplo n.º 23
0
def generate_reset_mail(user):
    """
    sends user reset password mail + generate his token
    :param user: User have to reset his password
    :return: None
    """
    from app import mail

    if not user:  # user with email not found
        return
    token = get_user_token()
    user.token_pwd = token
    db.session.commit()

    mail.send_mail("Demande réinitialisation mot de passe",
                   user.email,
                   "password_forgot_mail.html",
                   user=user,
                   url=request.url_root[:-1] +
                   url_for("auth.forgot_password") + "/" + token)
Exemplo n.º 24
0
def register():
    form = RegistForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    password=form.password.data,
                    email=form.email.data)
        db.session.add(user)
        db.session.commit()
        mail.send_mail(current_app.config['MAIL_ADMIN'],
                       '用户注册',
                       'mail/registry',
                       user=user)
        token = user.generate_confirmation_token()
        mail.send_mail(user.email,
                       '确认账户',
                       'auth/mail/confirm_account',
                       user=user,
                       token=token)
        flash('请前往邮箱确认账户')
        return redirect(url_for('main.index'))
    return render_template('auth/registry.html', form=form)
Exemplo n.º 25
0
def lostfound():
    """
    设置新密码界面
    点击确认, 发送确认邮件
    确认邮件防止别人修改已知邮箱密码
    """
    form = LostForm()
    if form.validate_on_submit():
        email = form.email.data
        newpassword = form.newpassword.data
        user = User.query.filter_by(email = email).first()
        if user:
            session[str(user.id)] = newpassword
            token = user.generate_confirm_token()
            send_mail(
                email, 'Confirm a New Password', 'auth/confirm',
                user=user, token=token
            )
        else:
            return False
    return render_template('auth/lost.html', form=form)
Exemplo n.º 26
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        # 根据表单数据创建User对象,然后保存到数据库
        u = User(username=form.username.data,
                 password=form.password.data,
                 email=form.email.data)
        #保存到数据库中
        db.session.add(u)
        # 此时还没有提交,所以新用户没有id ,需要手动提交
        db.session.commit()
        # 准备token
        # 发送激活邮件
        token = u.generate_activate_token()
        url = url_for("user.activate", token=token, _external=True)
        send_mail(form.email.data,
                  "账户激活",
                  "activate",
                  username=form.username.data,
                  url=url)
        flash("注册成功")
        return redirect(url_for('main.index'))
    return render_template("user/register.html", form=form)
Exemplo n.º 27
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    realname=form.realname.data,
                    unit=form.unit.data,
                    phone=form.phone.data,
                    email=form.email.data,
                    password=form.password.data,
                    active=False)
        user.save()
        token = user.generate_confirmation_token()
        send_mail(user.email,
                  'Confirm Your Account',
                  'auth/confirm',
                  user=user,
                  token=token)
        flash(u'感谢您的注册,一封确认邮件将会被发送到您的邮箱,请注意查收.', 'success')
        login_user(user)
        return redirect(url_for('main.home'))
    else:
        flash_errors(form)
    return render_template('auth/register.html', form=form)
Exemplo n.º 28
0
def reset_password_request():
    """密码忘记时,在登录页重置密码"""
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user:
            flash('未找到该用户')
        token = user.generate_reset_token()
        if not mail.send_mail(user.email,
                              '重置密码',
                              'auth/mail/reset_password',
                              user=user,
                              token=token):
            flash('邮件发送失败,请联系管理员')
        else:
            flash('密码重置链接已发往您的邮箱')
        return redirect(url_for('auth.reset_password_request'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 29
0
def on_after_forgot_password(user: M.FU_UserDB, token: str, request: Request):
    send_mail(user.email, "forgot-password", token)
Exemplo n.º 30
0
def send_email_not_found_mail(email):
    send_mail('[SPA-Base] Email Not Registered',
              sender=current_app.config['SERVER_EMAIL'],
              recipients=[email],
              text_body=render_template('auth/email/email_not_found.txt'),
              html_body=render_template('auth/email/email_not_found.html'))