本文整理汇总了Python中skylines.model.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: userNameRequestReceived
def userNameRequestReceived(self, host, port, key, payload):
"""The client asks for the display name of a user account."""
if len(payload) != 8: return
pilot = User.by_tracking_key(key)
if pilot is None:
log.err("No such pilot: %d" % key)
return
data = struct.unpack('!II', payload)
user_id = data[0]
user = User.get(user_id)
if user is None:
response = struct.pack('!IHHQIIIBBBBII', MAGIC, 0, TYPE_USER_NAME_RESPONSE, 0,
user_id, USER_FLAG_NOT_FOUND, 0,
0, 0, 0, 0, 0, 0)
response = set_crc(response)
self.transport.write(response, (host, port))
return
name = user.name[:64].encode('utf8', 'ignore')
club_id = user.club_id or 0
response = struct.pack('!IHHQIIIBBBBII', MAGIC, 0, TYPE_USER_NAME_RESPONSE, 0,
user_id, 0, club_id,
len(name), 0, 0, 0, 0, 0)
response += name
response = set_crc(response)
self.transport.write(response, (host, port))
示例2: test_admin
def test_admin():
u = User()
u.first_name = u"Example"
u.last_name = u"Manager"
u.email_address = u"[email protected]"
u.password = u.original_password = u"managepass"
u.admin = True
return u
示例3: test_user
def test_user():
u1 = User()
u1.first_name = u'Example'
u1.last_name = u'User'
u1.email_address = u'[email protected]'
u1.password = u1.original_password = u'test'
u1.tracking_key = 123456
return u1
示例4: new_post
def new_post(self, display_name, club, email_address, password, **kw):
if not club:
club = None
user = User(display_name=display_name, club_id=club,
email_address=email_address, password=password)
user.created_ip = request.remote_addr
user.generate_tracking_key()
DBSession.add(user)
pilots = DBSession.query(Group).filter(Group.group_name == 'pilots').first()
if pilots:
pilots.users.append(user)
redirect('/')
示例5: check_email
def check_email():
current_user = User.get(request.user_id) if request.user_id else None
json = request.get_json()
if not json:
return jsonify(error="invalid-request"), 400
email = json.get("email", "")
result = "available"
if current_user and email == current_user.email_address:
result = "self"
elif User.exists(email_address=email):
result = "unavailable"
return jsonify(result=result)
示例6: new_post
def new_post(form):
user = User(
first_name=form.first_name.data,
last_name=form.last_name.data,
email_address=form.email_address.data,
password=form.password.data
)
user.created_ip = request.remote_addr
db.session.add(user)
create_new_user_event(user)
db.session.commit()
return redirect(url_for('index'))
示例7: check_email
def check_email():
current_user = User.get(request.user_id) if request.user_id else None
json = request.get_json()
if not json:
return jsonify(error='invalid-request'), 400
email = json.get('email', '')
result = 'available'
if current_user and email == current_user.email_address:
result = 'self'
elif User.exists(email_address=email):
result = 'unavailable'
return jsonify(result=result)
示例8: near
def near(flight_id):
flight = get_requested_record(Flight, flight_id, joinedload=[Flight.igc_file])
current_user = User.get(request.user_id) if request.user_id else None
if not flight.is_viewable(current_user):
return jsonify(), 404
try:
latitude = float(request.args["lat"])
longitude = float(request.args["lon"])
time = float(request.args["time"])
except (KeyError, ValueError):
abort(400)
location = Location(latitude=latitude, longitude=longitude)
time = from_seconds_of_day(flight.takeoff_time, time)
flights = _get_near_flights(flight, location, time, 1000)
def add_flight_path(flight):
trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
trace["additional"] = dict(registration=flight.registration, competition_id=flight.competition_id)
return trace
return jsonify(flights=map(add_flight_path, flights))
示例9: read
def read(user_id):
user = User.get(user_id)
if user is None:
raise NotFound()
result = user_schema.dump(user)
return jsonify(result.data)
示例10: add_comment
def add_comment(flight_id):
flight = get_requested_record(Flight, flight_id)
current_user = User.get(request.user_id)
if not current_user:
return jsonify(), 403
json = request.get_json()
if json is None:
return jsonify(error="invalid-request"), 400
try:
data = FlightCommentSchema().load(json).data
except ValidationError as e:
return jsonify(error="validation-failed", fields=e.messages), 422
comment = FlightComment()
comment.user = current_user
comment.flight = flight
comment.text = data["text"]
create_flight_comment_notifications(comment)
db.session.commit()
return jsonify()
示例11: follow
def follow(user_id):
user = get_requested_record(User, user_id)
current_user = User.get(request.user_id)
Follower.follow(current_user, user)
create_follower_notification(user, current_user)
db.session.commit()
return jsonify()
示例12: test_hash_password
def test_hash_password():
hash = User._hash_password(u"secret123", salt=b"abcdef")
assert (
hash
== "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721272b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a"
)
assert is_unicode(hash)
示例13: login
def login():
if g.current_user:
return redirect(get_next())
form = g.login_form
if form.validate_on_submit():
# Find a user matching the credentials
user = User.by_credentials(form.email_address.data,
form.password.data)
# Check if the user wants a cookie
remember = form.remember_me.data
# Check if a user was found and try to login
if user and login_user(user, remember=remember):
user.login_ip = request.remote_addr
user.login_time = datetime.utcnow()
flash(_('You are now logged in. Welcome back, %(user)s!', user=user))
return redirect(get_next())
else:
form.email_address.errors.append(_('Login failed. Please check your eMail address.'))
form.password.errors.append(_('Login failed. Please check your password.'))
return render_template('login.jinja', form=form, next=get_next())
示例14: update
def update(club_id):
current_user = User.get(request.user_id)
if not current_user:
return jsonify(error="invalid-token"), 401
club = get_requested_record(Club, club_id)
if not club.is_writable(current_user):
return jsonify(error="forbidden"), 403
json = request.get_json()
if json is None:
return jsonify(error="invalid-request"), 400
try:
data = ClubSchema(partial=True).load(json).data
except ValidationError as e:
return jsonify(error="validation-failed", fields=e.messages), 422
if "name" in data:
name = data.get("name")
if name != club.name and Club.exists(name=name):
return jsonify(error="duplicate-club-name"), 422
club.name = name
if "website" in data:
club.website = data.get("website")
db.session.commit()
return jsonify()
示例15: test_users
def test_users(n=50):
fake = Faker(locale='de_DE')
fake.seed(42)
users = []
for i in xrange(n):
u = User()
u.first_name = fake.first_name()
u.last_name = fake.last_name()
u.email_address = fake.email()
u.password = u.original_password = fake.password()
u.tracking_key = fake.random_number(digits=6)
users.append(u)
return users