def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        #获取数据
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        if username and password and password2:
            user = User.query.filter(User.username == username).first()
            if user:
                error = '该账号已经注册,请更换账号!'
                return render_template('back/register.html', error=error)
            else:
                if password == password2:
                    user = User()
                    user.username = username
                    user.password = generate_password_hash(password)
                    user.save()
                    return redirect(url_for('back.login'))
                else:
                    error = '密码错误两次密码不一致!'
                    return render_template('back/register.html', error=error)
        else:
            error = '亲,请填写完整的信息!'
            return render_template('back/register.html', error=error)
Example #2
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        password1 = request.form.get('password1')

        print(username, password, password1)
        if username and password:
            #判断账号是否被注册过
            user = User.query.filter(User.username == username).first()
            if user:
                error = '该账号已注册,请更换账号'
                return render_template('back/register.html', error=error)
            elif password1 == password:
                user = User()
                user.username = username
                user.password = password
                user.save()
                return redirect(url_for('back.login'))
            elif password != password1:
                error = '两次输入不一致,请重新输入'
                return render_template('back/register.html', error=error)

        else:
            error = '请填写完整的信息 '
            return render_template('back/register.html', error=error)
Example #3
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('userpwd')
        password2 = request.form.get('userpwd2')
        if username and password and password2:
            user = User.query.filter(User.username == username).first()
            if user:
                error = '该用户名已经注册,请重新设置'
                return render_template('back/register.html', error=error)
            else:
                if password == password2:
                    user = User()
                    user.username = username
                    user.password = generate_password_hash(password)
                    user.save()
                    # return redirect(url_for('back.login'))
                    return redirect(url_for('back.login'))
                else:
                    error = '两次密码不一致,请重新输入'
                    return render_template('back/register.html', error=error)
        else:
            error = '请填写完整信息'
            return render_template('back/register.html', error=error)
Example #4
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        #获取数据
        username = request.form.get('username')
        password = request.form.get('password')
        password1 = request.form.get('password1')
        number = request.form.get('number')
        email = request.form.get('email')
        # 判断用户名是否注册过,如果注册在判断密码
        user = User.query.filter(User.name == username).first()
        if user:
            #用户存在
            error = '用户名已存在'
            return render_template('back/register.html', error=error)
        else:
            if password1 == password:
                #保存数据
                user = User()
                user.name = username
                # user.password = password
                #给密码编码
                user.password = generate_password_hash(password)
                user.email = email
                user.number = number
                user.save()
                return redirect(url_for('back.home'))
            else:
                #密码不一样
                error = '两次输入的密码不一致'
                return render_template('back/register.html', error=error)
Example #5
0
def rigister():
    if request.method == 'GET':
        return render_template('back/rigister.html')
    if request.method == 'POST':
        #获取数据
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        if username and password and password2:
            #先判断该账号是否被注册过
            user = User.query.filter(User.username == username).first()
            if user:
                # 判断该账号已经被注册过
                error = '该账号已注册,请更换账号'
                return render_template('back/rigister.html', error=error)
            else:
                if password2 == password:
                    # 保存数据
                    user = User()
                    user.username = username
                    user.password = generate_password_hash(password)
                    user.save()
                    return redirect(url_for('back.login'))
                else:
                    # 密码错误
                    error = '两次密码不一致'
                    return render_template('back/rigister.html', error=error)
        else:
            error = '请提交完整信息'
            return render_template('back/rigister.html',error = error)
Example #6
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        # 获取数据
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        if not all([username, password, password2]):
            error = '请提交完整的信息!'
            return render_template('back/register.html', error=error)
        user = User.query.filter(User.username == username).first()
        if user:
            error = '改账号已注册,请更换账号!'
            return render_template('back/register.html', error=error)
        if password != password2:
            error = '两次密码不一致!'
            return render_template('back/register.html', error=error)

        # 成功注册
        user = User()
        user.username = username
        print(username)
        user.password = generate_password_hash(password)
        user.save()
        return redirect(url_for('back.login'))
