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


Python User.username方法代码示例

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


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

示例1: init_db

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
 def init_db(self):
     engine = self.session.get_bind(mapper=None, clause=None)        
     
     inspector = Inspector.from_engine(engine)
     if 'ab_user' not in inspector.get_table_names():
         print "Security DB not found Creating..."
         Base.metadata.create_all(engine)
         print "Security DB Created"
         self.migrate_db()
     if self.session.query(Role).filter_by(name = self.auth_role_admin).first() is None:
         role = Role()
         role.name = self.auth_role_admin
         self.session.add(role)
         self.session.commit()
         print "Inserted Role for public access", self.auth_role_admin            
     if not self.session.query(Role).filter_by(name = self.auth_role_public).first():
         role = Role()
         role.name = self.auth_role_public
         self.session.add(role)
         self.session.commit()
         print "Inserted Role for public access", self.auth_role_public
     if not self.session.query(User).all():
         user = User()
         user.first_name = 'Admin'
         user.last_name = 'User'
         user.username = 'admin'
         user.password = 'general'
         user.active = True
         user.role = self.session.query(Role).filter_by(name = self.auth_role_admin).first()
         self.session.add(user)
         self.session.commit()
         print "Inserted initial Admin user"
         print "Login using Admin/general"
开发者ID:Dorianux,项目名称:Flask-AppBuilder,代码行数:35,代码来源:manager.py

示例2: sign_up

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def sign_up():
    _name = request.form['inputName']
    _user_name = request.form['inputUserName']
    _password = request.form['inputPassword']

    username_list = g.sql_session.query(User.username).all()
    if (_user_name,) not in username_list:
        user = User()
        user.name = _name
        user.username = _user_name
        user.password = generate_password_hash(_password)
        user.type = 1

        g.sql_session.add(user)

        try:
            g.sql_session.commit()
        except Exception as e:
            flash(str(e))
            g.sql_session.rollback()
            return redirect(url_for('.show_sign_up'))

        session['user'] = _user_name
        session['name'] = _name
        session['type'] = user.type
        return redirect(url_for('.user_home'))

    else:
        flash("The duplicated username")
        return redirect(url_for('.show_sign_up'))
开发者ID:ysrotciv,项目名称:dailytask,代码行数:32,代码来源:route.py

示例3: login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def login():
    admin_user = User.query.filter_by(username='admin').first()
    if not admin_user:
        if request.method == 'POST':
            if 'password' in request.form:
                password_hash, salt = hash_and_salt(request.form['password']) 
                new_user = User()
                new_user.username = 'admin'
                new_user.password = password_hash
                new_user.salt = salt
                db.session.add(new_user)
                db.session.commit()
                flash('Password set successfully. Please log in.')
                return redirect(url_for('webui.login'))
        return render_template('create_password.html')
    if request.method == 'POST':
        if request.form['password']:
                password_hash = hashlib.sha256()
                password_hash.update(admin_user.salt + request.form['password'])
                if admin_user.password == password_hash.hexdigest():
                    session['username'] = 'admin'
                    last_login_time =  admin_user.last_login_time
                    last_login_ip = admin_user.last_login_ip
                    admin_user.last_login_time = datetime.now()
                    admin_user.last_login_ip = request.remote_addr
                    db.session.commit()
                    flash('Logged in successfully.') 
                    if last_login_ip:
                        flash('Last login from ' + last_login_ip + ' on ' + last_login_time.strftime("%d/%m/%y %H:%M"))
                    return redirect(url_for('webui.index'))
                else:
                    flash('Wrong passphrase')
    return render_template('login.html')
开发者ID:security-geeks,项目名称:Ares,代码行数:35,代码来源:__init__.py

示例4: test_get_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def test_get_user():
    user = User()
    user.username = u"test"
    user.set_password("test123")

    assert user.save()
    assert user._id

    q = Question()
    q.question = u"test"
    q.author = u"anon"
    q.user = user.username

    assert q.save(validate=True)
    assert q._id

    user_from_question = q.get_user()

    assert user_from_question._id == user._id

    q.user = u"anon!"

    q.save()

    assert not q.get_user()
开发者ID:fernandotakai,项目名称:questions,代码行数:27,代码来源:question_tests.py

