Пример #1
0
	def start(self):
		"""start a new session"""
		import os
		import webnotes
		import webnotes.utils
		
		# generate sid
		if webnotes.login_manager.user=='Guest':
			sid = 'Guest'
		else:
			sid = webnotes.generate_hash()
		
		self.data['user'] = webnotes.login_manager.user
		self.data['sid'] = sid
		self.data['data']['user'] = webnotes.login_manager.user
		self.data['data']['session_ip'] = os.environ.get('REMOTE_ADDR')
		self.data['data']['last_updated'] = webnotes.utils.now()
		self.data['data']['session_expiry'] = self.get_expiry_period()

		# get ipinfo
		if webnotes.conn.get_global('get_ip_info'):
			self.get_ipinfo()
		
		# insert session
		webnotes.conn.begin()
		self.insert_session_record()

		# update profile
		webnotes.conn.sql("""UPDATE tabProfile SET last_login = '******', last_ip = '%s' 
			where name='%s'""" % (webnotes.utils.now(), webnotes.remote_ip, self.data['user']))
		webnotes.conn.commit()
		
		# set cookies to write
		webnotes.session = self.data
		webnotes.cookie_manager.set_cookies()
Пример #2
0
	def start(self):
		"""start a new session"""		
		# generate sid
		if self.user=='Guest':
			sid = 'Guest'
		else:
			sid = webnotes.generate_hash()
		
		self.data['user'] = self.user
		self.data['sid'] = sid
		self.data['data']['user'] = self.user
		self.data['data']['session_ip'] = webnotes.get_request_header('REMOTE_ADDR')
		if self.user != "Guest":
			self.data['data']['last_updated'] = webnotes.utils.now()
			self.data['data']['session_expiry'] = self.get_expiry_period()
		self.data['data']['session_country'] = get_geo_ip_country(webnotes.get_request_header('REMOTE_ADDR'))
		
		# insert session
		if self.user!="Guest":
			webnotes.conn.begin()
			self.insert_session_record()

			# update profile
			webnotes.conn.sql("""UPDATE tabProfile SET last_login = '******', last_ip = '%s' 
				where name='%s'""" % (webnotes.utils.now(), webnotes.get_request_header('REMOTE_ADDR'), self.data['user']))
			webnotes.conn.commit()		
Пример #3
0
    def start(self):
        """start a new session"""
        import os
        import webnotes
        import webnotes.utils

        # generate sid
        if webnotes.login_manager.user == 'Guest':
            sid = 'Guest'
        else:
            sid = webnotes.generate_hash()

        self.data['user'] = webnotes.login_manager.user
        self.data['sid'] = sid
        self.data['data']['user'] = webnotes.login_manager.user
        self.data['data']['session_ip'] = os.environ.get('REMOTE_ADDR')
        self.data['data']['last_updated'] = webnotes.utils.now()
        self.data['data']['session_expiry'] = self.get_expiry_period()
        self.data['data']['session_country'] = get_geo_ip_country(
            os.environ.get('REMOTE_ADDR'))

        # insert session
        webnotes.conn.begin()
        self.insert_session_record()

        # update profile
        webnotes.conn.sql(
            """UPDATE tabProfile SET last_login = '******', last_ip = '%s' 
			where name='%s'""" %
            (webnotes.utils.now(), webnotes.remote_ip, self.data['user']))
        webnotes.conn.commit()

        # set cookies to write
        webnotes.session = self.data
Пример #4
0
	def start(self):
		"""start a new session"""
		import os
		import webnotes
		import webnotes.utils
		
		# generate sid
		if webnotes.login_manager.user=='Guest':
			sid = 'Guest'
		else:
			sid = webnotes.generate_hash()
		
		self.data['user'] = webnotes.login_manager.user
		self.data['sid'] = sid
		self.data['data']['session_ip'] = os.environ.get('REMOTE_ADDR');

		# get ipinfo
		if webnotes.conn.get_global('get_ip_info'):
			self.get_ipinfo()
		
		# insert session
		self.insert_session_record()

		# update profile
		webnotes.conn.sql("""UPDATE tabProfile SET last_login = '******', last_ip = '%s' 
			where name='%s'""" % (webnotes.utils.now(), webnotes.remote_ip, self.data['user']))

		# set cookies to write
		webnotes.session = self.data
		webnotes.cookie_manager.set_cookies()
