當前位置: 首頁>>代碼示例>>Python>>正文


Python models.User類代碼示例

本文整理匯總了Python中app.users.models.User的典型用法代碼示例。如果您正苦於以下問題:Python User類的具體用法?Python User怎麽用?Python User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了User類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: oauth_callback

def oauth_callback(provider):
    if not current_user.is_anonymous():
        return redirect(url_for('simple_page.index'))

    oauth = OAuthSignIn.get_provider(provider)
    social_id, username, email = oauth.callback()
    if social_id is None:
        flash(getttext(u'Authentication failed'), 'danger')
        return redirect(url_for('simple_page.index'))

    # check if user exists and if no creates new
    user = User.query.filter_by(social_id=social_id).first()
    if user is None:
        user = User(
            username=username,
            password='',
            email=email,
            social_id=social_id
        )
        db.session.add(user)
        db.session.commit()

    login_user(user, remember=True)
    user.update_login_info()
    return redirect(url_for('simple_page.index'))
開發者ID:VirrageS,項目名稱:przygoda,代碼行數:25,代碼來源:views.py

示例2: create

def create():
    args = ['username', 'realname', 'email', 'pw', 'phone']
    result = ''
    try:
        for i in args:
            assert i in request.args, 'missing ' + i

        assert len(list(graph_db.find("User","username",request.args['username']))) == 0, "user already exists"
        assert len(list(graph_db.find("User","email",request.args['email']))) == 0, "email already exists"

        u = User(username=request.args['username'],
                 realname=request.args['realname'],
                 email=request.args['email'],
                 password=hash_pw(request.args['pw']),
                 phone=request.args['phone'])

        while True:
            u.userid = randint(app.config['UID_START'],app.config['UID_END'])
            if len(list(graph_db.find("User","id",u.userid))) == 0: break

        u.save()

        result = "user %s created" % u.userid

    except AssertionError, e:
        result = str(e)
開發者ID:Lonapp,項目名稱:at-the-back,代碼行數:26,代碼來源:controllers.py

示例3: after_login

def after_login(resp):
    if resp.email is None or resp.email == "":
        flash(gettext('Invalid login. Please try again.'))
        return redirect(url_for('login_view'))
    user = User.query.filter_by(email = resp.email).first()
    userdetails = UserDetails(user=user)
    if user is None:
        nickname = resp.nickname
        if nickname is None or nickname == "":
            nickname = resp.email.split('@')[0]
        nickname = User.make_valid_nickname(nickname)
        nickname = User.make_unique_nickname(nickname)
        user = User(nickname = nickname, email = resp.email, role = ROLE_USER)
        
        db.session.add(user)
        db.session.add(userdetails)
        db.session.commit()
        # make the user follow him/herself
        db.session.add(user.follow(user))
        db.session.commit()
        
    userdetails = UserDetails.query.filter_by(user=user).first()
    if userdetails is None:
        userdetails = UserDetails(user=user)
        db.session.add(userdetails)
        db.session.commit()
        
    remember_me = False
    if 'remember_me' in session:
        remember_me = session['remember_me']
        session.pop('remember_me', None)
    login_user(user, remember = True)
    return redirect(request.args.get('next') or url_for('main_flow.index'))
開發者ID:nava45,項目名稱:connection,代碼行數:33,代碼來源:views.py

示例4: test_invalid_password_is_rejected

    def test_invalid_password_is_rejected(self):
        User.create(name="Joe", email="[email protected]", password="12345")

        with self.client:
            self.client.post("/login/", data={"name": "Joe", "password": "****"})

            self.assertTrue(current_user.is_anonymous())
開發者ID:KirkHadley,項目名稱:flask-tracking,代碼行數:7,代碼來源:tests.py

示例5: create_test_user

