Example #1
0
def create_app(config_name):
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'PyFly123'
    app.config.from_object(config[config_name])
    init_extensions(app)
    init_func(app)
    config_blueprint(app)
    with app.app_context():
        app.config['MAIL_SUBJECT_PREFIX'] = db_utils.get_option('mail_prefix') or app.config['MAIL_SUBJECT_PREFIX']
        install_init()
    return app
Example #2
0
def user_sign():
    date = datetime.utcnow().strftime('%Y-%m-%d')
    user = current_user.user
    doc = {'user_id': user['_id'], 'date': date}
    sign_log = mongo.db['user_signs'].find_one(doc)
    if sign_log:
        return jsonify(code_msg.REPEAT_SIGNED)
    interval = db_utils.get_option('sign_interval',
                                   {'val': '1-100'})['val'].split('-')
    coin = random.randint(int(interval[0]), int(interval[1]))
    doc['coin'] = coin
    mongo.db['user_signs'].insert_one(doc)
    mongo.db.users.update({'_id': user['_id']}, {'$inc': {'coin': coin}})
    return jsonify(models.R.ok(data={'signed': True, 'coin': coin}))
Example #3
0
def register():
    if db_utils.get_option('open_user', {}).get('val') != '1':
        abort(404)
    user_form = forms.RegisterForm()
    if user_form.is_submitted():
        if not user_form.validate():
            return jsonify(
                models.R.fail(code_msg.PARAM_ERROR.get_msg(),
                              str(user_form.errors)))
        utils.verify_num(user_form.vercode.data)
        user = mongo.db.users.find_one({'email': user_form.email.data})
        if user:
            return jsonify(code_msg.EMAIL_EXIST)
        #以字典的形式存储用户注册时所填写的信息
        user = dict({
            'is_active':
            False,
            'coin':
            0,
            'email':
            user_form.email.data,
            'username':
            user_form.username.data,
            'vip':
            0,
            'reply_count':
            0,
            'avatar':
            url_for('static',
                    filename='images/avatar/' + str(randint(0, 12)) + '.jpg'),
            'password':
            generate_password_hash(user_form.password.data),
            'create_at':
            datetime.utcnow()
        })
        #向mongo数据库插入此用户的这条数据
        mongo.db.users.insert_one(user)
        send_active_email(user['username'], user['_id'], user['email'])
        return jsonify(
            code_msg.REGISTER_SUCCESS.put('action', url_for('user.login')))
    ver_code = utils.gen_verify_num()
    # session['ver_code'] = ver_code['answer']
    #title会传给base页面的变量title,会在对应的页面标签显示
    return render_template('user/reg.html',
                           ver_code=ver_code['question'],
                           form=user_form,
                           title='注册')