Пример #1
0
def user_regist():  # 注册
    if request.method == "POST":
        # print(request.form)
        user = User()
        user.name = request.form["user_name"]
        user.pwd = request.form["user_pwd"]
        user.age = request.form["user_age"]
        user.birthday = request.form["user_birthday"]
        user.email = request.form["user_email"]
        user.face = request.form["user_face"]

        # 查看用户是否存在
        user_one = query_user_by_name(user.name)
        if user_one:
            # 返回注册界面,重新注册
            flash("用户名已存在!", category="err"
                  )  # Flashes a message to the next request 闪现一条消息到下一次消息请求

            return render_template("user_regist.html")

        # 如果不存在执行插入操作
        # 插入一条数据
        instert_user_to_db(user)
        flash("注册成功!", category="ok")
        # username作为查询参数带到url中去
        ## 重定向页面 生成url 执行 user_login 函数 跳转到登录界面
        return redirect(url_for("user_login", username=user.name))
    return render_template("user_regist.html")
Пример #2
0
def user_regist():
    form = RegistForm()
    if form.validate_on_submit():
        user = User()
        user.name = form.user_name.data
        user.pwd = form.user_pwd.data
        user.email = form.data['user_email']
        user.age = form.user_edge.data
        user.birthday = form.data["user_birthday"]
        # filestorage = form.user_face.data
        filestorage = request.files["user_face"]
        print(filestorage)
        user.face = filestorage.filename
        print(user.face)
        # 查看用户名是否已经存在
        user_x = query_user_by_name(user.name)
        if user_x:
            flash("用户名已经存在!", category='err')
            return render_template('user_regist.html', form=form)
        # 如果用户不存在,执行插入操作
        insert_user_to_db(user)
        # 保存用户头像文件
        filestorage.save(filestorage.filename)
        flash("用户注册成功!", category='ok')
        return redirect(url_for("user_login", username=user.name))
    return render_template('user_regist.html', form=form)
Пример #3
0
def user_regist():
    regForm = RegistForm()
    if regForm.validate_on_submit():
        if not check_files_ext([regForm.user_face.data.filename],
                               ALLOWED_IMAGE_EXT):
            flash(message=u'上传的图片格式不支持!', category='error')
            return render_template('user_regist.html', form=regForm)
        user = User()
        user.name = request.form['user_name']
        user.pwd = request.form['user_pwd']
        user.email = request.form['user_email']
        user.age = request.form['user_age']
        user.birthday = request.form['user_birthday']
        f = request.files['user_face']
        user.face = change_filename_to_uuid(f.filename)
        user_x = query_user_by_name(user.name)
        if user_x:
            flash(u"用户名已经存在!", category='error')
            return render_template('user_regist.html', form=regForm)
        insert_user_to_db(user)
        userfolder = os.path.join(app.config["UPLOAD_FOLDER"], user.name)
        if not os.path.exists(userfolder):
            os.mkdir(userfolder, os.O_RDWR)
        f.save(os.path.join(userfolder, user.face))
        flash(u"注册成功", category='ok')
        return redirect(url_for("user_login", username=user.name))
    return render_template('user_regist.html', form=regForm)
Пример #4
0
def user_info():
    infoForm = ChangeInfoForm()
    user_old = query_user_by_name(session.get('user_name'))
    if infoForm.validate_on_submit():
        user = User()
        user.name = request.form.get(
            'user_name') if request.form['user_name'] else user_old.name
        user.email = request.form.get(
            'user_email') if request.form['user_email'] else user_old.email
        user.age = request.form.get(
            'user_age') if request.form['user_age'] else user_old.age
        user.birthday = request.form.get(
            'user_birthday'
        ) if request.form['user_birthday'] else user_old.birthday
        user.face = request.form.get(
            'user_face') if request.form['user_face'] else user_old.face
        update_user_by_name(
            user_old.name, {
                "name": user.name,
                "email": user.email,
                "age": user.age,
                "birthday": user.birthday,
                "face": user.face
            })
        session['user_name'] = user.name
        return redirect(url_for("user_detail"))
    return render_template("user_info.html", user=user_old, form=infoForm)
