Ejemplo n.º 1
0
def register(request):
    r = json.loads(request.body)
    account = r['account']
    password = r['password']
    code = r['code']
    if judge_type(account) is None:
        return JsonResponse({'success': False, 'msg': "账号格式有误!"})
    # 从redis缓存中读取缓存信息 account唯一
    check_code = cache.get(account)
    print(check_code)
    # 验证验证码是否正确
    if check_code == code:
        # 新加用户
        user = User()
        user.username = '******' + shuffle_str(True)[0:6]
        # 判断账号类型
        if judge_type(account) == 'phone':
            user.phone = account
        else:
            user.email = account
        # 密码加密
        user.password = encrypt(password)
        print(user.password)
        # 保存
        user.save()
        return JsonResponse({'success': True, 'msg': "注册成功!"})
    else:
        return JsonResponse({'success': False, 'msg': "验证码错误!"})
Ejemplo n.º 2
0
def register():
    """用户注册"""
    if request.method == "POST":
        username = request.form.get("username")
        password = request.form.get("password")
        confirm_password = request.form.get('confirmpwd')
        email = request.form.get('email')
        phone = request.form.get('phone')
        if password == confirm_password:
            user = User()
            user.username = username
            user.password = generate_password_hash(password)
            user.phone = phone
            user.email = email
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.login'))
    return render_template('user/register.html')
Ejemplo n.º 3
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        email = request.form.get('email')
        if password == repassword:
            user = User()
            user.username = username
            # 使用自带的函数实现加密:generate_password_hash
            user.password = generate_password_hash(password)
            user.phone = phone
            user.email = email
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.index'))
    return render_template('user/register.html')
Ejemplo n.º 4
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:
            # 注册用户
            user = User()
            user.username = username
            user.password = hashlib.sha256(
                password.encode('utf-8')).hexdigest()
            user.phone = phone
            # 添加并提交
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.user_center'))
    return render_template('user/register.html')
Ejemplo n.º 5
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        email = request.form.get('email')
        if password == repassword:
            user = User()
            user.username = username
            user.password = hashlib.md5(password.encode('utf-8')).hexdigest()
            user.phone = phone
            user.email = email
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.index'))
        else:
            return '二次密码不一致,请重新输入'
    return render_template('user/register.html')
Ejemplo n.º 6
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        email = request.form.get('email')
        if password == repassword:
            # 注册用户
            user = User()
            user.username = username
            # 使用自带的函数实现加密:generate_password_hash
            user.password = generate_password_hash(password)
            print(password)
            user.phone = phone
            user.email = email
            # 添加并提交
            db.session.add(user)
            db.session.commit()
            return '注册成功!'
    return render_template('user/register.html')
Ejemplo n.º 7
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')  # request是从页面获取的,表单一点提交就会提交信息
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:  # 如果密码一致
            # 1注册用户,与模型结合
            user = User()
            # 2给对象的属性赋值
            user.username = username  # .username表示访问user的属性,获取属性
            user.password = generate_password_hash(
                password)  # 使用自带的函数实现加密generate_password_hash
            user.phone = phone  # 属性赋值
            # 添加并提交
            # 3.将user对象添加到session中(类似缓存)
            db.session.add(user)
            # 4.提交到数据库
            db.session.commit()
            return render_template('base.html')

    return render_template('user/register.html')
Ejemplo n.º 8
0
def register():
    user, types = user_type()
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        email = request.form.get('email')
        if repassword == password:
            user = User()
            user.username = username
            user.password = generate_password_hash(password)
            user.phone = phone
            user.email = email
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.index'))
        else:
            return render_template('user/register.html',
                                   msg='两次密码不一致',
                                   types=types)
    return render_template('user/register.html', types=types)
Ejemplo n.º 9
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:
            # 与模型结合
            # 1.找到模型类并创建对象
            user = User()
            # 2. 给对象赋值
            user.username = username
            user.password = password
            user.phone = phone
            # 添加到数据库
            # 3.将user对象添加到session中(类似缓存)
            db.session.add(user)
            # 4.提交数据部分
            db.session.commit()
            return '用户添加成功'
        else:
            return '两次密码不一致'
    return render_template('user/register.html')
Ejemplo n.º 10
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:
            # 与模型结合,完成数据库的添加
            # 1. 找到模型类,并创建对象
            user = User()
            # 2. 给对象的属性赋值
            user.username = username
            user.password = password
            user.phone = phone
            # 添加进数据库
            # 3. 将user对象添加到session中(类似缓存)
            db.session.add(user)
            # 4. 提交到数据库
            db.session.commit()
            return '用户注册成功!'
        else:
            return '两次密码不一致!'
    return render_template('user/register.html')
Ejemplo n.º 11
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:
            #与模型结合,拿取属性的值
            #1.找到模型类并创建对象
            user = User()
            #2.给对象的属性赋值
            user.username = username
            user.password = hashlib.md5(password.encode('utf-8')).hexdigest()
            user.phone = phone
            #添加数据至数据库
            #3.将user对象添加到session()中【缓存】
            db.session.add(user)
            #4.将缓存的数据插入到数据库里,提交数据
            db.session.commit()
            return redirect(url_for('user.user_center'))
        else:
            return "二次密码不一致"
    return render_template('user/register.html')