Example #1
0
async def send_reset_password(request, user):
    one = ''.join(random.choices(string.digits, k=1))
    two = ''.join(random.choices(string.digits, k=1))
    three = ''.join(random.choices(string.digits, k=1))
    four = ''.join(random.choices(string.digits, k=1))
    five = ''.join(random.choices(string.digits, k=1))
    six = ''.join(random.choices(string.digits, k=1))
    str_number = '' + str(one) + str(two) + str(three) + str(four) + str(
        five) + str(six)
    await set_to_cache("session-reset-password:"******"id"]), str_number,
                       3600)
    print("send_reset_password.uid========" + "session-reset-password:"******"id"]))
    subject = 'Khôi phục mật khẩu'

    #get template for forgot password
    #mailbody = reset_link

    if ("type_confirm" in user and user["type_confirm"] is not None
            and user["type_confirm"] == 1):
        await sendSMS(user, str_number, "ma xac nhan khoi phuc mat khau cua ")
    else:
        mailbody = jinja.render_string('email/reset-pass.html',
                                       request,
                                       userName=user['name'],
                                       one=one,
                                       two=two,
                                       three=three,
                                       four=four,
                                       five=five,
                                       six=six)
        scheduler = AsyncIOScheduler()
        scheduler.add_job(send_email, args=[subject, user["email"], mailbody])
        scheduler.start()
Example #2
0
async def send_active_account(request, user):
    one = ''.join(random.choices(string.digits, k=1))
    two = ''.join(random.choices(string.digits, k=1))
    three = ''.join(random.choices(string.digits, k=1))
    four = ''.join(random.choices(string.digits, k=1))
    five = ''.join(random.choices(string.digits, k=1))
    six = ''.join(random.choices(string.digits, k=1))
    str_number = '' + str(one) + str(two) + str(three) + str(four) + str(
        five) + str(six)
    await set_to_cache("session-active-account:" + str(user["id"]), str_number,
                       3600)
    subject = 'Kích hoạt tài khoản'

    #get template for forgot password
    #mailbody = reset_link
    if ("type_confirm" in user and user["type_confirm"] is not None
            and user["type_confirm"] == 1):
        await sendSMS(user, str_number, "ma xac nhan kich hoat tai khoan ")
    else:
        mailbody = jinja.render_string('email/active-account.html',
                                       request,
                                       userName=user['name'],
                                       one=one,
                                       two=two,
                                       three=three,
                                       four=four,
                                       five=five,
                                       six=six)
        scheduler = AsyncIOScheduler()
        scheduler.add_job(send_email, args=[subject, user["email"], mailbody])
        scheduler.start()
Example #3
0
async def send_reset_password_instructions(request, user):
    token = await generate_token(str(user.id), 86400)
    #reset_link = url_for_security('reset_password', token=token, _external=True)
    reset_link = app.config.get('DOMAIN_URL') + "/api/resetpw?token=" + token
    subject = app.config.get('EMAIL_SUBJECT_PASSWORD_RESET')
    
    #get template for forgot password
    #mailbody = reset_link
    mailbody = jinja.render_string('email/reset_instructions.txt',request, reset_link=reset_link) 
    scheduler = AsyncIOScheduler()
    scheduler.add_job(send_mail,args=[subject, user.email, mailbody])
    print("email===",user.email,"===mailbody===",mailbody)
    scheduler.start()