示例5: activate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def activate(key):
	""" Activate profile. Create a new user object. 
		We use the email as username.
	"""
	profile = RegistrationProfile.query.filter(
		RegistrationProfile.activation_key==key).first()
	
	if not profile:
		return render_template("auth/activation_failed.html")

	if not profile.activation_date == None:
		return render_template("auth/already_activated.html")
	
	if profile.expiration_date > datetime.datetime.now():
		user = User()
		user.first_name = profile.first_name
		user.last_name = profile.last_name
		user.email = profile.email
		user.username = profile.email
		user.password = profile.password
		profile.activation_date = datetime.datetime.now()
		user.dob = profile.dob
		user.identifier_id= profile.identifier_id
		user.country = profile.country
		user.zipcode = profile.zipcode
		user.city = profile.city
		user.street = profile.street
		db_session.add(user)
		db_session.add(profile)
		db_session.commit()
		flash("Your account has been activated. You may login now.")
		return redirect(url_for('index'))
	return render_template("auth/activation_expired.html")
开发者ID:miku,项目名称:evreg,代码行数:35,代码来源:app.py

示例6: login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def login():
	message_box = ""
	login_form = LoginForm(prefix="login")
	register_form = RegisterForm(prefix="register")

	#Only validate forms if the user pressed one of the submit buttons
	if 'submit_button' in request.form:
		if request.form['submit_button'] == 'Login':
			if login_form.validate_on_submit():
				user = User.query.filter_by(username = request.form['login-username'].strip()).first()
				if user == None or user.password != request.form['login-password'].strip():
					message_box = message_box_html('Username / Password combination is invalid.', error=True)
				else:
					login_user(user)
					return redirect(url_for('workspace'))
			else:
				message_box = get_form_error(login_form)
		elif request.form['submit_button'] == 'Register':
			if register_form.validate_on_submit():
				if User.query.filter_by(username = request.form['register-username'].strip()).first() != None:
					message_box = message_box_html('Username already in use.', error=True)
				elif User.query.filter_by(email = request.form['register-email'].strip()).first():
					message_box = message_box_html('Email address already in use.', error=True)
				else:
					new_user = User()
					new_user.username = request.form['register-username'].strip()
					new_user.password = request.form['register-password'].strip()
					new_user.email = request.form['register-email'].strip()
					db.session.add(new_user)
					db.session.commit()
					message_box = message_box_html('Your account has been created.')
			else:	#Set error message to the first validation error.
				message_box = get_form_error(register_form)
	
	return render_template('login.html', login_form=login_form, register_form=register_form, message_box=message_box)
开发者ID:BradWells,项目名称:fluidScheduler,代码行数:37,代码来源:views.py

示例7: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
    def post(self, **kwargs):
        role = self.request.get('role', default_value=None)
        tenantKey = self.request.get('tenant_key', default_value=None)
        unitKey = self.request.get('unit_key', default_value=None)
        locationKey = self.request.get('location_key', default_value = None)
        username = self.request.get('username', default_value=None)
        password = self.request.get('password', default_value=None)
        if not all([role,locationKey,username,password]):
            self.abort(400)
        if role == 'tenant' and not tenantKey:
            self.abort(400)
        key = None
        if role == 'tenant':
            key = ndb.Key(Location, int(locationKey),
                    Unit, int(unitKey),
                    Tenant, int(tenantKey))
        elif role == 'manager':
            key = ndb.Key(Location, int(locationKey))
        else:
            self.response.status = 400
            self.response.status_message = 'Role must be either tenant or manager.'

        user = User()
        try:
            user.role = role
            user.related_key = key
            user.username = username
            user.password = password
            user.put()
        except Exception as msg:
            self.abort(500, details=msg)
            return
        self.response.write(json.dumps(user.to_dict()))
开发者ID:bardec,项目名称:assignment3_2,代码行数:35,代码来源:user.py

示例8: register

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def register():
    error = None
    if request.method == 'POST':

        uname =request.form['username']
        passwd = request.form['password']
        spasswd =  request.form['spassword']
        usercheck = db.GqlQuery("SELECT * FROM User WHERE username = :username", username=uname).get()

        if  len(uname.strip()) == 0 :
            error = "Username field cannot be empty"
        elif usercheck is not None:
            error = "Username is already in use. Choose another"
        elif len(passwd) == 0 | len(spasswd) == 0:
            error = 'Password field cannot be empty'
        elif spasswd != passwd:
            error = 'Passwords do not match'
        else :
            u = User()
            u.username = uname
            u.password = get_hash(passwd)
            u.put()
            flash("Registration was successful")
            return redirect(url_for("login"))

    return render_template('register.html',error=error)
