当前位置: 首页>>代码示例>>Python>>正文


Python User.add方法代码示例

本文整理汇总了Python中models.User.add方法的典型用法代码示例。如果您正苦于以下问题:Python User.add方法的具体用法?Python User.add怎么用?Python User.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User的用法示例。


在下文中一共展示了User.add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import add [as 别名]
    def run(self, username, password):
        if User.query.filter_by(username=username).first() is not None:
            raise InvalidCommand("User with this username already exists")

        user = User(username, username.title(), password, True)
        user.add(user)
        print ("Superuser `%s` created successfully" % username)
开发者ID:sreekanthkaralmanna,项目名称:bookmyhotel,代码行数:9,代码来源:manage.py

示例2: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import add [as 别名]
 def post(self):
     request_dict = request.get_json()
     if not request_dict:
         response = {'user': 'No input data provided'}
         return response, status.HTTP_400_BAD_REQUEST
     errors = user_schema.validate(request_dict)
     if errors:
         return errors, status.HTTP_400_BAD_REQUEST
     name = request_dict['name']
     existing_user = User.query.filter_by(name=name).first()
     if existing_user is not None:
         response = {'user': 'An user with the same name already exists'}
         return response, status.HTTP_400_BAD_REQUEST
     try:
         user = User(name=name)
         error_message, password_ok = \
             user.check_password_strength_and_hash_if_ok(request_dict['password'])
         if password_ok:
             user.add(user)
             query = User.query.get(user.id)
             result = user_schema.dump(query).data
             return result, status.HTTP_201_CREATED
         else:
             return {"error": error_message}, status.HTTP_400_BAD_REQUEST
     except SQLAlchemyError as e:
         db.session.rollback()
         resp = {"error": str(e)}
         return resp, status.HTTP_400_BAD_REQUEST
开发者ID:xianjunzhengbackup,项目名称:code,代码行数:30,代码来源:views.py

示例3: add_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import add [as 别名]
def add_user():
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    age = request.form.get('age', '')

    #检查用户信息
    _is_ok, _error = User.validate_add(username, password, age)
    if _is_ok:
        User.add(request.form)      #检查ok,添加用户信息
    return json.dumps({'is_ok':_is_ok, "error":_error})
开发者ID:ryan2333,项目名称:reboot,代码行数:12,代码来源:views.py

示例4: complete_command

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import add [as 别名]
    def complete_command(user_state, command_code, chat_message, router):
        view_render_extras = {} #need to add this data to update a view instead of redrawing

        user_view, view_params = router.get_view(user_state, command_code, chat_message.chat_id)

        temp_view_params_text = view_params['text']
        key_code = 0
        sms_code = UserState.get_command_value(chat_message.chat_id, user_state, command_code)
        error = ""
        phone_number = UserState.get_command_value(chat_message.chat_id, user_state, UserState.STATE_UNAUTH_C_GET_PHONE)
        phone_number_formatted = phone_number[0] + '-' + phone_number[1:4] + '-' + phone_number[4:7] + '-' + phone_number[7:]

        if (chat_message.message_type == ChatMessage.UPDATE_TYPE_CALLBACK):
            key_code = int(chat_message.data)
            sms_code, view_render_extras = VerifyPhoneController.update_sms_code_by_callback(chat_message, view_params, sms_code)

        #processing voice message
        elif chat_message.has_voice:
            sms_code, view_render_extras = VerifyPhoneController.update_sms_code_by_audio(chat_message, view_params, sms_code)

        UserState.set_command_value(chat_message.chat_id, user_state, command_code, sms_code)
        sms_code_formatted = ' '.join('{:-<6s}'.format(sms_code))               
        view_params['text'] = view_params['text'].format(phone_number=phone_number_formatted, sms_code=sms_code_formatted, error=error)
        return_value = None        

        #Handling result
        if ((chat_message.message_type == ChatMessage.UPDATE_TYPE_CALLBACK) and (key_code == ViewParams.KEYBOARD_KEY_OK)
            or (chat_message.voice)):
            try:
                AbstractView.show_toast(chat_message.chat_id, MessageText.STATE_AUTH_LOADING, view_render_extras)
                user_obj = AlfaApi.send_sms_code(phone_number, sms_code)  
                
                User.add(chat_id, "access_token", user_obj['access_token'])
                User.add(chat_id, "refresh_token", user_obj['refresh_token'])

                UserState.set_state(chat_message.chat_id, UserState.STATE_NOCARD, UserState.STATE_NOCARD_C_INIT)
                view_params['text'] = MessageText.MESSAGE_CORRECT_CODE
                view_params.update({'force_remove_inline': True})
                return_value = {'run_next': True}

            except AlfaApiError:
                error = ErrorText.ERROR_WRONG_SMS_CODE
                sms_code = ""
                UserState.set_command_value(chat_message.chat_id, user_state, command_code, sms_code)                
                sms_code_formatted = ' '.join('{:-<6s}'.format(sms_code)) 
                view_params['text'] = temp_view_params_text.format(phone_number=phone_number_formatted, sms_code=sms_code_formatted, error=error)

        user_view.render(**view_params)
        return return_value