Пример #5
0
def user_regist():
    if request.method == 'POST':
        print(request.form)
        user = User()
        user.name = request.form["user_name"]
        user.pwd = request.form["user_pwd"]
        user.email = request.form['user_email']
        user.age = request.form['user_age']
        user.birthday = request.form['user_birthday']
        user.face = request.form['user_face']
        print(user.name)
        return redirect(url_for("user_login", username=user.name))
    return render_template('user_regist.html')
Пример #6
0
def load_users(session):
    with open('seed_data/u.user', 'rb') as csvfile:
        userreader = csv.reader(csvfile, delimiter = '|')
        for userrow in userreader:
            u = User() 
            u.id = userrow[0]
            u.age = userrow[1]
            u.gender = userrow[2]
            u.occupation = userrow[3]
            u.zipcode = userrow[4]
            u.email = None
            u.password = None

            session.add(u)
Пример #7
0
def user_regist():  # 注册
    form = RegistForm()
    if form.validate_on_submit(
    ):  # 检查提交方式是否为post 验证forms.py定义的validators 验证是否通过
        # print("form", form.user_name.data)
        # print("form", form.data)
        # print("form", form.data["user_name"])
        # print("request.form", request.form)
        user = User()
        # user.name = request.form["user_name"]
        user.name = form.user_name.data
        # user.pwd = request.form["user_pwd"]
        user.pwd = form.user_pwd.data
        # user.age = request.form["user_age"]
        user.age = form.user_age.data
        # user.birthday = request.form["user_birthday"]
        user.birthday = form.user_birthday.data
        # user.email = request.form["user_email"]
        user.email = form.user_email.data
        # user.face = request.form["user_face"]
        # user.face = form.user_face.data
        # filerstorage=form.user_face.data
        filerstorage = request.files["user_face"]  # 获取头像文件
        user.face = filerstorage.filename

        # 查看用户是否存在
        user_one = query_user_by_name(user.name)
        if user_one:
            # 返回注册界面,重新注册
            flash("用户名已存在!", category="err"
                  )  # Flashes a message to the next request 闪现一条消息到下一次消息请求

            return render_template("user_regist.html", form=form)

        # 如果不存在执行插入操作
        # 插入一条数据
        instert_user_to_db(user)
        # 保存用户头像文件
        filerstorage.save(user.face)
        flash("注册成功!", category="ok")
        # username作为查询参数带到url中去
        ## 重定向页面 生成url 执行 user_login 函数 跳转到登录界面
        return redirect(url_for("user_login", username=user.name))
    return render_template("user_regist.html", form=form)
Пример #8
0
def user_regist():
    if request.method == "POST":
        user = User()
        user.name = request.form["user_name"]
        user.pwd = request.form["user_pwd"]
        user.email = request.form["user_email"]
        user.age = request.form["user_edge"]
        user.birthday = request.form["user_birthday"]
        user.face = request.form["user_face"]
        # 查看用户名是否已经存在
        user_x = query_user_by_name(user.name)
        if user_x:
            flash("用户名已经存在!", category='err')
            return render_template('user_regist.html')
        # 如果用户不存在,执行插入操作
        insert_user_to_db(user)
        flash("用户注册成功!", category='ok')
        return redirect(url_for("user_login", username=user.name))
    return render_template('user_regist.html')
Пример #9
0
def user_regist():
    if request.method == 'POST':
        user = User()
        user.name = request.form.get('user_name')
        user.pwd = request.form.get('user_pwd')
        user.email = request.form.get('user_email')
        user.age = request.form.get('user_age')
        user.birthday = request.form.get('user_birthday')
        user.face = request.form.get('user_face')
        user_x = query_user_by_name(user.name)
        if user_x:
            flash('用户名已经存在,请更换用户名注册', category='err')

            return render_template('user_regist.html')

        insert_user_to_db(user)
        flash('恭喜您注册成功', category='ok')
        return redirect(url_for('user_login', username=user.name))
    return render_template('user_regist.html')