Example #7
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        # 获取前端传来的数据
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        # 数据校验
        if username and password and password2:
            # 先校验账号,查询数据库
            user = User.query.filter(User.username == username).first()
            if user:
                error = '用户已存在,请重新注册'
                return render_template('back/register.html', error=error)
            else:
                # 校验密码
                if password2 == password:
                    # 保存数据
                    user = User()
                    user.username = username
                    user.password = generate_password_hash(password)
                    user.save()
                    return redirect(url_for('back.login'))

                else:
                    error = '两次密码不一致,请重新输入'
                    return render_template('back/register.html', error=error)
        else:
            error = '请输入完整数据'
            return render_template('back/register.html', error=error)
Example #8
0
def users_add():
    if request.method == 'GET':
        return render_template('back/goods_detail.html')
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        # 判断参数是否全部输入
        if username and password and password2:
            # 判断账号是否注册
            user = User.query.filter(User.u_name == username).first()
            if user:
                error = '该账号已注册,请重新输入!'
                return render_template('back/goods_detail.html', error=error)
            else:
                # 判断密码是否一致
                if password == password2:
                    admin = User()
                    admin.u_name = username
                    admin.u_password = generate_password_hash(password)
                    admin.u_password2 = password2
                    admin.save()
                    return redirect(url_for('back.user_list'))
                else:
                    error = '密码不一致!'
                    return render_template('back/goods_detail.html',
                                           error=error)
        else:
            error = '确保信息输入完整'
            return render_template('back/goods_detail.html', error=error)
Example #9
0
def login1():#注册
    if request.method == 'POST':
        # 获取数据
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        if username and password:
            #判断该账号是否注册过,这里是从数据库取值
            user = User.query.filter(User.username == username).first()
            if user:
                error = '该账号已经被注册'
                return render_template('back/login.html',error=error)
            else:
                if password == password2:
                    # 保存数据
                    user = User()
                    user.username = username
                    user.password =  generate_password_hash(password)
                    user.save()
                    # return render_template('back/register.html')
                    return redirect(url_for('back.register'))
                else:
                #     密码错误
                    error = '密码不一致'
                    return render_template('back/login.html',error=error)
Example #10
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        if username and password and password2:
            user = User.query.filter(User.username == username).first()
            if user:
                error = '该账号已注册,请更换其他账号'
                return render_template('back/register.html', error=error)
            else:
                if password != password2:
                    error = '两次密码填写不一致,请重新注册'
                    return render_template('back/register.html', error=error)
                else:
                    user = User()
                    user.username = username
                    user.password = generate_password_hash(password)
                    user.save()
                    session['user_id'] = user.id
                    return redirect(url_for('back.login'))
        else:
            error = '请填写完整信息'
            return render_template('back/register.html', error=error)
Example #11
0
def zhuce():
    if request.method == 'GET':
        return render_template('/back/zhuce.html/')
    if request.method == 'POST':
        nameuser = request.form.get('nameuser')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        if nameuser and password:

            user = User.query.filter(User.username == nameuser).first()
            if user:
                cw = '用户名已经注册'
                return render_template('/back/zhuce.html/', cw=cw)
            else:
                if password == password2:

                    u1 = User()
                    u1.username = nameuser
                    u1.password = generate_password_hash(password)
                    u1.save()
                    return redirect(url_for('back.login'))
                else:
                    cw = '两次密码不一样'
                    return render_template('/back/zhuce.html/', cw=cw)

        else:
            cw = '请填写完整的信息'
            return render_template('/back/zhuce.html/', cw=cw)
Example #12
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        face = request.form.get('face')
        if username and password and password2 and face:
            user = User.query.filter(User.username == username).first()
            if user:
                error = '该账号已被注册!'
                return render_template('back/register.html', error=error)
            else:
                img = face.split(',')[-1]
                if not register_face_user(img, username):
                    error = '注册失败'
                    return render_template('back/register.html', error=error)
                if password2 == password:
                    file = base64.b64decode(img)
                    img_dir = os.path.join(IMAGE_DIR, username + '.jpg')
                    with open(img_dir, 'wb') as f:
                        f.write(file)
                    user = User()
                    user.username = username
                    user.password = generate_password_hash(password)
                    user.save()
                    return redirect(url_for('back.login'))
                else:
                    error = '两次密码不一致'
                    return render_template('back/register.html', error=error)
        else:
            error = '信息不完整!'
            return render_template('back/register.html', error=error)
