Beispiel #1
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)
                    db.session.add(user)
                    db.session.commit()
                    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)
Beispiel #2
0
def register():
    if request.method == "GET":
        return render_template('back/register.html')
    #增加数据
    user = User()
    user.username = request.form.get('username')
    user.password = generate_password_hash(request.form.get("password"))
    #验证是否已经被注册
    if User.query.get(user.username) is None:
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('back.login'))
    return render_template('back/register.html')
Beispiel #3
0
 def new_user(username, password, email):
     """
     创建新用户
     :param username: str,用户名
     :param password: str,密码
     :param email: str,邮箱
     :return:
     """
     user = User(email=email, username=username)
     hash_pw = user.hash_password(password)
     user.password = hash_pw
     db.session.add(user)
     db.session.commit()
     return user
Beispiel #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)
Beispiel #5
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)
Beispiel #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 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)
Beispiel #7
0
def add_user(*args):
    decoded_data = json.loads(request.data.decode())
    user = User(username=decoded_data.get("username"),
                password=decoded_data.get("password"),
                role=eval("Roles.{}".format(decoded_data.get("role").lower())))
    try:
        db.session.add(user)
        db.session.commit()
    except SQLAlchemyError as e:
        return {"error": e.__dict__["orig"]}, 400
Beispiel #8
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)
Beispiel #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)
Beispiel #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)
Beispiel #11
0
def add_user():
    if request.method == 'GET':
        return render_template('back/add_user.html')
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        tel = request.form.get('tel')
        email = request.form.get('email')
        if username and password and tel and email:
            user = User.query.filter(User.username == username).first()
            if user:
                error = '姓名已存在'
                return redirect(url_for('back.add_user', error=error))
            else:
                user = User()
                user.username = username
                user.password = password
                user.tel = tel
                user.email = email
                db.session.add(user)
                db.session.commit()
                return redirect(url_for('back.user_list'))

        else:
            error = '请填写完整用户信息'
            return render_template('back/add_user.html', error=error)
Beispiel #12
0
def register():
    if request.method == 'GET':
        return render_template('back/register.html')

    if request.method == 'POST':
        # 获取数据
        user = User()
        username = request.form.get('username')
        password = request.form.get('userpwd')
        password_again = request.form.get('userpwd2')
        face = request.form.get('face').split(',')[-1]
        if not(face and username and password and password_again):
            error = '请填写完整信息'
            return render_template('back/register.html', error=error)
        if password != password_again:
            error = '两次密码输入不一致,请重新输入 '
            return render_template('back/register.html', error=error)
        user_list = select_login_info(username)
        if user_list != []:
            error = '用户名已存在 '
            return render_template('back/register.html', error=error)
        if not register_face_user(face, username):  # 把username当做人脸识别的userId
            error = '注册失败'
            return render_template('back/register.html', error=error)
        user.username = username
        user.password = generate_password_hash(password)
        user.save_update()
        return redirect(url_for('back.login'))
Beispiel #13
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)
Beispiel #14
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)
Beispiel #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 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'))
Beispiel #16
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)
Beispiel #17
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)
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)
Beispiel #19
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)
Beispiel #20
0
def rpc():
    engine = create_engine(DB_URI)
    ConnectionDB._engine = engine
    Base.metadata.create_all(bind=engine)

    RPC.init(DB_URI)

    user = User(name=TEST_USER, token=TEST_TOKEN)
    RPC.session.add(user)
    RPC.session.commit()

    RPC.user = user
    return RPC
Beispiel #21
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_res = User.query.filter(User.name == username).first()
            if user_res:  # 判断是否注册
                error = '该用户名已注册,请更换!'
                return render_template('back/register.html',
                                       err=error)  #error需要页面的{{error}}接收
            if password != password2:
                error = '重复密码不一致!'
                return render_template('back/register.html', err=error)
            #保存用户
            user = User()
            user.name = username
            user.pwd = generate_password_hash(password)  #加密保存到数据库
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('first.login'))
        return render_template('back/register.html')
Beispiel #22
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'))
Beispiel #23
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)
Beispiel #24
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)
Beispiel #25
0
from back.config import app, db
from back.models import User, Roles
from flask import Response


@app.route("/health/")
def health():
    return Response(status=200)


if __name__ == '__main__':
    # if you want to reinitialize db content please uncomment next line
    # db.drop_all()
    db.create_all()
    user = User(username="******", role=Roles.ADMIN, password="******")
    db.session.add(user)
    user = User(username="******", role=Roles.SCSO, password="******")
    db.session.add(user)
    user_nd = User(username="******", role=Roles.CSO, password="******")
    db.session.add(user_nd)
    user_rd = User(username="******", role=Roles.FM, password="******")
    db.session.add(user_rd)
    user_fr = User(username="******", role=Roles.PM, password="******")
    db.session.add(user_fr)
    user_fi = User(username="******", role=Roles.SM, password="******")
    db.session.add(user_fi)
    user_si = User(username="******", role=Roles.PS, password="******")
    db.session.add(user_si)
    user_sv = User(username="******", role=Roles.SS, password="******")
    db.session.add(user_sv)