Exemplo n.º 1
0
def update_temp_user_email(session, email):
    '''
        根据session更新email
        生成随机验证码,向邮箱发送验证码
        从temp_user中查找session记录,将email code 以及errtry=0 pass=0添加至其中
    '''

    from model.mongodb import MongoDB
    db = MongoDB().db
    temp_user = db.temp_user

    one = temp_user.find_one({'session':session})
    if one == None:
        return False

    from lib import generate_verify_code
    code = generate_verify_code()

    email_data = {
        'fromuser':'******',
        'touser':email,
        'subject':'X网站注册邮件验证码',
        'message':'你好,您的邮件验证码是%s,20分钟内输入有效'%code
    }

    from lib import send_email
    send_email(email_data)

    import time
    temp_user.update({'session':session},{'$set':{'email':email,'code':code,'errtry':0,'pass':0,'createtime':time.time()}})
    return True
Exemplo n.º 2
0
def resend_verify_code(session, email):
    '''
        根据session查找temp_user里的记录
        检查记录中上次create时间与当前时间差是否超过一分钟
        重新发送验证码邮件
        更新创建时间和验证码
    '''
    from model.mongodb import MongoDB
    db = MongoDB().db
    temp_user = db.temp_user

    one = temp_user.find_one({'session':session,'email':email})
    if one == None:
        return False

    if not 'pass' in one:
        return False

    if one['pass'] == 1:
        return False

    old_createtime = one['createtime']

    import time
    now_time = time.time()

    if now_time - old_createtime < 60:
        return False

    from lib import generate_verify_code
    code = generate_verify_code()

    email_data = {
        'fromuser':'******',
        'touser':email,
        'subject':'X网站注册邮件验证码',
        'message':'你好,您的邮件验证码是%s,20分钟内输入有效'%code
    }

    from lib import send_email
    send_email(email_data)

    temp_user.update({'session':session,'email':email},{'$set':{'code':code,'errtry':0,'pass':0,'createtime':now_time}})
    return True
Exemplo n.º 3
0
def testtest():
    from lib import generate_verify_code
    code = generate_verify_code()
    print code