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


Python User.new_user方法代码示例

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


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

示例1: dummy_data

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def dummy_data():
    # Dummy test users
    for i in xrange(4):
        User.new_user(
            email='dummy{0}@dummy.com'.format(i), username='dummy{0}'.format(i),
            password='dummy', management_api=pulse_management)

    users = User.query.all()

    # And some dummy queues
    dummy_queue = Queue(name='dummy-empty-queue', size=0, owner=users[0])
    db_session.add(dummy_queue)
    db_session.commit()

    dummy_queue = Queue(name='dummy-non-empty-queue', size=config.warn_queue_size/5, owner=users[0])
    db_session.add(dummy_queue)
    db_session.commit()

    dummy_queue = Queue(name='dummy-warning-queue', size=config.warn_queue_size + 1, owner=users[1])
    db_session.add(dummy_queue)
    db_session.commit()

    dummy_queue = Queue(name='dummy-deletion-queue', size=int(config.del_queue_size * 1.2), owner=users[2])
    db_session.add(dummy_queue)
    db_session.commit()

    # Test admin user
    User.new_user(
        email='[email protected]', username='dummy-admin', password='dummy-admin',
        management_api=pulse_management, admin=True)

    logger.info('Finished generating dummy data.')
开发者ID:ewongbb,项目名称:pulseguardian,代码行数:34,代码来源:dbinit.py

示例2: register_handler

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def register_handler():
    username = request.form['username']
    password = request.form['password']
    email = session['email']
    errors = []

    if not re.match('^[a-z0-9]+$', username):
        errors.append("The submitted username contains non-alphanumeric characters")
    if User.query.filter(User.email == email).first():
        errors.append("A user with the same email already exists")
    if not User.strong_password(password):
        errors.append("Your password must contain a mix of letters and numerical characters and be at least 6 characters long")

    # Checking if a user exists in RabbitMQ OR in our db
    try:
        pulse_management.user(username=username)
        in_rabbitmq = True
    except PulseManagementException:
        in_rabbitmq = False

    if in_rabbitmq:
        errors.append("A user with the same username already exists in Pulse")
    if User.query.filter(User.username == username).first():
        errors.append("A user with the same username already exists in our database")
    if errors:
        signup_error = "{0}.".format(', '.join(errors))
        return render_template('register.html', email=email, signup_error=signup_error)

    user = User.new_user(email=email, username=username, password=password, management_api=pulse_management)
    db_session.add(user)
    db_session.commit()

    return render_template('confirm.html')
开发者ID:ewongbb,项目名称:pulseguardian,代码行数:35,代码来源:web.py

示例3: auth_handler

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def auth_handler():
    # The request has to have an assertion for us to verify
    if 'assertion' not in request.form:
        return jsonify(ok=False, message="Assertion parameter missing")

    # Send the assertion to Mozilla's verifier service.
    data = dict(assertion=request.form['assertion'],
                audience=config.persona_audience)
    resp = requests.post(config.persona_verifier, data=data, verify=True)

    # Did the verifier respond?
    if resp.ok:
        # Parse the response
        verification_data = resp.json()
        if verification_data['status'] == 'okay':
            email = verification_data['email']
            session['email'] = email

            user = User.query.filter(User.email == email).first()
            if user is None:
                user = User.new_user(email=email)

            if user.pulse_users:
                return jsonify(ok=True, redirect='/')

            return jsonify(ok=True, redirect='/register')

    # Oops, something failed. Abort.
    error_msg = "Couldn't connect to the Persona verifier ({0})".format(
        config.persona_verifier)
    logging.error(error_msg)
    return jsonify(ok=False, message=error_msg)
开发者ID:abhi12ravi,项目名称:pulseguardian,代码行数:34,代码来源:web.py

示例4: create_user

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def create_user():
    email, username, password = request.json['email'], request.json['username'], request.json['password']
    try:
        user = User.new_user(email=email, username=username, password=password).save()
        # TODO : restrict information returned ? (security)
        return jsonify(ok=True, result=user.to_dict())
    except mongoengine.ValidationError as e:
        return jsonify(ok=False, result=e.message)
开发者ID:INSA-4IF-SpecIFic,项目名称:elif,代码行数:10,代码来源:api.py

示例5: load_fake_account

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def load_fake_account(fake_account):
    """Load fake user and setup session."""

    # Set session user.
    session['email'] = fake_account
    session['fake_account'] = True

    # Check if user already exists in the database, creating it if not.
    g.user = User.query.filter(User.email == fake_account).first()
    if g.user is None:
        g.user = User.new_user(email=fake_account)