Example #13
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        # 模拟注册功能
        # 获取页面中传递的参数
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        if username and password and password2:
            # 先判断该账号是否被注册过
            user = User.query.filter(User.username == username).first()
            print(user.username)
            if user and user.is_delete == 0:
                # 判断该账号已经被注册过
                error = '该账号已注册,请更换账号'
                return render_template('back/register.html', error=error)
            elif not user:
                if password2 == password:
                    # 保存数据
                    user = User()
                    user.username = username
                    user.password = generate_password_hash(password)
                    user.save()
                    return redirect(url_for('first.session_login'))
                else:
                    # 密码错误
                    error = '两次密码不一致'
                    return render_template('back/register.html', error=error)
            elif user.is_delete == 1:
                if password == password2:

                    user.password = generate_password_hash(password)
                    user.is_delete = 0
                    user.save()
                    return redirect(url_for('first.session_login'))
                else:
                    # 密码错误
                    error = '两次密码不一致'
                    return render_template('back/register.html', error=error)
        else:
            error = '请填写完整的信息'
            return render_template('back/register.html', error=error)
Example #14
0
def regist():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        account = request.form.get('account')
        password1 = request.form.get('password01')
        password2 = request.form.get('password02')
        user = User.query.filter(User.account == account).first()
        print(user)
        if user:
            msg = '此用户已经存在'
            return render_template('back/register.html', msg=msg)
        print(password1, password2)
        if password1 != password2:
            msg = '密码不一致'
            return render_template('back/register.html', msg=msg)
        user = User()
        user.account = account
        user.password = generate_password_hash(password1)
        user.save()
    return redirect(url_for('back.login'))
Example #15
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        # 获取提交的用户名、密码
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')

        # 判断信息是否输入完整
        if username and password and password2:
            # 获取数据库中的用户信息
            user = User.query.filter(User.username == username).first()
            # 判断用户是否存在
            if user:
                error = '该账号已被注册,请更换新账号'
                return render_template('back.register.html', error=error)
            # 不存在就创建
            else:
                # 判断两次密码输入是否一致
                if password == password2:
                    # 创建一个用户对象
                    user = User()
                    # 添加用户名
                    user.username = username
                    # 通过generate_password_hash加密
                    user.password = generate_password_hash(password)
                    # 调用save方法将用户对象保存到数据库中
                    user.save()
                    return redirect(url_for('back.login'))
                # 两次密码不一致做的事情
                else:
                    error = '两次输入密码不一致'
                    return render_template('back/register.html', error=error)
        # 信息输入不完整做的事情
        else:
            error = '信息请填写完整'
            return render_template('back/register.html', error=error)
Example #16
0
def register():
    db.create_all()
    if request.method == 'GET':
        return render_template('back/register.html')
    if request.method == 'POST':
        # 获取从注册页面传来的数据
        username = request.form.get('username')
        password = request.form.get('password')
        affirm_password = request.form.get('password2')

        if username and password and affirm_password:

            user = User.query.filter(User.username == username).first()

            if user:
                error = '该用户已存在,请重新输入用户名!'
                return render_template('back/register.html', error=error)

            if password != affirm_password:
                error = '两次密码不一致,请重新输入!'
                return render_template('back/register.html', error=error)

            user = User()
            user.username = username
            user.password = generate_password_hash(password)

            user.save()

            user_inform = UserInform()
            user_inform.name = 'QF' + username
            user_inform.user_id = user.id
            user_inform.save()

            return redirect(url_for('back.login'))
        else:
            error = '请填写完整的注册信息!'
            return render_template('back/register.html', error=error)