def authenticate(credential): """ If the given credentials are valid, return a User object. """ if credential is None: return None query = db.Query(User) users = query.filter('username ='******'%s' " % credential[0]) return None users = query.filter('is_active =', True) user = users.get() if user and credential[1] is not None: if (not user.check_password(raw_password=credential[1])): user = None logging.debug('authenticate: %s' % str(user)) return user
def get(self, uid): users = ndb.gql('SELECT * FROM User WHERE uid = :1', uid) u = users.get() submissions = Submissions.query(Submissions.uid == uid) if u: self.render('profile.html', user=u, submissions=submissions) else: self.redirect('/')
def getUser(user_id): users = UserDB.query(UserDB.user_id == user_id) if users.count() > 1: raise endpoints.InternalServerErrorException('Multiple Users for %s found.' % (user_id,)) elif users.count() == 1: return UserResponse(msg='User '+user_id, code='OK', data=[userDB_to_user(users.get())]) raise endpoints.NotFoundException('User %s not found.' % (user_id,))
def get_user(self): userCookie = self.request.cookies.get('user_id') if userCookie: user_id, hash_val = userCookie.split("|") users = db.GqlQuery("SELECT * FROM User WHERE __key__ = KEY('User', %s)" % int(user_id)) if users: user = users.get() if user: if valid_pw(user.username, user.password, hash_val): return user_id else: return none
def get(self, key): self.response.headers.add_header('Access-Control-Allow-Origin', '*') logging.info('get submit') users = User.all() users.filter('iden =', key) u = users.get() if not u: self.response.out.write('No user found') return currTime = datetime.datetime.now() startTime = u.start endTime = u.end startTime = datetime.datetime(currTime.year, currTime.month, currTime.day, startTime.hour, startTime.minute, startTime.second) endTime = datetime.datetime(currTime.year, currTime.month, currTime.day, endTime.hour, endTime.minute, endTime.second) if endTime.hour < startTime.hour: # Normal startTime -= datetime.timedelta(days = 1) logging.info(startTime) logging.info(endTime) q = Link.all() q.filter('ended =', True) q.filter('start >=', startTime) #q.filter('end <',endTime) data = [] table_body = '' for l in q: logging.info(endTime) if l.end > endTime: continue new_row = '' new_row += '<td><a href = "http://www.reddit.com%s" target="_blank">%s</a></td>' % (l.url, l.title) new_row += "<td>%s</td>" % l.subreddit table_body+= '<tr>%s</tr>' % new_row with open('indextest.html') as infile: t = infile.read() t = t.replace('*********', table_body) return self.response.out.write(t)
def post(self, error_msg=None): email = self.request.get("email") password = self.request.get("password") if(email.find('@')!=-1): users = User.all().filter('email', email) else: users = User.all().filter('username', email) if users.count() == 0: error_msg = "You have entered an incorrect e-mail address or username." else: user = users.get() if not user.check_password(password): error_msg = "You have entered an incorrect password." else: sessions.Session().login_user(user) self.redirect("/") return template_values = { "email": email, "error": error_msg } self.generate('login.html',template_values)
def authenticate(credential): """ If the given credentials are valid, return a User object. """ if credential is None: return None query = db.Query(User) users = query.filter('username ='******'%s' " % credential[0]) return None users = query.filter('is_active =', True) user = users.get() if user and credential[1] is not None: if (not user.check_password(raw_password = credential[1])): user = None logging.debug('authenticate: %s' % str(user)) return user
def get(self): args = self.args_to_dict() s = {} self.session = sessions.Session() if self.session['openid_stuff']: try: s = pickle.loads(str(self.session['openid_stuff'])) except: pass consumer = Consumer(s, store.DatastoreStore()) if not consumer: return fetchers.setDefaultFetcher(fetcher.UrlfetchFetcher()) auth_response = consumer.complete(args, self.request.uri) if auth_response.status == 'success': openid = auth_response.getDisplayIdentifier() #when user add openid from profile setting, just return status. if self.session['openid_userid']: user = User.get(self.session['openid_userid']) if user: users = User.all().filter('openids', openid) if users.count() == 0: user.openids += [db.Category(openid.strip().encode('utf8'))] user.put() else: msg = "OpenID had already been attached to another user." if users.count()==1 and users.get() == user: msg = "OpenID had already been attached to you." self.generate('user/user_profile_openid_verify.html', {"status":"fail","msg":msg}) return self.generate('user/user_profile_openid_verify.html', {"status":"success","msg":"Attach OpenID to user successfully."}) return sreg_data = sreg.SRegResponse.fromSuccessResponse(auth_response) users = User.all().filter('openids', openid) if users.count() == 0: user = User() user.openids = [db.Category(openid.strip().encode('utf8'))] if sreg_data: user.username = sreg_data["nickname"] user.fullname = sreg_data["fullname"] user.country = sreg_data["country"] user.birthday = datetime.datetime.strptime(sreg_data["dob"], '%Y-%m-%d') user.gender = sreg_data["gender"] user.language = sreg_data["language"] user.postcode = sreg_data["postcode"] #user.email = sreg_data["email"] else: user.username = openid user.put() self.session.login_user(user) self.redirect('/user') return else: user = users[0] self.session.login_user(user) self.redirect('/') return else: #when user add openid from profile setting, just return status. if self.session['openid_userid']: self.generate('user/user_profile_openid_verify.html', {"status":"fail","msg":"Attach OpenID to user unsuccessfully: OpenID verification failed."}) return self.show_main_page('OpenID verification failed.')
def getUser(email): logging.info(email) users = database.User.all() users.filter('email =', email) return users.get() if users.count(limit=1) else None