コード例 #1
0
	def create_user(self, data, ):
		if 'email' in data:
			alias = data.get('name','')
			email = data.get('email','')

			if 'plan_name' in data:
				plan_name = data['plan_name']

			u = User.create_user(alias=alias, email=email)
		else:
			u = {'error': 'Email has not been supplied'}

		msg = self.tpl
		if 'error' in u:
			msg['status'] = 'error'
			msg['errormessage'] = u['error']
		else:
			u = User.get_user(profile_id=u['profile_id'])

			msg['status'] = 'ok'
			msg['payload'] = {'name': u['alias']}
			
			self._send_confirmation_email(secret_key=u.get('secret_key',''),alias=alias,email=email)

		return HttpResponse( bsondumps(msg), content_type='application/json' )
コード例 #2
0
ファイル: views.py プロジェクト: valerashylin/webscraper
	def get_user(self, profile_id='', secret_key=''):
		if profile_id == '' and secret_key == '':
			if not self.u:
				session_usr = self.request.session['user']
				self.u = User(session_usr)
			else:
				pass
		else:
			self.u = User.get_user(profile_id=profile_id, secret_key=secret_key)

		return self.u
コード例 #3
0
	def get_user_plan(self, params, *args, **kwargs):
		uid = params['userid']
		
		msg = self.tpl

		u = User.get_user(profile_id=uid)
		if 'error'in u:
			msg['status'] = 'error'
			msg['errormessage'] = u['error']
			return HttpResponse( bsondumps(msg), content_type='application/json' )

		mongo_user = u
		plan = User(u).get_user_plan()

		msg['status'] = 'ok'
		msg['payload']['user'] = mongo_user
		msg['payload']['plan'] = plan

		return HttpResponse( bsondumps(msg), content_type='application/json' )
コード例 #4
0
	def get_user_and_plan(self, access_data, *args, **kwargs):
		access_token = access_data.get('access_token', '')

		msg = self.tpl

		if not access_token:
			msg['status'] = 'error'
			msg['errormessage'] = 'Empty access token'
			return HttpResponse( bsondumps(msg), content_type='application/json' )

		url = 'https://graph.facebook.com/me?access_token={access_token}&fields=id,email,gender,link,locale,name,timezone,updated_time,verified'
		url = url.format(access_token=access_token)
		try:
			response = urllib2.urlopen(url)
		except urllib2.HTTPError:
			fb_user={'error': {'message': 'Wrong api token'}}
		except urllib2.URLError as e:
			fb_user = {'error':{'message': 'Could not connect to Facebook'}}
		else:
			# All is fine
			res = response.read()
			fb_user = json.loads(res)

		if 'error' in fb_user:
			msg['status'] = 'error'
			msg['errormessage'] = fb_user['error']['message']
			return HttpResponse( bsondumps(msg), content_type='application/json' )

		u = User.get_user(facebook_user=fb_user)
		if 'error' in u:
			msg['status'] = 'error'
			msg['errormessage'] = u['error']
			return HttpResponse( bsondumps(msg), content_type='application/json' )

		mongo_user = u
		plan = User(mongo_user).get_user_plan()

		msg['status'] = 'ok'
		msg['payload']['user'] = mongo_user
		msg['payload']['plan'] = plan

		return HttpResponse( bsondumps(msg), content_type='application/json' )
コード例 #5
0
	def get_user_plan(self, params, *args, **kwargs):
		secret_key = params.get('secret_key','')
		u = User.get_user(secret_key = secret_key)
		
		msg = self.tpl

		time.sleep(0.1)

		if 'error' in u:
			msg['status'] = 'error'
			msg['errormessage'] = u['error']
			return HttpResponse( bsondumps(msg), content_type='application/json' )

		mongo_user = u
		plan = User(u).get_user_plan()

		msg['status'] = 'ok'
		msg['payload']['user'] = mongo_user
		msg['payload']['plan'] = plan

		return HttpResponse( bsondumps(msg), content_type='application/json' )
コード例 #6
0
	def update_user(self, params, *args, **kwargs):
		uid = params['profile_id']
		
		msg = self.tpl

		u = User.get_user(profile_id=uid)

		if 'error' in u:
			msg['status'] = 'error'
			msg['errormessage'] = u['error']
			return HttpResponse( bsondumps(msg), content_type='application/json' )

		res = User(u).delete()

		if res:
			msg['status'] = 'ok'
			msg['payload']['message'] = "user deleted successfully"
		else:
			msg['status'] = 'error'
			msg['errormessage'] = 'unable to delete the user'

		return HttpResponse( bsondumps(msg), content_type='application/json' )
コード例 #7
0
	def update_user(self, params, *args, **kwargs):
		uid = params['userid']
		data = kwargs['data']
		
		msg = self.tpl
			
		u = User.get_user(profile_id=uid)
		if 'error' in u:
			msg['status'] = 'error'
			msg['errormessage'] = u['error']
			return HttpResponse( bsondumps(msg), content_type='application/json' )

		res = User(u).update_info(data=data)

		if 'error' not in res:
			msg['status'] = 'ok'
			msg['payload']['user'] = u
		else:
			msg['status'] = 'error'
			msg['errormessage'] = res['error']

		return HttpResponse( bsondumps(msg), content_type='application/json' )