Exemple #1
0
def make_jwt(user, expire_on=None, secret=None):
    if not frappe.session.get('sid') or frappe.session.sid == "Guest":
        return
    if not secret:
        secret = frappe.utils.password.get_encryption_key()
    if expire_on and not isinstance(expire_on, frappe.utils.datetime.datetime):
        expire_on = frappe.utils.get_datetime(expire_on)

    id_token_header = {"typ": "jwt", "alg": "HS256"}
    id_token = {"user": user, "ip": frappe.local.request_ip}
    if expire_on:
        id_token['exp'] = int(
            (expire_on -
             frappe.utils.datetime.datetime(1970, 1, 1)).total_seconds())
    token_encoded = jwt.encode(id_token,
                               secret,
                               algorithm='HS256',
                               headers=id_token_header).decode("ascii")
    frappe.flags.jwt = token_encoded

    from frappe.sessions import delete_session
    delete_session(frappe.session.get("sid"),
                   user=user,
                   reason="Session Deleted for JWT")

    return token_encoded
Exemple #2
0
	def logout(self, arg='', user=None):
		if not user: user = frappe.session.user
		self.run_trigger('on_logout')

		if user == frappe.session.user:
			delete_session(frappe.session.sid, user=user, reason="User Manually Logged Out")
			self.clear_cookies()
		else:
			clear_sessions(user)
Exemple #3
0
	def logout(self, arg='', user=None):
		if not user: user = frappe.session.user
		self.run_trigger('on_logout')

		if user == frappe.session.user:
			delete_session(frappe.session.sid)
			self.clear_cookies()
		else:
			clear_sessions(user)
Exemple #4
0
	def logout(self, arg='', user=None):
		if not user: user = frappe.session.user
		self.run_trigger('on_logout')

		if user == frappe.session.user:
			delete_session(frappe.session.sid, user=user, reason="User Manually Logged Out")
			self.clear_cookies()
		else:
			clear_sessions(user)
Exemple #5
0
def logout(*args, **kwargs):
    from frappe.sessions import delete_session, clear_sessions

    token = kwargs.get("decoded")

    qs = kwargs.get("query_strings")
    if qs.get("sessions", None) == "all":
        clear_sessions(token.get("user"), force=True)
        return

    delete_session(token.get("sid"))
    return {"message": "Goodbye!"}