コード例 #1
0
	def set_new_password(self, old_password, new_password):
		if get_decrypted_password(self.doctype, self.name, 'password', raise_exception=True) == old_password:
			set_encrypted_password(self.doctype, self.name, new_password, 'password')
			self.reload()
			return True
		else:
			frappe.msgprint(_("Old Password is not valid, please fill correct Old Password to Set New Password.!!"))
			return False
コード例 #2
0
	def _save_passwords(self):
		'''Save password field values in __Auth table'''
		if self.flags.ignore_save_passwords:
			return

		for df in self.meta.get('fields', {'fieldtype': ('=', 'Password')}):
			new_password = self.get(df.fieldname)
			if new_password and not self.is_dummy_password(new_password):
				# is not a dummy password like '*****'
				set_encrypted_password(self.doctype, self.name, new_password, df.fieldname)

				# set dummy password like '*****'
				self.set(df.fieldname, '*'*len(new_password))
コード例 #3
0
ファイル: base_document.py プロジェクト: Dattatech/frappetest
	def _save_passwords(self):
		'''Save password field values in __Auth table'''
		if self.flags.ignore_save_passwords:
			return

		for df in self.meta.get('fields', {'fieldtype': 'Password'}):
			new_password = self.get(df.fieldname)
			if new_password and not self.is_dummy_password(new_password):
				# is not a dummy password like '*****'
				set_encrypted_password(self.doctype, self.name, new_password, df.fieldname)

				# set dummy password like '*****'
				self.set(df.fieldname, '*'*len(new_password))
コード例 #4
0
def execute():
    if '__OldAuth' not in frappe.db.get_tables():
        frappe.db.sql_ddl('''alter table `__Auth` rename `__OldAuth`''')

    create_auth_table()

    # user passwords
    frappe.db.sql(
        '''insert ignore into `__Auth` (doctype, name, fieldname, `password`)
		(select 'User', user, 'password', `password` from `__OldAuth`)''')

    frappe.db.commit()

    # other password fields
    for doctype in frappe.db.sql_list(
            '''select distinct parent from `tabDocField`
		where fieldtype="Password" and parent != "User"'''):

        frappe.reload_doctype(doctype)
        meta = frappe.get_meta(doctype)

        for df in meta.get('fields', {'fieldtype': 'Password'}):
            if meta.issingle:
                password = frappe.db.get_value(doctype, doctype, df.fieldname)
                if password:
                    set_encrypted_password(doctype,
                                           doctype,
                                           password,
                                           fieldname=df.fieldname)
                    frappe.db.set_value(doctype, doctype, df.fieldname,
                                        '*' * len(password))

            else:
                for d in frappe.db.sql(
                        '''select name, `{fieldname}` from `tab{doctype}`
					where `{fieldname}` is not null'''.format(fieldname=df.fieldname,
                                               doctype=doctype),
                        as_dict=True):

                    set_encrypted_password(doctype,
                                           d.name,
                                           d.get(df.fieldname),
                                           fieldname=df.fieldname)

                frappe.db.sql(
                    '''update `tab{doctype}` set `{fieldname}`=repeat("*", char_length(`{fieldname}`))'''
                    .format(doctype=doctype, fieldname=df.fieldname))

            frappe.db.commit()

    frappe.db.sql_ddl('''drop table `__OldAuth`''')
コード例 #5
0
def reset_pin():
    pwd, apwd = None, None
    if frappe.session.user != "Guest":
        pwd = frappe.form_dict.get('pwd')
        apwd = frappe.form_dict.get('apwd')

    if pwd and apwd:
        set_encrypted_password("User",
                               frappe.session.user,
                               pwd,
                               fieldname="pin")
        frappe.db.commit()
        return "SUCCESS"
    else:
        raise frappe.ValidationError(
            "Passwords does not match or key is missing")
コード例 #6
0
    def _save_passwords(self):
        """Save password field values in __Auth table"""
        from frappe.utils.password import set_encrypted_password

        if self.flags.ignore_save_passwords is True:
            return

        for df in self.meta.get('fields', {'fieldtype': ('=', 'Password')}):
            if self.flags.ignore_save_passwords and df.fieldname in self.flags.ignore_save_passwords:
                continue
            new_password = self.get(df.fieldname)
            if new_password and not self.is_dummy_password(new_password):
                # is not a dummy password like '*****'
                set_encrypted_password(self.doctype, self.name, new_password,
                                       df.fieldname)

                # set dummy password like '*****'
                self.set(df.fieldname, '*' * len(new_password))
コード例 #7
0
ファイル: base_document.py プロジェクト: erpnext-tm/frappe
	def _save_passwords(self):
		"""Save password field values in __Auth table"""
		from frappe.utils.password import remove_encrypted_password, set_encrypted_password

		if self.flags.ignore_save_passwords is True:
			return

		for df in self.meta.get("fields", {"fieldtype": ("=", "Password")}):
			if self.flags.ignore_save_passwords and df.fieldname in self.flags.ignore_save_passwords:
				continue
			new_password = self.get(df.fieldname)

			if not new_password:
				remove_encrypted_password(self.doctype, self.name, df.fieldname)

			if new_password and not self.is_dummy_password(new_password):
				# is not a dummy password like '*****'
				set_encrypted_password(self.doctype, self.name, new_password, df.fieldname)

				# set dummy password like '*****'
				self.set(df.fieldname, "*" * len(new_password))
