def login(request): basept = get_renderer('templates/base.pt').implementation() login_url = resource_url(request.context, request, 'login') referrer = request.url if referrer == login_url: referrer = request.application_url came_from = request.params.get('came_from', referrer) message = '' login = '' password = '' if 'form.submitted' in request.params: login = request.params['login'] password = request.params['password'] user = User.objects.filter(email=login).first() if user is not None and user.password == password: headers = remember(request, login) return HTTPFound(location = came_from, headers = headers) message = 'Failed login' if 'form.registration.submitted' in request.params: #we are in case of new user login = request.params['email'] password = request.params['password'] name = request.params['name'] surname = request.params['surname'] user = User.objects.filter(email=login).first() if user is None: #create a Whisperer User whisperer_url = 'http://whisperer.vincenzo-ampolo.net/user/add' #Using email to add the new user data = urllib.urlencode({'name':login}) req = urllib2.Request(whisperer_url, data) response = simplejson.load(urllib2.urlopen(req)) #Get the user id inside whisperer and store in Milo user = User(email=login, first_name=name, last_name=surname, password=password,whisperer_id=response['id']) user.save() headers = remember(request, login) return HTTPFound(location = came_from, headers = headers) message = 'User already exists' return dict( message = message, url = request.application_url + '/login', came_from = came_from, login = login, password = password, base_pt = basept )
async def http_server(db_connection, shared_obj, config): app = web.Application() user = User(db_connection, shared_obj, config, sendWSMessage) app.add_routes([ web.get('/api/users', user.get), web.get('/api/users/{id}', user.get), web.post('/api/users', user.post), web.put('/api/users/{id}', user.put), web.delete('/api/users/{id}', user.delete), ]) production = Production(db_connection, shared_obj, config, sendWSMessage) app.add_routes([ web.post('/api/production', production.post), web.get('/api/production', production.get), web.get('/api/production/{id}', production.get), web.put('/api/production/{id}', production.put), web.delete('/api/production/{id}', production.delete), ]) printer = Printer(db_connection, shared_obj, config, sendWSMessage) app.add_routes([ web.get('/api/print/{action}', printer.get), web.post('/api/print/{action}', printer.post), web.get('/api/print/{action}/{subaction}', printer.get), web.post('/api/print/{action}/{subaction}', printer.post), web.put('/api/print/{action}/{subaction}', printer.put), web.delete('/api/print/{action}/{subaction}', printer.delete) ]) index = Index(db_connection, shared_obj, config) app.add_routes([ web.get('/', index.get), web.get('/users', index.get), web.get('/weighing', index.get), web.get('/templates', index.get), web.get('/production/list', index.get), web.get('/api/{action}', index.get) ]) app.add_routes([ web.static('/', './static'), ]) setup_middlewares(app) runner = web.AppRunner(app, logger=LOGGER) await runner.setup() site = web.TCPSite(runner, '0.0.0.0', 8080) await site.start()
def user_logout(): query_args = { 'token': request.args.get('token', ''), 'fb_id': request.args.get('fb_id', '') } try: user = User.logout(**query_args) result = custom_status.HTTPOk(result=user) except custom_status.CustomStatus as e: result = e except Exception: result = custom_status.InternalServerError() result = result.toDict() resp = jsonify(result) resp.status_code = result['status']['statusCode'] return resp
def user_get(fb_id): """ """ query_args = { 'fb_id': fb_id, # Default message_type can be: 'sent', 'received' or 'all'. 'message_type': request.args.get('deref', 'all') } try: user = User.get(**query_args) result = custom_status.HTTPOk(result=user) except custom_status.CustomStatus as e: result = e except Exception: result = custom_status.InternalServerError() result = result.toDict() resp = jsonify(result) resp.status_code = result['status']['statusCode'] return resp
def user_login(): query_args = { 'token': request.args.get('token', ''), 'expiration': request.args.get('expiration', fb_access_token_expire), 'fb_id': request.args.get('fb_id', ''), # TODO(ajen): # 1. Update user with real gcm id. 'gcm_id': request.args.get('gcm_id', 'tmp_gcm_id') } try: user = User.login(**query_args) result = custom_status.HTTPOk(result=user) except custom_status.CustomStatus as e: result = e except Exception: result = custom_status.InternalServerError() result = result.toDict() resp = jsonify(result) resp.status_code = result['status']['statusCode'] return resp
def user_info(self, user_id): (status, data) = self.get_data('users/%s.json' % user_id) if status: return User(data, api=self)
def printSeperator(text): le = 32 - ( len(text) // 2 ) dwn = "-v-v-v-" out = '-'*le + dwn + ' ' + text + ' ' + dwn + '-'*le while out < 80: out += '-' # while out > 80: # out = out[:-1] print(out) return None resource = NHSSL() john_d = User('jdoe', hashlib.sha1('Password1'.encode('UTF-8')).digest(), 65535, 'John', 'Doe', '*****@*****.**', '555-111-2323', 2014, 2010) john_d.__parent__ = resource["users"] resource["jdoe"] = john_d resource["users"]["jdoe"] = john_d jane_d = User('janedoe', hashlib.sha1('sphinxcookies'.encode('UTF-8')).digest(), 128034, 'Jane', 'Doe', '*****@*****.**', '555-222-3232', 2015, 2012)