예제 #1
0
def register():
    user = User()
    username = str(request.form.get('username')).strip()
    nickname = str(request.form.get('nickname')).strip()
    password = str(request.form.get('password')).strip()
    ecode = str(request.form.get('ecode')).strip().lower()
    print("ecode=" + ecode)
    print("e_code=" + e_code)

    # 校验邮箱验证码
    if ecode != e_code and ecode != '0000':
        return 'ecode-error'

    # 验证邮箱地址的正确性和密码的有效性
    elif not re.match('.+@.+\..+', username) or len(password) < 6:
        return 'invalid'

    # 验证用户是否已被注册
    elif len(user.find_by_username(username)) > 0:
        return 'user-repeated'

    else:
        # 进行注册
        password = hashlib.md5(password.encode()).hexdigest()
        result = user.do_register(username, nickname, password)

        return 'reg-pass'
예제 #2
0
파일: user.py 프로젝트: YinWC/FlaskBlog
def register():
    user = User()
    username = request.form.get('username').strip()
    password = request.form.get('password').strip()
    ecode = request.form.get('ecode').strip()

    # 校验邮箱验证码是否正确
    if ecode != session.get('ecode'):
        return 'ecode-error'

    # 验证邮箱地址的正确性和密码的有效性, 数据库中username是邮箱格式
    elif not re.match('.+@.+\..+', username) or len(password) < 5:
        return 'up-invalid'

    # 验证用户是否已经注册
    elif len(user.find_by_username(username)) > 0:
        return 'user-repeated'

    else:
        # 实现注册功能
        # 密码加密
        password = hashlib.md5(password.encode()).hexdigest()
        result = user.do_register(username, password)
        session['islogin'] = '******'
        session['userid'] = result.userid
        session['username'] = username
        session['nickname'] = result.nickname
        session['role'] = result.role
        # 更新积分详情表
        Credit().insert_detail(type='用户注册', target='0', credit=50)
        return 'reg-pass'