Пример #5
0
    def start(self):
        """start a new session"""
        import os
        import webnotes
        import webnotes.utils

        # generate sid
        if webnotes.login_manager.user == "Guest":
            sid = "Guest"
        else:
            sid = webnotes.generate_hash()

        self.data["user"] = webnotes.login_manager.user
        self.data["sid"] = sid
        self.data["data"]["user"] = webnotes.login_manager.user
        self.data["data"]["session_ip"] = os.environ.get("REMOTE_ADDR")
        self.data["data"]["last_updated"] = webnotes.utils.now()
        self.data["data"]["session_expiry"] = self.get_expiry_period()
        self.data["data"]["session_country"] = get_geo_ip_country(os.environ.get("REMOTE_ADDR"))

        # insert session
        webnotes.conn.begin()
        self.insert_session_record()

        # update profile
        webnotes.conn.sql(
            """UPDATE tabProfile SET last_login = '******', last_ip = '%s' 
			where name='%s'"""
            % (webnotes.utils.now(), webnotes.remote_ip, self.data["user"])
        )
        webnotes.conn.commit()

        # set cookies to write
        webnotes.session = self.data
Пример #6
0
def write_file(content, files_path):
    """write file to disk with a random name (to compare)"""
    # create account folder (if not exists)
    webnotes.create_folder(files_path)
    fname = os.path.join(files_path, webnotes.generate_hash())

    # write the file
    with open(fname, 'w+') as f:
        f.write(content)

    return fname
def write_file(content):
	"""write file to disk with a random name (to compare)"""
	# create account folder (if not exists)
	webnotes.create_folder(get_files_path())
	fname = os.path.join(get_files_path(), webnotes.generate_hash())

	# write the file
	with open(fname, 'w+') as f:
		f.write(content)

	return fname	
Пример #8
0
    def reset_app_html(self):
        import webnotes

        if os.path.exists("public/app.html"):
            os.remove("public/app.html")

        with open('lib/public/html/app.html', 'r') as app_html:
            data = app_html.read()
            data = data % {"_version_number": webnotes.generate_hash()}
            with open('public/app.html', 'w') as new_app_html:
                new_app_html.write(data)
Пример #9
0
	def reset_app_html(self):
		import webnotes

		if os.path.exists("public/app.html"):
			os.remove("public/app.html")
					
		with open('lib/public/html/app.html', 'r') as app_html:
			data = app_html.read()
			data = data % {"_version_number": webnotes.generate_hash() }
			with open('public/app.html', 'w') as new_app_html:
				new_app_html.write(data)
Пример #10
0
	def reset_app_html(self):
		import webnotes

		if os.path.exists("public/app.html"):
			os.remove("public/app.html")
		
		splash = ""
		if os.path.exists("public/app/images/splash.svg"):
			with open("public/app/images/splash.svg") as splash_file:
				splash = splash_file.read()
		
		with open('lib/public/html/app.html', 'r') as app_html:
			data = app_html.read()
			data = data % {
				"_version_number": webnotes.generate_hash(),
				"splash": splash
			}
			with open('public/app.html', 'w') as new_app_html:
				new_app_html.write(data)
Пример #11
0
    def reset_app_html(self):
        import webnotes

        if os.path.exists("public/app.html"):
            os.remove("public/app.html")

        splash = ""
        if os.path.exists("public/app/images/splash.svg"):
            with open("public/app/images/splash.svg") as splash_file:
                splash = splash_file.read()

        with open('lib/public/html/app.html', 'r') as app_html:
            data = app_html.read()
            data = data % {
                "_version_number": webnotes.generate_hash(),
                "splash": splash
            }
            with open('public/app.html', 'w') as new_app_html:
                new_app_html.write(data)
Пример #12
0
def add_user(data):
	data = json.loads(data)
	
	if not (data.get("id") and data.get("fb_access_token")):
		raise webnotes.ValidationError

	user = data["email"]
		
	if not get_fb_userid(data.get("fb_access_token")):
		# garbage
		raise webnotes.ValidationError
	
	if not webnotes.conn.exists("Profile", user):
		if data.get("birthday"):
			b = data.get("birthday").split("/")
			data["birthday"] = b[2] + "-" + b[0] + "-" + b[1]
		
		profile = webnotes.bean({
			"doctype":"Profile",
			"first_name": data["first_name"],
			"last_name": data["last_name"],
			"email": data["email"],
			"enabled": 1,
			"new_password": webnotes.generate_hash(data["email"]),
			"fb_username": data["username"],
			"fb_userid": data["id"],
			"fb_location": data.get("location", {}).get("name"),
			"fb_hometown": data.get("hometown", {}).get("name"),
			"fb_age_range": data.get("age_range") and "{min}-{max}".format(**data.get("age_range")),
			"birth_date":  data.get("birthday"),
			"fb_bio": data.get("bio"),
			"fb_education": data.get("education") and data.get("education")[-1].get("type"),
			"user_type": "Website User"
		})
		profile.ignore_permissions = True
		profile.get_controller().no_welcome_mail = True
		profile.insert()
	
	webnotes.local.login_manager.user = user
	webnotes.local.login_manager.post_login()