def create_test_user():
    user = User()
    user.vk_id = "24076752"
    user.access_token = "GsPlUf1RVH8AAAAAAAAAAQIpLzXXVtywxpD90ySk8XbSsFO5DoU0dhOlGU4qU5Fc"
    user.expires = datetime.datetime.now() + datetime.timedelta(days=100)
    db.session.add(user)
    db.session.commit()
開發者ID:ledovsky,項目名稱:vk-sms,代碼行數:7,代碼來源:manage.py

示例6: login

def login():
	if request.method == 'POST':
		user = User(name=request.form['username'], passwd = request.form['passwd'])
		if user.is_active():
			login_user(user)
			redirect(url_for('frontend.home'))
	redirect(url_for('frontend.login'))
開發者ID:scgodbold,項目名稱:flaskFramework,代碼行數:7,代碼來源:views.py

示例7: setup_user

def setup_user(oauth_provider, oauth_id, display_name, image_url):
    key = dict(
        oauth_id = unicode(oauth_id),
        oauth_provider = oauth_provider
        )
    slugs = set(u.display_slug for u in User.query.all())
    user = User.query.filter_by(**key).first()
    if not user:
        user = User(**key)
        db.session.add(user)
    user.display_slug = slugify_unique(display_name, slugs)
    user.display_name = display_name
    user.oauth_token, user.oauth_secret = session['oauth']

    # Load image
    s = StringIO()
    im = im_open(StringIO(req_get(image_url).content))
    im.thumbnail((128, 128), ANTIALIAS)
    im.save(s, 'JPEG')
    user.image = s.getvalue()

    db.session.commit()
    login_user(user, remember = True)
    # Why do i need this?
    del session['oauth']
    return redirect('/static/auth_recv.html')
開發者ID:bjourne,項目名稱:vvm,代碼行數:26,代碼來源:views.py

示例8: register

def register():
  """
  Registration Form
  """
  form = RegisterForm(request.form)
  if form.validate_on_submit():
    # create an user instance not yet stored in the database
    user = User(username=form.name.data,
                email=form.email.data,
                password=generate_password_hash(form.password.data)
    )
    #current_user=True)
    # Insert the record in our database and commit it
    try:
      user.save()
    except errors.NotUniqueError:
      return render_template("users/register.html",
                             form=form,
                             duplicate=True,
                             user=None)
    except:
      raise

    # Log the user in, as he now has an id
    session['user_id'] = str(user.id)
    session['user'] = user.username
    print "session user_id: %s" % (str(user.id))
    # flash will display a message to the user
    #flash('Thanks for registering')
    # redirect user to the 'home' method of the user module.
    return redirect(url_for('users.home'))
  return render_template("users/register.html", form=form, user=None)
開發者ID:arcolife,項目名稱:digGit,代碼行數:32,代碼來源:views.py

示例9: register

def register():
    email = request.form['email']
    username = request.form['username']
    password = request.form['password'].encode('utf8')
    salt = generate_random_salt()
    password_hash = generate_password_hash(password, salt)

    # Check if email already exist in database
    # if account does not exist create account in database

    if User.objects(email=email).first() == None:
        user = User(email=email)
        user.accounts['internal'] = {"username":username, "password_hash":password_hash, \
                "salt":salt}
        user.save()
        ret = json_util.dumps({"message":"account created", "status":"success"})
        resp = Response(response=ret,
                        status=201,
                        mimetype="application/json")
        return resp
    else:
        ret = json_util.dumps({"message":"Email already exist in database"})
        resp = Response(response=ret,
                        status=200,
                        mimetype="application/json")
        return resp
開發者ID:cryptojuice,項目名稱:goodmusic,代碼行數:26,代碼來源:views.py

示例10: test_users_can_logout

    def test_users_can_logout(self):
        User.create(name="Joe", email="[email protected]", password="12345")

        with self.client:
            self.client.post("/login/", data={"name": "Joe", "password": "12345"})
            self.client.get("/logout/")

            self.assertTrue(current_user.is_anonymous())
開發者ID:KirkHadley,項目名稱:flask-tracking,代碼行數:8,代碼來源:tests.py

