Esempio n. 1
0
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        user = mongodb.get_user(form.username.data)
        if user:
            return jsonify(error(30006))
        mongodb.add_user(form.fullname.data, form.email.data, form.address.data,
                         form.username.data, md5(form.password.data))
        return jsonify(ok('/admin/'))
    else:
        return jsonify(error(30004))
Esempio n. 2
0
def login():
    form = LoginForm(request.form)
    forget_form = ForgetForm(request.form)
    reg_form = RegisterForm(request.form)
    form_type = convert_str2int(request.values.get('form_type', 0))
    if request.method == 'POST':
        if form.validate_on_submit():
            user = mongodb.get_user(form.username.data)
            if user:
                if user['password'] == md5(form.password.data):
                    # session保存登录用户名和头像
                    session[LOGIN_USER_ID] = str(user['_id'])
                    session[LOGIN_USERNAME] = form.username.data
                    session[LOGIN_USER_HEADER_IMAGE] = user['header_img']
                    return jsonify(ok('/admin/'))
                else:
                    return jsonify(error(30001))
            else:
                return jsonify(error(30002))
        else:
            return jsonify(error(30003))

    return render_template('admin/login.html', form=form, forget_form=forget_form,
                           reg_form=reg_form, form_type=form_type)