开发者ID:abhi12ravi,项目名称:pulseguardian,代码行数:13,代码来源:web.py

示例6: test_user

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
    def test_user(self):
        user = User.new_user(email='[email protected]', username='dummy',
                             password='DummyPassword', management_api=None)
        db_session.add(user)
        db_session.commit()

        self.assertIn(user, User.query.all())
        # Emails are normalized by putting them lower-case
        self.assertEqual(User.query.filter(User.email == '[email protected]').first(), user)
        self.assertEqual(User.query.filter(User.username == 'dummy').first(), user)
        self.assertIsNone(User.query.filter(User.username == 'DOMMY').first())
开发者ID:ewongbb,项目名称:pulseguardian,代码行数:13,代码来源:runtests.py

示例7: process_signup

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def process_signup():
    email, username, password = request.form['email'].lower(), request.form['username'], request.form['password']
    user = User.new_user(email=email, username=username, password=password, editor=False)
    try:
        user.save()
        session['logged_in'] = user.email
        inject_user()
        load_user()
        return redirect('/')
    except mongoengine.ValidationError as e:
        return render_template('signup.html', error=e.to_dict())
开发者ID:INSA-4IF-SpecIFic,项目名称:elif,代码行数:13,代码来源:web.py

示例8: update_queue_information

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
    def update_queue_information(self, queue_data):
        if not 'messages' in queue_data:
            # FIXME: We should do something here, probably delete the queue,
            # as it's in a weird state.  More investigation is required.
            # See bug 1066338.
            return None

        q_size, q_name = (queue_data['messages'],
                          queue_data['name'])
        queue = Queue.query.filter(Queue.name == q_name).first()

        # If the queue doesn't exist in the db, create it.
        if queue is None:
            logger.info("New queue '{0}' encountered. "
                        "Adding to the database.".format(q_name))
            queue = Queue(name=q_name, owner=None)

        # Update the saved queue size.
        queue.size = q_size
        db_session.add(queue)
        db_session.commit()

        # If we don't know who created the queue...
        if queue.owner is None:
            logger.debug("Queue '{0}' owner's unknown.".format(q_name))

            # If no client is currently consuming the queue, just skip it.
            if queue_data['consumers'] == 0:
                logger.debug("Queue '{0}' skipped (no owner, no current consumer).".format(q_name))
                return queue

            # Otherwise look for its user.
            owner_name = self.api.queue_owner(queue_data)

            user = User.query.filter(User.username == owner_name).first()

            # If the queue was created by a user that isn't in the
            # pulseguardian database, skip the queue.
            if user is None:
                logger.info(
                    "Queue '{0}' owner, {1}, isn't in the db. Creating the user.".format(q_name, owner_name))
                user = User.new_user(username=owner_name, email='', password='',
                                     management_api=None)

            # Assign the user to the queue.
            logger.info(
                "Assigning queue '{0}' to user {1}.".format(q_name, user))
            queue.owner = user
            db_session.add(queue)
            db_session.commit()

        return queue
开发者ID:ewongbb,项目名称:pulseguardian,代码行数:54,代码来源:guardian.py

示例9: load_user

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def load_user():
    """Loads the currently logged-in user (if any) to the request context."""

    # Check if fake account is set and load user.
    if fake_account:
        load_fake_account(fake_account)
        return

    email = session.get('email')
    if not email:
        g.user = None
        return

    g.user = User.query.filter(User.email == session.get('email')).first()
    if not g.user:
        g.user = User.new_user(email=email)
开发者ID:abhi12ravi,项目名称:pulseguardian,代码行数:18,代码来源:web.py

示例10: setUp

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
    def setUp(self):
        init_and_clear_db()
        self.management_api = PulseManagementAPI()
        self.guardian = PulseGuardian(self.management_api, warn_queue_size=TEST_WARN_SIZE,
                                      del_queue_size=TEST_DELETE_SIZE, emails=False)

        self.consumer_cfg = pulse_cfg.copy()
        self.consumer_cfg['applabel'] = str(uuid.uuid1())

        # Configure / Create the test user to be used for message consumption
        self.consumer_cfg['user'], self.consumer_cfg['password'] = CONSUMER_USER, CONSUMER_PASSWORD
        username, password = self.consumer_cfg['user'], self.consumer_cfg['password']
        self.user = User.new_user(username=username, email=CONSUMER_EMAIL,
                                  password=password, management_api=self.management_api)
        db_session.add(self.user)
        db_session.commit()

        self.publisher = self.publisher_class(**pulse_cfg)