开发者ID:miquelet,项目名称:flask_projects,代码行数:28,代码来源:app.py

示例9: create_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
 def create_user(self, username, raw):
     password = self.create_password(raw)
     token = password.split("$")[0]
     user = User()
     user.username = username
     user.password = password
     user.token = token
     self.db.add(user)
     self.db.commit()
开发者ID:ibigbug,项目名称:ZQ-Planet,代码行数:11,代码来源:mixin.py

示例10: test_verify_password

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def test_verify_password():
    user = User()
    user.username = u"test"
    user.set_password('test1234')

    user.save()

    assert user.verify_password('test1234')
    assert not user.verify_password('test')
开发者ID:fernandotakai,项目名称:questions,代码行数:11,代码来源:user_tests.py

示例11: create_couch_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def create_couch_user(username, password):
    db = get_db("couchauth")
    User.set_db(db)
    users = User.view("couchauth/username")
    query = users[username]
    user = query.one()
    if not user:
        user = User()
        user.username = username
        user.set_password(password)
        user.save()
    return user
开发者ID:GaloC,项目名称:gplib,代码行数:14,代码来源:libs.py

示例12: load_user_from_db

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def load_user_from_db(user_object):
	""" 
		Retrieve the user information from user_object
		and return the User object for use in Login/Registration.
	"""

	user = User()
	user.user_id = user_object['user_id']
	user.password = user_object['password']
	user.email = user_object['email']
	user.username = user_object['username']
	user.site_id = user_object['site_id']
	return user
开发者ID:tomzaragoza,项目名称:graphbin,代码行数:15,代码来源:app.py

示例13: add_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def add_user():
    print("For better security it is recommended that you add users using a"
        " client on a different machine from the server, this utility is only"
        " designed for adding a user to an otherwise empty system.\n")
    init(config["connection_string"])
    u = User()
    while not u.username:
        u.username = input("Enter username: ")
    while not u.full_name:
        u.full_name = input("Enter full name: ")
    while not u.email:
        u.email = input("Enter email: ")
    password = None
    while not password:
        password = getpass("Enter password: ")
    admin_response = None
    while admin_response not in ["y", "n"]:
        admin_response = input("Is user an admin? [y/n]: ")
    u.admin = admin_response == "y"

    print("Generating keys...", end="")
    sys.stdout.flush()

    private = RSA.generate(config["key_length"])
    public = private.publickey()

    salt = os.urandom(8)
    key = PBKDF2(password, salt).read(32)
    iv = os.urandom(16)
    cypher = AES.new(key, AES.MODE_CFB, iv)

    encrypted_private_key = cypher.encrypt(private.exportKey("DER"))

    u.public_key = base64.b64encode(public.exportKey("DER")).decode("UTF-8")
    u.encrypted_private_key = base64.b64encode(encrypted_private_key).decode(
        "UTF-8")
    u.pbkdf2_salt = base64.b64encode(salt).decode("UTF-8")
    u.aes_iv = base64.b64encode(iv).decode("UTF-8")

    auth_key = base64.b64encode(hashlib.pbkdf2_hmac("sha512",
        password.encode("UTF-8"), u.username.encode("UTF-8"), 100000))

    u.auth_hash = bcrypt.hashpw(auth_key, bcrypt.gensalt()).decode("UTF-8")

    print("Done!")
    print("Adding user...", end="")
    sys.stdout.flush()
    db_session.add(u)
    db_session.commit()
    print("Done!")
开发者ID:camerongray1515,项目名称:Multi-User-Password-Locker,代码行数:52,代码来源:main.py

示例14: create_super_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def create_super_user():
    c = raw_input("Create Super User?(y/n)")
    if c == "n":
        import sys
        sys.exit(1)
    username = raw_input("username:")
    import getpass
    raw = getpass.getpass("password:")
    user = User()
    user.username = username
    user.password = UserMixin.create_password(raw)
    db.session.add(user)
    db.session.commit()
    print "Finished!!!"
开发者ID:ibigbug,项目名称:ZQ-Planet,代码行数:16,代码来源:syncdb.py

示例15: regist

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import username [as 别名]
def regist(request):
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            user = User()
            user.username = username
            user.password = password
            user.save()
            return render_to_response('success.html',{'username':username})
    else:
        uf = UserForm()
    return render_to_response('register.html',{'uf':uf})
开发者ID:yeminghua,项目名称:first,代码行数:16,代码来源:views.py


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