本文整理汇总了Python中models.UserInfo类的典型用法代码示例。如果您正苦于以下问题:Python UserInfo类的具体用法?Python UserInfo怎么用?Python UserInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
def register(request):
if request.method == 'POST': # If the form has been submitted...
row = UserInfo(email_id = request.POST['email'], password = request.POST['pwd'],
full_name = request.POST['fullname'])
row.save()
email = request.POST['email'];
return HttpResponseRedirect('alternative')
示例2: loginView
def loginView(request):
context = get_context(request)
# Forget AccountAccesses to merge if user goes somewhere then back to login.
if 'merge_access' in request.session:
del request.session['merge_access']
if 'merge_access_info' in request.session:
del request.session['merge_access_info']
if request.user.is_authenticated():
try:
access = request.user.accountaccess_set.all()[0]
except IndexError:
access = None
else:
client = access.api_client
user_info = client.get_profile_info(raw_token=access.access_token)
context['info'] = user_info
user = request.user
try:
user_profile = UserProfile.objects.get(user=user)
except UserProfile.DoesNotExist:
new_user_info = UserInfo()
new_user_info.save()
user_profile, just_created = UserProfile.objects.get_or_create(user=user, user_info=new_user_info)
# I'm not sure if this condition is necessary.
if just_created:
standarize_user_info(user_info)
if 'gender' in user_info:
user_profile.gender = user_info['gender']
user.save()
user_profile.save()
return render(request, 'login.html', context)
示例3: current_user_info
def current_user_info(self):
if self.user_info is None:
"""Get the current user by lookup if we can"""
if self.username:
self.user_info = UserInfo.get_by_username(self.username)
"""Gets the current user. This involves a query. Its more efficient to perform
lookups with the username and verify that the user_info is current."""
if self.google_user is not None:
users_query = UserInfo.query( UserInfo.google_user==self.google_user)
self.user_info = users_query.get()
if self.oauth_user_id is not None:
users_query = UserInfo.query( UserInfo.oauth_user_id==self.oauth_user_id)
self.user_info = users_query.get()
if self.user_info and self.username is None:
self.username = self.user_info.username
if self.user_info is not None and self.is_user_info_current(self.user_info):
return self.user_info
else:
return None
示例4: set_username
def set_username(self,username):
errors = []
match = re.search(r'^[\d\w_\-]+$', username)
isvalid = match and 4 <= len(username) and len(username) <= 20;
if not isvalid:
errors.append('invalid_name')
else:
user_info = self.current_user_info()
if user_info is None:
user_info_key = UserInfo.create_key(username)
#in the circumstances of a collision whoever asked last is the winner
#of course if fifty 'Daniels' pile up then we have an issue
user_info = user_info_key.get()
if user_info is None:
user_info = UserInfo.put_new(username,oauth_user_id=self.oauth_user_id,google_user=self.google_user)
else:
errors.append('other_has_name')
if len(errors) == 0:
return True, user_info
else:
return False, errors
示例5: register_new_user
def register_new_user(email, password):
user = UserInfo(
email=email,
password=password,
id=email
)
user.put()
示例6: login
def login():
if 'Authorization' in request.headers:
user = UserInfo.get_with_token(request.headers['Authorization'])
if user is not None:
login_user(user)
response = {}
response['code'] = 0
response['cell'] = user.cell
response['token'] = user.token
return json.dumps(response)
# return "User: "+user.cell+" successfully logged in by token"
try:
cell = request.json['cell']
pwd = request.json['password']
user = UserInfo.get_with_cell(cell=cell)
if (user is not None) and (user.password == pwd):
login_user(user, remember=True)
response = {}
response['code'] = 0
response['cell'] = cell
response['token'] = user.token
return json.dumps(response)
else:
response = {'code': 1}
return json.dumps(response)
except (KeyError, TypeError, ValueError):
response = {'code': -2}
return json.dumps(response)
示例7: get
def get(self, mode = ''):
if mode == 'login':
if 'allowed' in self.request.cookies and \
self.request.cookies['allowed'].count('_'):
_twitter_id, _login_hash = \
self.request.cookies['allowed'].split('_', 1)
user_info = UserInfo.all().filter('twitter_id =', _twitter_id).get()
if user_info and _sha512(user_info.acc_key) == _login_hash:
self.session = Session()
self.session['twitter_id'] = _twitter_id
return self.redirect('/home')
auth = _oauth_handler()
auth_url = auth.get_authorization_url()
memcache.set(auth.request_token.key,
auth.request_token.secret,
3600)
return self.redirect(auth_url)
elif mode == 'verify':
auth = _oauth_handler()
ver = self.request.get('oauth_verifier')
req_key = self.request.get('oauth_token')
req_sec = memcache.get(req_key)
auth.set_request_token(req_key, req_sec)
acc_token = auth.get_access_token(ver)
api = tweepy.API(auth_handler = auth)
me = api.me()
if not UserInfo.all().filter('twitter_id =', str(me.id)).get():
user_info = UserInfo(twitter_id = str(me.id),
screen_name = me.screen_name,
name = me.name,
image = me.profile_image_url,
acc_key = acc_token.key,
acc_sec = acc_token.secret)
user_info.put()
self.session = Session()
self.session.delete_item('twitter_id')
self.session['twitter_id'] = str(me.id)
c = SimpleCookie()
c['allowed'] = '%d_%s' % (me.id, _sha512(acc_token.key))
c['allowed']['path'] = '/auth'
c['allowed']['expires'] = 86400 * 10
self.response.headers.add_header('Set-Cookie', c.output(header = ''))
return self.redirect('/home')
elif mode == 'logout':
user_info = _login_user(self)
if user_info:
self.session = Session()
self.session.delete_item('twitter_id')
return self.redirect('/')
示例8: test_signals
def test_signals(self):
old_count = LogEntry.objects.count()
userobject = UserInfo(name='testname', \
surname='testsurname', \
birthday='2010-02-17', \
about='test', \
contacts='test');
userobject.save()
self.assertNotEqual(old_count, LogEntry.objects.count())
示例9: post
def post(self):
userinfo = self.currentuser
if userinfo == None:
userinfo = UserInfo()
userinfo.nickname = cgi.escape(self.request.get('nickname'))
if is_empty(userinfo.nickname):
self.render_edit("nickname can't be empty")
return
email = cgi.escape(self.request.get('email'))
avatar = self.request.get('avatar')
first_login = self.request.get('first_login')
if avatar != '':
avatar = images.resize(avatar, 128)
userinfo.avatar = db.Blob(avatar)
if email == '':
email = 'none'
userinfo.email = email
if first_login != '':
userinfo.lastposted = date.today()
userinfo.lastvoted = userinfo.lastposted
userinfo.put()
self.redirect('/')
示例10: get
def get(self):
user = users.get_current_user()
if user:
code = self.request.get("code")
if code:
old_userinfos = UserInfo.all().filter('user =', user).fetch(500)
db.delete(old_userinfos)
fs, credentials = self._get_new_fs_and_credentials()
try:
user_token = fs.get_access_token(code)
userinfo = UserInfo(user = user, token = user_token, secret = None, is_ready=False, is_authorized=True, level_max=int(3 * constants.level_const))
except DownloadError, err:
if str(err).find('ApplicationError: 5') >= 0:
pass # if something bad happens on OAuth, then it currently just redirects to the signup page
#TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code
else:
raise err
try:
manage_foursquare_data.update_user_info(userinfo)
manage_foursquare_data.fetch_and_store_checkins_next(userinfo, limit=50)
except foursquare.FoursquareRemoteException, err:
if str(err).find('403 Forbidden') >= 0:
pass # if a user tries to sign up while my app is blocked, then it currently just redirects to the signup page
#TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code
else:
raise err
except DownloadError:
pass #TODO make this better, but I'd rather throw the user back to the main page to try again than show the user an error.
示例11: flush
def flush():
ndb.delete_multi(School.query().fetch(keys_only=True))
ndb.delete_multi(QuestionInstance.query().fetch(keys_only=True))
ndb.delete_multi(State_Questions.query().fetch(keys_only=True))
ndb.delete_multi(Topic_States.query().fetch(keys_only=True))
ndb.delete_multi(Question.query().fetch(keys_only=True))
ndb.delete_multi(State.query().fetch(keys_only=True))
ndb.delete_multi(Address.query().fetch(keys_only=True))
ndb.delete_multi(Teacher.query().fetch(keys_only=True))
ndb.delete_multi(Class.query().fetch(keys_only=True))
ndb.delete_multi(Assessment_Record.query().fetch(keys_only=True))
ndb.delete_multi(Student.query().fetch(keys_only=True))
ndb.delete_multi(UserInfo.query().fetch(keys_only=True))
ndb.delete_multi(Student_Assessments.query().fetch(keys_only=True))
ndb.delete_multi(Assessment.query().fetch(keys_only=True))
ndb.delete_multi(Subject.query().fetch(keys_only=True))
ndb.delete_multi(Topic_Questions.query().fetch(keys_only=True))
ndb.delete_multi(State_Questions.query().fetch(keys_only=True))
ndb.delete_multi(Topic_States.query().fetch(keys_only=True))
ndb.delete_multi(Subject_Topics.query().fetch(keys_only=True))
ndb.delete_multi(Student_Assessments.query().fetch(keys_only=True))
ndb.delete_multi(Topic.query().fetch(keys_only=True))
ndb.delete_multi(User.query().fetch(keys_only=True))
ndb.delete_multi(Assessment_Record.query().fetch(keys_only=True))
ndb.delete_multi(State_Types.query().fetch(keys_only=True))
示例12: checkIdAndEmail
def checkIdAndEmail(userId, email):
query = UserInfo.all()
query.filter('userId = ', userId).filter('email = ', email)
if query.count() == 0:
return False;
else:
return True;
示例13: checkEmail
def checkEmail(email):
query = UserInfo.all()
query.filter('email = ', email)
if query.count() == 0:
return False;
else:
return True;
示例14: checkUserId
def checkUserId(userId):
query = UserInfo.all()
query.filter('userId = ', userId)
if query.count() == 0:
return False;
else:
return True;
示例15: authService
def authService(userId, passwd):
query = UserInfo.all()
query.filter('userId = ', userId).filter('passwd = ', passwd)
if query.count() == 0:
return False;
else:
return True;