开发者ID:dmitry-nosov,项目名称:alfabank_c2c_telegram_bot,代码行数:51,代码来源:controllers.py

示例5: api_create_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import add [as 别名]
def api_create_user():
    """ Creates a new user, with sign up and login the user. """

    username = request.json.get("username")
    password = request.json.get("password")
    realname = request.json.get("realname")
    if username is None or password is None or realname is None:
        abort(400)  # missing arguments
    if User.query.filter_by(username=username).first() is not None:
        return make_response(jsonify({"error": "User with this username already exists"}), 400)  # existing user
    user = User(username, realname, password, False)
    user.add(user)
    flask_login.login_user(user)
    token = user.generate_auth_token()
    session["token"] = token
    return jsonify({"token": token.decode("ascii")})
开发者ID:sreekanthkaralmanna,项目名称:bookmyhotel,代码行数:18,代码来源:app.py

示例6: signup

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import add [as 别名]
def signup():
    if request.method == 'GET':
        signup_form = RegistrationForm()
        return render_template('signup.html', error=False, form=signup_form)
    else:
        signup_form = RegistrationForm(request.form)
        if signup_form.validate():
            user = User.add(email=signup_form.email.data,
                password=signup_form.password.data, first_name=signup_form.first_name.data,
                last_name=signup_form.last_name.data, staff=True)
            session['user'] = user.email
            return redirect(url_for('index'))
        else:
            return render_template('signup.html', error=True, form=signup_form)
开发者ID:yaroslav-dudar,项目名称:prom-ua-test-task,代码行数:16,代码来源:views.py

示例7: reg

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import add [as 别名]
def reg():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index.home'))

    msg = None
    form = RegForm()
    if form.validate_on_submit():
        email = str(form.email.data)
        user = User.get_by_email(email)
        if user:
            msg = '邮箱已存在,请更换邮箱'
        else:
            user = User.add(str(form.name.data), email, str(form.pwd.data))
            if user:
                login_user(user, bool(form.remember_me))
                return redirect(url_for('index.home'))
            else:
                msg = '注册出错'
    return render_template('account/reg.html', msg=msg, form=form)
开发者ID:nocoffe,项目名称:pyweb,代码行数:21,代码来源:account.py

示例8: user_create_view

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import add [as 别名]
def user_create_view(request):

    username = request.authenticated_userid

    if request.method == 'POST':

        try:
            manager = BCRYPTPasswordManager()
            username = request.params.get('username')
            password = request.params.get('password')
            hashed = manager.encode(password)
            email = request.params.get('email')
            user = User.add(
                username=username,
                password=hashed,
                email=email,
            )
            Criteria.add(user=user)
            headers = remember(request, username)

            return HTTPFound(request.route_url('send_email'), headers=headers)
        except:
            return {}
    return {'username': username}
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:26,代码来源:views.py


注:本文中的models.User.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。