Example #1
0
    def post(self):
        # 获取数据
        args = parser.parse_args()

        username = args.get('username')
        password = args.get('password')
        phone = args.get('phone')
        bobby = args.get('hobby')
        print(bobby)
        icon = args.get('icon')
        print(icon)
        # 创建user对象
        user = User()
        user.username = username
        user.password = password
        if icon:
            upload_path = os.path.join(Config.UPLOAD_ICON_DIR, icon.filename)
            icon.save(upload_path)
            # 保存路径个
            user.icon = os.path.join('upload/icon', icon.filename)
        if phone:
            user.phone = phone
        db.session.add(user)
        db.session.commit()

        return user
Example #2
0
def register():
    if request.method == 'GET':

        return render_template('register.html')
    else:
        print(request.form)
        print(dict(request.form))
        username = request.form.get('username')
        paw = request.form.get('password')
        rpaw = request.form.get('repassword')
        phone = request.form.get('phone')
        if username:
            print('aaaa')
        if paw:
            print('bbb')
        if paw == rpaw:
            user = User()
            user.username = username
            user.password = paw
            user.phone = phone
            db.session.add(user)
            db.session.commit()
            # user.save()
            return redirect(url_for('user.index'))
        else:
            return '密码不一致'
Example #3
0
 def post(self):
     args = parse.parse_args()
     username = args.get('username')
     password = args.get('password')
     hobby = args.get('hobby')
     print(hobby)
     user = User()
     user.username = username
     user.password = password
     db.session.add(user)
     db.session.commit()
     return user
Example #4
0
def user_register():
    if request.method == 'POST':
        username = request.form.get('username')
        phone = request.form.get('phone')
        password = request.form.get('password')
        re_password = request.form.get('repassword')
        if password == re_password:
            user = User()
            user.username = username
            user.password = generate_password_hash(password)
            user.phone = phone
            db.session.add(user)  # 将user对象添加到session缓存
            db.session.commit()
            return redirect(url_for('user.login'))
    return render_template('user/register.html')
Example #5
0
 def post(self):
     args = parser.parse_args()
     username = args.get('username')
     password = args.get('password')
     phone = args.get('phone')
     hobby = args.get('hobby')
     icon = args.get('icon')
     user = User()
     if icon:
         upload_path = os.path.join(config.UPLOAD_ICON_DIR, icon.filename)
         icon.save(upload_path)
         user.icon = config.UPLOAD_ICON_DIR + '\\' + icon.filename
     user.username = username
     user.password = password
     user.phone = phone
     db.session.add(user)
     db.session.commit()
     return user
Example #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')
        if password == repassword:
            for item in users:
                if item.username == username:
                    return render_template('user/register.html', msg='用户已存在')
            user = User()
            user.username = username
            user.password = password
            user.phone = phone

            db.session.add(user)
            db.session.commit()
            return redirect('/')
    return render_template('user/register.html')
Example #7
0
def register():
    print(request.method)
    if request.method == "POST":
        form = request.form
        username = form.get("username")
        password = form.get("password")
        repassword = form.get("repassword")
        phone = form.get("phone")
        if password == repassword:
            user = User()
            user.username = username
            user.password = password
            user.phone = phone
            db.session.add(user)
            db.session.commit()
            return "用户注册成功"
        else:
            return "两次密码不一致"
    else:
        return render_template('user/register.html')
Example #8
0
def register():
    if request.method == "POST":
        form = request.form
        username = form.get("username")
        password = form.get("password")
        repassword = form.get("repassword")
        phone = 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.home'))
        else:
            return "两次密码不一致"
    else:
        return render_template('user/register.html')
Example #9
0
 def post(self):
     # 获取数据
     args = parser.parse_args()
     username = args.get('username')
     password = args.get('password')
     phone = args.get('phone')
     hobby = args.get('hobby')  # ['篮球', '皮球']
     icon = args.get('icon')  # <FileStorage: 'gjjxj.jpg' ('image/jpeg')>
     # 创建user对象
     user = User()
     user.username = username
     user.password = password
     if icon:
         upload_path = os.path.join(Config.UPLOAD_ICON_DIR, icon.filename)
         icon.save(upload_path)
         # 保存路径
         user.icon = os.path.join('upload', 'icon', icon.filename)
     if phone:
         user.phone = phone
     db.session.add(user)
     db.session.commit()
     return user
Example #10
0
File: view.py Project: xyz06/myblog
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        pwd = request.form.get('pwd')
        repwd = request.form.get('cpwd')
        phone = request.form.get('phone')
        select_user = User.query.filter(User.username == username).all()
        if len(select_user) == 0:
            if pwd == repwd:
                user = User()
                user.username = username
                user.pwd = generate_password_hash(pwd)
                user.phone = phone

                db.session.add(user)
                db.session.commit()
                return redirect(url_for('user.login'))
            else:
                return '密码不一致'
        return render_template('user/register.html', msg='用户名已存在')

    return render_template('user/register.html')
Example #11
0
def register_blueprint():
    """

    :return: response
    """
    if request.method == 'POST':
        # 将前端页面的数据传回后台
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        # 判断如果两次密码一致,则创建User对象
        if password == repassword:
            # 使用model持久化的方式存储数据
            user_db = User()
            user = user_db.query.filter_by(username=username).all()
            # 判断用户名唯一性
            if user:
                return render_template('user/register.html', msg='用户名已存在!')

            user_db.username = username
            user_db.password = hashlib.sha256(password.encode('utf-8')).hexdigest()  # 密码加密
            user_db.phone = phone

            # 将一条数据添加入数据库中,session相当于缓存
            db.session.add(user_db)
            db.session.commit()

            # # 使用列表的方式存储数据
            # user = User_value(username, password, phone)
            # # 将user对象加入users列表中
            # users.append(user)
            # print(url_for('user.center'))  # 反响解析
            return redirect(url_for('user.center'))
        else:
            return render_template('user/register.html', msg='两次密码不一致!')

    return render_template('user/register.html')
Example #12
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.sha256(
                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')