示例11: add_admin

def add_admin():
    """Adds admin to database"""
    admin = User.query.filter_by(username="admin").first()
    if admin is None:
        new_admin = User("admin", generate_password_hash("supertajnehaslo"), "[email protected]", social_id=None)
        new_admin.role = USER.ADMIN
        new_admin.confirmed = True
        db.session.add(new_admin)
        db.session.commit()
開發者ID:VirrageS,項目名稱:przygoda,代碼行數:9,代碼來源:miscellaneous.py

示例12: test_users_can_login

    def test_users_can_login(self):
        User.create(name="Joe", email="[email protected]", password="12345")

        with self.client:
            response = self.client.post("/login/", data={"name": "Joe", "password": "12345"})

            self.assert_redirects(response, url_for("index"))
            self.assertTrue(current_user.name == "Joe")
            self.assertFalse(current_user.is_anonymous())
開發者ID:KirkHadley,項目名稱:flask-tracking,代碼行數:9,代碼來源:tests.py

示例13: add_users

def add_users():
    form = AddUserForms(request.form)
    all_users = User.query.all()
    form.select_role.choices = [(role.id, role.name)        ## Loads up choices
                                for role in Role.query.all()] 
    ## load roles that had supervisor roles in it:
 

    form.select_supervisor.choices = [(user.username, user.username)
                                     for user in User.query.all() if user.is_supervisor]

    print form.select_role.choices 
    if form.validate_on_submit():
        password = generate_password_hash('seer')       
        u = User (form.fname.data,form.midname.data,form.lname.data,    ## Load user
                  form.email.data,form.username.data,password)
        print form.select_role.data

        for i in form.select_role.data:  ## Loads up the selected choices of the user
            print i 
            u.role.append(Role.query.get(i))
        print u.role

        ##Checks if the user is a supervisor
        if form.check_if_supervisor.data:
            u.is_supervisor = True

        ## Loads up the supervisor of the user, and loads up the user to its supervisor
        u.supervisor = form.select_supervisor.data
        print form.select_supervisor.data

        supervisor = User.query.filter_by(username=form.select_supervisor.data).first()
        if supervisor.supervisee is None or '': 
            
            supervisor.supervisee = u.username
            print supervisor.supervisee
        else:
            supervisor.supervisee = supervisor.supervisee + ' ' + u.username
            print supervisor.supervisee

        db_session.add(u)
        db_session.add(supervisor)
        db_session.commit()

        us = UserStatistics(userId=u.id)
        us.sl = form.number_of_sick_leaves.data
        us.vl = form.number_of_vacation_leaves.data
        us.offset = 0
        db_session.add(us)
        db_session.commit()
        flash('User Created')
        return redirect(url_for('Users.add_users'))
    return render_template('admin/add_user.html', form = form)
開發者ID:blouiecubero,項目名稱:projectIRIS,代碼行數:53,代碼來源:controllers.py

示例14: test_make_unique_name

 def test_make_unique_name(self):
     user = User(name='john', email='[email protected]')
     db.session.add(user)
     db.session.commit()
     name = User.make_unique_name('john')
     self.assertEqual(name, 'john2')
     # use the new name
     user = User(name=name, email='[email protected]')
     db.session.add(user)
     db.session.commit()
     new_name = User.make_unique_name('john')
     self.assertEqual(new_name, 'john3')
開發者ID:dingweihua,項目名稱:microblog,代碼行數:12,代碼來源:test_models.py

示例15: register_view

def register_view():
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User()
        form.populate_obj(user)
	user.initials = user.initials.upper()
	user.generate_password_hash(user.password)
        session.add(user)
        session.commit()
        login_user(user)
        return redirect(url_for('index'))
    return render_template('users/register.html', form=form)
開發者ID:bhoward00,項目名稱:peercoui,代碼行數:12,代碼來源:views.py


注:本文中的app.users.models.User類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。