开发者ID:ewongbb,项目名称:pulseguardian,代码行数:20,代码来源:runtests.py

示例11: gen_db

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def gen_db():
    # DB init
    db = mongoengine.connect(config.db_name)
    db.drop_database(config.db_name)
    print '. Dropped database'

    dummy = User.new_user('[email protected]', 'ahmed.kachkach', 'ahmed.kachkach')
    dummy.save()

    # GLSL init
    glsl_scene = boiler_scene(dummy, title="Dummy Scene", description="Just a random dummy scene")
    glsl_scene.save()

    another_glsl_scene = boiler_scene(dummy, title="Another Dummy Scene", description="And here you go : yet another dummy scene.")
    another_glsl_scene.save()

    pyramideScene = pyramide_scene(dummy, title="Pyramide", description="Pyramide of balls")
    pyramideScene.save()

    #Rendering.create(width=1000, height=600, samples=16, scene=glsl_scene).save()
    Rendering.create(width=1366, height=768, samples=64, scene=another_glsl_scene, max_iterations=5).save()
    Rendering.create(width=1366, height=768, samples=128, scene=pyramideScene, max_iterations=5).save()

    print '. Generated dummy data !'
开发者ID:RenderMen,项目名称:RenderMen,代码行数:26,代码来源:gen_db.py

示例12: test_db

# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import new_user [as 别名]
def test_db():
    """ Wipes the database and initializes it with some dummy data """
    db = mongoengine.connect(config.db_name)
    db.drop_database(config.db_name)

    # Dummy users
    User.new_user(email="[email protected]{}".format(config.email_domain),
                  username="dummy_user", password="123456", editor=False).save()

    # Other dummmy users
    for i in xrange(8):
        User.new_user(email="dummy{}@{}".format(i + 1, config.email_domain),
                      username="dummy_user{}".format(i+1), password="123456", editor=False).save()

    # Editor user
    editor = User.new_user(email="[email protected]{}".format(config.email_domain),
              username="editor_user", password="123456", editor=True).save()

    # Other editor users
    for i in xrange(8):
        User.new_user(email="editor{}@{}".format(i + 1, config.email_domain),
                      username="editor_user{}".format(i+1), password="123456", editor=True).save()


    # Dummy exercises
    for i in xrange(8):
        test1 = Test(input='1\n', output='1').save()
        test2 = Test(input='2\n', output='2').save()
        test3 = Test(input='2\n', output='2').save()

        exercise = Exercise(author=editor, title="Dummy exercise {}".format(i),
                            description="## This is an exercise\n\n" +
                                        "* You get a single number as an input\n" +
                                        "* Simply return that number as an output\n",
                            boilerplate_code=config.default_boilerplate_code, reference_code=config.default_boilerplate_code, tags=['sort','trees'])

        exercise.tests = [test1, test2, test3]
        exercise.published = True
        exercise.save()

    # "Doable" exercise
    exercise = Exercise(author=editor, title="Return n²",
                    description="### Return the given number to the 2 !\n\n" +
                                "* You get a\n" +
                                "* Print a²\n" +
                                "![Alt text](/static/img/cat.jpeg)",
                    boilerplate_code=config.default_boilerplate_code,
                    reference_code=config.default_boilerplate_code,
                    tags=['algorithms'])
    test1 = Test(input='1\n', output='1').save()
    test2 = Test(input='2\n', output='4').save()
    test3 = Test(input='-2\n', output='4').save()
    exercise.tests = [test1, test2, test3]
    exercise.published = True
    exercise.save()

    # Palindrome exercise
    reference_code = """
#include <iostream>
#include <stack>
#include <sstream>
using namespace std;

struct node {
    node* next;
    int data;
    explicit node(int data):node(nullptr,data){}
    node(node* head,int data):next(head),data(data){}
};

node* insert(node* head,int data){
    return new node(head,data);
}

bool is_palindrome(node* head){
    auto temp = head;
    std::stack<node*> s;
    while(nullptr != temp){
        s.push(temp);
        temp = temp->next;
    }
    while(!s.empty()){
        if(head->data != s.top()->data){
            return false;
        }
        s.pop();
        head = head->next;
    }
    return true;
}

int main() {
    string line;
    while(getline(cin,line)){
        istringstream iss(line);
        int value;
        if(iss >> value){
            auto l = insert(nullptr,value);
            while(iss >> value){
                l = insert(l,value);
#.........这里部分代码省略.........
开发者ID:INSA-4IF-SpecIFic,项目名称:elif,代码行数:103,代码来源:utils.py


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