本文整理匯總了Python中models.User方法的典型用法代碼示例。如果您正苦於以下問題:Python models.User方法的具體用法?Python models.User怎麽用?Python models.User使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models
的用法示例。
在下文中一共展示了models.User方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: change_email_request
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def change_email_request():
form = form_class.ChangeEmailForm()
if form.validate_on_submit():
if current_user.verify_password(form.password.data):
new_email = escape(form.email.data)
token = current_user.generate_email_change_token(new_email)
send_email(new_email,
'CVE-PORTAL -- Confirm your email address',
'/emails/change_email',
user=current_user,
token=token)
syslog.syslog(syslog.LOG_WARNING,
"User as requested an email change: Old:" + current_user.email + " New: " + form.email.data)
flash('An email with instructions to confirm your new email address has been sent to you.', 'info')
return redirect(url_for('main.index'))
else:
flash('Invalid email or password.', 'danger')
return render_template("auth/change_email.html", form=form)
示例2: change_pgp
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def change_pgp():
form = form_class.ChangePGPForm()
if form.validate_on_submit():
if current_user.verify_password(form.password.data):
ki = gpg.import_keys(form.pgp.data)
if not ki.fingerprints:
fingerp = "--- NO VALID PGP ---"
else:
fingerp = ki.fingerprints[0]
current_user.pgp = form.pgp.data
current_user.fingerprint = fingerp
models.db.session.add(current_user)
models.db.session.commit()
flash('Your PGP key has been updated.', 'info')
syslog.syslog(syslog.LOG_INFO, "User Changed his PGP: " + current_user.email)
return redirect(url_for('main.index'))
else:
flash('Invalid password.', 'danger')
return render_template("auth/change_pgp.html", form=form)
示例3: update_user_details
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def update_user_details(user_id, name, email, new_password):
"""
Update an existing user, identified by user_id, with the provided fields. If name or email is None, this will
remove these fields from the user entry. If new_password is None, the user's password will not be updated.
:param user_id: User ID of the user to update
:param name: Updated name, can be empty string or None to indicate no update
:param email: Updated email, can be empty string or None to indicate no update
:param new_password: New password, if updating the user's password
:return: models.User object representing the updated user
:raises InvalidEmailException: If an invalid email is passed
"""
if email and not is_email_address_valid(email):
raise InvalidEmailException('{email_addr} is not a valid email address'.format(email_addr=email))
user = get_user_by_id(user_id, active_only=True)
user.name = name
user.email = email
if new_password:
user.password_hash = util.cryptography.secure_hash(new_password)
session.commit()
return user
示例4: get_user_by_id
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def get_user_by_id(user_id, active_only=False):
"""
Get a User object by user_id, whose attributes match those in the database.
:param user_id: User ID to query by
:param active_only: Set this flag to True to only query for active users
:return: User object for that user ID
:raises UserDoesNotExistException: If no user exists with the given user_id
"""
if active_only:
user = models.User.query.filter_by(user_id=user_id, is_active=True).first()
else:
user = models.User.query.filter_by(user_id=user_id).first()
if not user:
raise UserDoesNotExistException('No user with user_id {user_id} exists'.format(user_id=user_id))
return user
示例5: get_user_by_username
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def get_user_by_username(username, active_only=False):
"""
Get a User object by username, whose attributes match those in the database.
:param username: Username to query by
:param active_only: Set this flag to True to only query for active users
:return: User object for that username
:raises UserDoesNotExistException: If no user exists with the given username
"""
if active_only:
user = models.User.query.filter_by(username=username.lower(), is_active=True).first()
else:
user = models.User.query.filter_by(username=username.lower()).first()
if not user:
raise UserDoesNotExistException('No user with username {username} exists'.format(username=username))
return user
示例6: get_user_by_api_key
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def get_user_by_api_key(api_key, active_only=False):
"""
Get a User object by api_key, whose attributes match those in the database.
:param api_key: API key to query by
:param active_only: Set this flag to True to only query for active users
:return: User object for that user ID
:raises UserDoesNotExistException: If no user exists with the given user_id
"""
if active_only:
user = models.User.query.filter_by(api_key=api_key, is_active=True).first()
else:
user = models.User.query.filter_by(api_key=api_key).first()
if not user:
raise UserDoesNotExistException('No user with api_key {api_key} exists'.format(api_key=api_key))
return user
示例7: createUserConfig
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def createUserConfig(user, config_path='.config.ini'):
"""
Create .config.ini file for Spotify credentials.
Parameters
----------
user: User object
Spotify user object.
config_path: str
Path to .config.ini.
"""
s_config = ConfigParser()
s_config['spotify'] = {
'client_id': user.client_id,
'client_secret': user.client_secret,
'username': user.username,
'playlist_id': user.getPlaylistsAsString(),
'redirect_uri': user.redirect
}
with open(config_path, 'w') as f:
s_config.write(f)
示例8: authenticated
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def authenticated(f):
@wraps(f)
def decorated(*args, **kwargs):
global h
# if token not set
if not h["Freelancer-OAuth-V1"]:
# set it to session token (if it exists)
if 'Authorization' in session and 'name' in session:
u = User.query.filter_by(access_token=session["Authorization"], name=session["name"]).first()
if (not u):
return auth()
else:
h["Freelancer-OAuth-V1"] = u.access_token
else:
return logout()
return f(*args, **kwargs)
return decorated
# Authorise a user
示例9: handle_redirect
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def handle_redirect():
payload = {
'grant_type': 'authorization_code',
'code': request.args['code'],
'client_id': client_id,
'client_secret': client_secret,
'redirect_uri': 'http://127.0.0.1:5000/auth_redirect',
}
response = requests.post(base_accounts_url + '/oauth/token', data=payload).json()
h = {"Freelancer-OAuth-V1": response["access_token"]}
url = base_url + "/api/users/0.1/self/"
details = requests.get(url, headers=h).json()
session['Authorization'] = response['access_token']
session['name'] = details['result']['username']
user = User.query.filter_by(name=session["name"]).first()
if not user:
user = User(details['result']['username'], details["result"]['email'], response['access_token'], response['refresh_token'])
db.session.add(user)
else:
user.access_token = response['access_token']
user.refresh_token = response['refresh_token']
db.session.commit()
return render_template("user.html", user=user)
# Unauthenticate the user
示例10: setUp
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def setUp(self):
super(CommentFavorTests, self).setUp()
self.admin = models.User(name='admin', email='admin@example.com', email_confirmed=1, is_paid=1)
self.admin.set_password('asdfasdf')
self.admin.save()
self.user2 = models.User(name='user2', email='user2@example.com', email_confirmed=1, is_paid=1)
self.user2.set_password('asdfasdf')
self.user2.save()
self.src = models.Sourcefile(width=1, height=1, file_key='asdf', thumb_key='qwer')
self.src.save()
self.shf = models.Sharedfile(source_id=self.src.id, user_id=self.admin.id, name='shared.jpg', title='shared', share_key='1', content_type='image/jpg')
self.shf.save()
print "person who owns the comment"
self.comment = models.Comment(user_id=self.user2.id, sharedfile_id=self.shf.id, body="just a comment")
self.comment.save()
print self.comment.user_id
self.sign_in('admin','asdfasdf')
response = self.post_url('/p/%s/comment/%s/like?json=1' % (self.shf.share_key, self.comment.id))
示例11: setUp
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def setUp(self):
super(ConversationTests, self).setUp()
self.admin = User(name='admin', email='admin@mltshp.com', email_confirmed=1, is_paid=1)
self.admin.set_password('asdfasdf')
self.admin.save()
self.user2 = User(name='user2', email='user2@example.com', email_confirmed=1, is_paid=1)
self.user2.set_password('asdfasdf')
self.user2.save()
self.sid = self.sign_in('user2', 'asdfasdf')
self.xsrf = self.get_xsrf()
self.src = Sourcefile(width=1, height=1, file_key='asdf', thumb_key='qwer')
self.src.save()
self.shf = Sharedfile(source_id=self.src.id, user_id=self.admin.id, name='shared.jpg', title='shared', share_key='1', content_type='image/jpg')
self.shf.save()
示例12: setUp
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def setUp(self):
"""
Create users to test different liking situations.
"""
super(ImageLikeTests, self).setUp()
self.admin = User(name='admin', email='admin@example.com', email_confirmed=1, is_paid=1)
self.admin.set_password('asdfasdf')
self.admin.save()
self.joe = User(name='joe', email='joe@example.com', email_confirmed=1, is_paid=1)
self.joe.set_password('asdfasdf')
self.joe.save()
self.bill = User(name='bill', email='bill@example.com', email_confirmed=1, is_paid=1)
self.bill.set_password('asdfasdf')
self.bill.save()
self.frank = User(name='frank', email='frank@example.com', email_confirmed=1, is_paid=1)
self.frank.set_password('asdfasdf')
self.frank.save()
示例13: setUp
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def setUp(self):
super(InviteMemberTests, self).setUp()
self.user = models.User(name='admin', email='admin@mltshp.com', email_confirmed=1, is_paid=1)
self.user.set_password('pass')
self.user.save()
#create a shake for admin
self.shake = models.Shake(user_id=self.user.id, type='group', name='asdf', title='asdf', description='asdf')
self.shake.save()
#create three other users
self.usera = models.User(name='usera', email='usera@example.com', email_confirmed=1, is_paid=1)
self.usera.set_password('pass')
self.usera.save()
self.userb = models.User(name='userb', email='userb@example.com', email_confirmed=1, is_paid=1)
self.userb.set_password('pass')
self.userb.save()
self.sign_in('admin', 'pass')
示例14: setUp
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def setUp(self):
super(ImageSaveTests, self).setUp()
# uploader
self.admin = User(name='admin', email='admin@mltshp.com', email_confirmed=1, is_paid=1)
self.admin.set_password('asdfasdf')
self.admin.save()
# saver
self.bob = User(name='bob', email='bob@mltshp.com', email_confirmed=1, is_paid=1)
self.bob.set_password('asdfasdf')
self.bob.save()
# saver
self.tom = User(name='tom', email='tom@mltshp.com', email_confirmed=1, is_paid=1)
self.tom.set_password('asdfasdf')
self.tom.save()
# unconfirmed user
self.jim = User(name='jim', email='jim@mltshp.com', email_confirmed=0, is_paid=1)
self.jim.set_password('asdfasdf')
self.jim.save()
# uploader's file.
self.sharedfile = self._create_sharedfile(self.admin)
示例15: setUp
# 需要導入模塊: import models [as 別名]
# 或者: from models import User [as 別名]
def setUp(self):
super(FileViewTests, self).setUp()
self.user = User(name='admin', email='admin@mltshp.com', email_confirmed=1, is_paid=1)
self.user.set_password('asdfasdf')
self.user.save()
self.user2 = User(name='user', email='user@mltshp.com', email_confirmed=1, is_paid=1)
self.user2.set_password('asdfasdf')
self.user2.save()
self.sid2 = self.sign_in('user', 'asdfasdf')
self.sid = self.sign_in('admin', 'asdfasdf')
self.xsrf = self.get_xsrf()
self.test_file1_path = os.path.abspath("test/files/1.png")
self.test_file1_sha1 = Sourcefile.get_sha1_file_key(self.test_file1_path)
self.test_file1_content_type = "image/png"
self.test_file2_path = os.path.abspath("test/files/love.gif")
self.test_file2_sha1 = Sourcefile.get_sha1_file_key(self.test_file2_path)
self.test_file2_content_type = "image/gif"