本文整理汇总了Python中models.User.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_user方法的具体用法?Python User.get_user怎么用?Python User.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.get_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_or_create_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def get_or_create_user():
user = users.get_current_user()
u = User.get_user(user)
if not u and users.is_current_user_admin():
u = User(user=user, role='admin')
u.put()
return u
示例2: home
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def home(cell_path=None):
maps = memcache.get('default_maps')
if maps:
maps = json.loads(maps)
else:
maps = default_maps()
memcache.add(key='default_maps', value=json.dumps(maps), time=3600*24)
# send only the active report
reports = json.dumps([Report.current().as_dict()])
user = users.get_current_user()
u = User.get_user(user)
if not u and users.is_current_user_admin():
u = User(user=user, role='admin')
u.put()
if not u:
abort(403)
logout_url = users.create_logout_url('/')
return render_template('home.html',
reports_json=reports,
user=u,
maps=maps,
logout_url=logout_url)
示例3: insert_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def insert_user(self, _user):
if (functions.auth_user(_user.email)):
user_key = ndb.Key('AIESEC','User')
u = User.get_user()
if _user.user_id in u:
raise endpoints.InternalServerErrorException()
else:
user = User(parent = user_key, user_id = _user.user_id,
email = _user.email, user = _user.user,
university = _user.university, state = _user.state)
user.put()
User.get_user(True)
return _user
else:
raise endpoints.UnauthorizedException('This method requires you to be authenticated. You may need to activate the toggle above to authorize your request using OAuth 2.0.')
示例4: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def get(self):
template_vals = dict()
template_vals['name_of_user'] = users.get_current_user().nickname()
template_vals['notebooks'] = self.get_notebooks(users.get_current_user().user_id())
user = User.get_user(users.get_current_user().user_id())
template_vals['lectures'] = user.lecture_ids
template_vals['tutorial'] = user.tutorial
render(self, template_vals, 'dashboard.html')
示例5: decorated_function
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def decorated_function(*args, **kwargs):
user = None
user_id = session.get('id')
if user_id:
user = User.get_user(user_id)
g.loggedin_user = user
if not user:
flash('You need to login.', category='error')
return redirect(url_for('login', next=request.path))
return f(*args, **kwargs)
示例6: profile
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def profile():
if request.method == "POST":
# Create a brand new account.
if request.form["submit"] == "Create":
email = request.form["email"]
# Make sure an email is provided.
if not email:
return render_template('404.html'), 404
user = User.get_user(email)
if not user:
user = User()
user.email = email
user.password = "password"
user.save()
session["email"] = email
sounds = user.get_sounds()
return render_template("profile.html", sounds=sounds)
else:
return render_template('404.html'), 404
# Log an existing user in.
elif request.form["submit"] == "Login":
email = request.form["email"]
user = User.get_user(email)
if not user:
return render_template('404.html'), 404
else:
session["email"] = email
sounds = user.get_sounds()
return render_template("profile.html", sounds=sounds)
# Log an existing user out.
elif request.form["submit"] == "Logout":
session["email"] = None
return render_template('index.html')
else:
return render_template('404.html'), 404
else:
if session["email"]:
user = User.get_user(session["email"])
sounds = user.get_sounds()
return render_template("profile.html", sounds=sounds)
else:
return render_template('index.html')
示例7: dispatch
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def dispatch(self):
google_user = users.get_current_user()
if google_user:
google_id = google_user.user_id()
user = User.get_user(google_id=google_id)
if user:
super(AuthHandler, self).dispatch()
else:
render(self, {}, 'index.html')
else:
self.redirect('/dashboard')
示例8: changePW
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def changePW():
campID=request.args.get('campID',type=str)
oldpw=request.args.get('oldpw')
newpw=request.args.get('newpw')
user=User.get_user(campID)
if user.password == oldpw:
user.password=newpw
db.session.commit()
return "True"
else:
return "False"
示例9: management_handle
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def management_handle():
if request.method == 'POST':
return makepublic._makepublic()#?????????
elif request.method == 'GET':
if request.args.get('Delete',type=str)=='Delete':#删除某个加分项
itemID=request.args.get('itemID',type=int)
Score_items.delete(itemID)
return " "
elif request.args.get('Delete',type=str)=='DeleteStu':#删除学生
campID=request.args.get('campID',type=str)
User.delete(campID)
return " "
elif request.args.get('Edit',type=str)=='Edit':#编辑
id=request.args.get('id',type=str)
name=request.args.get('edit_name',type=unicode)
campID=request.args.get('edit_campID',type=str)
grade=request.args.get('edit_grade',type=unicode)
studentID=request.args.get('edit_studentID',type=str)
return User.edit(id,campID,name,grade,studentID)
elif request.args.get('Add',type=str)=='Add':#添加学生
name=request.args.get('add_name',type=unicode)
campID=request.args.get('add_campID',type=str)
grade=request.args.get('add_grade',type=unicode)
studentID=request.args.get('add_studentID',type=str)
user=User.get_user(campID)
if user:
return u"一卡通号重复"
else :
User.addstudent(campID,name,grade,addstudent)
return u"添加成功"
elif request.args.get('action',type=str)=='resetpw':
campID=request.args.get('campID',type=str)
user=User.get_user(campID)
try:
user.password=user.campID
db.session.commit()
return u"重置成功"
except StandardError,e:
return u"未知错误"
示例10: profile
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def profile(username):
profile_user = User.get_user(username)
if not profile_user:
abort(404)
if g.user and g.user.username != profile_user.username:
visit = Visit(profile_user.id, g.user.id)
db.session.merge(visit)
db.session.commit()
return render_template("profile.html", profile_user=profile_user, questions=QUESTIONS, comment_form=CommentForm())
示例11: index
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def index():
return render_template(
'chart.html',
browser=request.user_agent.browser
)
@lido_app.route('/login')
def login():
return twitter.authorize(
callback=url_for(
'oauth_authorized',
next=request.args.get('next') or request.referrer or None)
)
@twitter.tokengetter
def get_twitter_token(token=None):
return session.get('twitter_token')
@lido_app.route('/oauth-authorized')
@twitter.authorized_handler
def oauth_authorized(resp):
print 'foo-bar'
next_url = request.args.get('next') or url_for('index')
if resp is None:
flash(u'You denied the request to sign in.')
return redirect(next_url)
user = User.get_user(resp['screen_name'])
if user is None:
user = User(
username=resp['screen_name'],
token=resp['oauth_token'],
secret=resp['oauth_token_secret']
)
else:
user.oauth_token = resp['oauth_token']
user.oauth_token_secret = resp['oauth_token_secret']
user.save()
# use flask_login to set up the user session stuff
flask_login.login_user(user)
session['twitter_token'] = (
resp['oauth_token'],
resp['oauth_token_secret']
)
session['twitter_user'] = resp['screen_name']
flash('You were signed in as %s' % resp['screen_name'])
return redirect(next_url)
示例12: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def login():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
u = User()
user = u.get_user(email, password)
if user is not None:
login_user(user) # this is flask login
return redirect(url_for('main'))
else:
return render_template('apps/auth/login.html', message="Email or password is incorrect, try again")
else:
return render_template('apps/auth/login.html')
示例13: add_buddy
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def add_buddy(username):
if not g.user:
flash("You must be logged in to add buddies.")
return redirect(url_for("views.profile", username=username))
buddy_user = User.get_user(username)
if g.user.id == buddy_user.id:
flash("You may not add yourself as a buddy.")
return redirect(url_for("views.profile", username=username))
buddy = Buddy(g.user.id, buddy_user.id)
db.session.merge(buddy)
db.session.commit()
return redirect(url_for("views.profile", username=username))
示例14: submit_comment
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def submit_comment(username):
if not g.user:
flash("You are not authorized for that action.")
return redirect(url_for("views.profiles"))
form = CommentForm(request.form)
user = User.get_user(username)
if form.validate_on_submit():
commenter = g.user
comment = Comment(user.id, commenter.id, form.comment.data)
db.session.add(comment)
db.session.commit()
return redirect(url_for("views.profile", username=user.username))
flash("There was an error with you comment.")
return redirect(url_for("views.profile", username=user.username))
示例15: _getMyScore
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user [as 别名]
def _getMyScore():
"getmyscore.py:scripts used by user.html"
#0 :delete
#1 :getscore
opt=request.args.get('opt',type=int)
campID = request.args.get('campID', type=str)
user=User.get_user(campID)
if user:
if(opt==1) :
return getmyscore._getmyscore(user)
elif(opt==0):
return getmyscore._deleteapply(user)
else:
return getmyscore._getTotal(user)#Update the total score (called when searching or login)
else:
return "user not found"