コード例 #8
0
ファイル: update_auth.py プロジェクト: Dattatech/frappetest
def execute():
	if '__OldAuth' not in frappe.db.get_tables():
		frappe.db.sql_ddl('''alter table `__Auth` rename `__OldAuth`''')

	create_auth_table()

	# user passwords
	frappe.db.sql('''insert ignore into `__Auth` (doctype, name, fieldname, `password`)
		(select 'User', user, 'password', `password` from `__OldAuth`)''')

	frappe.db.commit()

	# other password fields
	for doctype in frappe.db.sql_list('''select distinct parent from `tabDocField`
		where fieldtype="Password" and parent != "User"'''):

		frappe.reload_doctype(doctype)
		meta = frappe.get_meta(doctype)

		for df in meta.get('fields', {'fieldtype': 'Password'}):
			if meta.issingle:
				password = frappe.db.get_value(doctype, doctype, df.fieldname)
				if password:
					set_encrypted_password(doctype, doctype, password, fieldname=df.fieldname)
					frappe.db.set_value(doctype, doctype, df.fieldname, '*'*len(password))

			else:
				for d in frappe.db.sql('''select name, `{fieldname}` from `tab{doctype}`
					where `{fieldname}` is not null'''.format(fieldname=df.fieldname, doctype=doctype), as_dict=True):

					set_encrypted_password(doctype, d.name, d.get(df.fieldname), fieldname=df.fieldname)

				frappe.db.sql('''update `tab{doctype}` set `{fieldname}`=repeat("*", char_length(`{fieldname}`))'''
					.format(doctype=doctype, fieldname=df.fieldname))

			frappe.db.commit()

	frappe.db.sql_ddl('''drop table `__OldAuth`''')
コード例 #9
0
ファイル: google_calendar.py プロジェクト: erpnext-tm/frappe
def sync_events_from_google_calendar(g_calendar, method=None):
	"""
	Syncs Events from Google Calendar in Framework Calendar.
	Google Calendar returns nextSyncToken when all the events in Google Calendar are fetched.
	nextSyncToken is returned at the very last page
	https://developers.google.com/calendar/v3/sync
	"""
	google_calendar, account = get_google_calendar_object(g_calendar)

	if not account.pull_from_google_calendar:
		return

	sync_token = account.get_password(fieldname="next_sync_token", raise_exception=False) or None
	events = frappe._dict()
	results = []
	while True:
		try:
			# API Response listed at EOF
			events = (
				google_calendar.events()
				.list(
					calendarId=account.google_calendar_id,
					maxResults=2000,
					pageToken=events.get("nextPageToken"),
					singleEvents=False,
					showDeleted=True,
					syncToken=sync_token,
				)
				.execute()
			)
		except HttpError as err:
			msg = _("Google Calendar - Could not fetch event from Google Calendar, error code {0}.").format(
				err.resp.status
			)

			if err.resp.status == 410:
				set_encrypted_password("Google Calendar", account.name, "", "next_sync_token")
				frappe.db.commit()
				msg += " " + _("Sync token was invalid and has been resetted, Retry syncing.")
				frappe.msgprint(msg, title="Invalid Sync Token", indicator="blue")
			else:
				frappe.throw(msg)

		for event in events.get("items", []):
			results.append(event)

		if not events.get("nextPageToken"):
			if events.get("nextSyncToken"):
				account.next_sync_token = events.get("nextSyncToken")
				account.save()
			break

	for idx, event in enumerate(results):
		frappe.publish_realtime(
			"import_google_calendar", dict(progress=idx + 1, total=len(results)), user=frappe.session.user
		)

		# If Google Calendar Event if confirmed, then create an Event
		if event.get("status") == "confirmed":
			recurrence = None
			if event.get("recurrence"):
				try:
					recurrence = event.get("recurrence")[0]
				except IndexError:
					pass

			if not frappe.db.exists("Event", {"google_calendar_event_id": event.get("id")}):
				insert_event_to_calendar(account, event, recurrence)
			else:
				update_event_in_calendar(account, event, recurrence)
		elif event.get("status") == "cancelled":
			# If any synced Google Calendar Event is cancelled, then close the Event
			frappe.db.set_value(
				"Event",
				{
					"google_calendar_id": account.google_calendar_id,
					"google_calendar_event_id": event.get("id"),
				},
				"status",
				"Closed",
			)
			frappe.get_doc(
				{
					"doctype": "Comment",
					"comment_type": "Info",
					"reference_doctype": "Event",
					"reference_name": frappe.db.get_value(
						"Event",
						{
							"google_calendar_id": account.google_calendar_id,
							"google_calendar_event_id": event.get("id"),
						},
						"name",
					),
					"content": " - Event deleted from Google Calendar.",
				}
			).insert(ignore_permissions=True)
		else:
			pass

	if not results:
		return _("No Google Calendar Event to sync.")
	elif len(results) == 1:
		return _("1 Google Calendar Event synced.")
	else:
		return _("{0} Google Calendar Events synced.").format(len(results))