def get_redirect_url(self, *args, **kwargs): # article = get_object_or_404(Article, pk=kwargs['pk']) # article.update_counter() # return super().get_redirect_url(*args, **kwargs) token_storage = TokenStorage(self.request.user) c = OutlookConnection( get_local_key("o365_app_settings.o365_app_client_id"), get_local_key("o365_app_settings.o365_app_secret"), token_storage, ) auth_url = c.get_auth_url() return auth_url
def get_context_data(self, **kwargs): # return super(OutlookAuthResultView, self).get_context_data(**kwargs) # param = retrieve_param(self.request) token_storage = TokenStorage(self.request.user) c = OutlookConnection( get_local_key("o365_app_settings.o365_app_client_id"), get_local_key("o365_app_settings.o365_app_secret"), token_storage, ) token_url = "%s/?%s" % ("https://localhost", self.request.META['QUERY_STRING']) res = c.update_extra_data(token_url) return res
def get_redirect_url(self, *args, **kwargs): # article = get_object_or_404(Article, pk=kwargs['pk']) # article.update_counter() # return super().get_redirect_url(*args, **kwargs) token_storage = LoginTokenStorage(self.request.user) c = OutlookConnection( get_local_key("o365_login_app_settings.o365_app_client_id"), get_local_key("o365_login_app_settings.o365_app_secret"), token_storage, redirect_url='https://%s/django_outlook/login_result/' % self.request.get_host() ) auth_url = c.get_auth_url() return auth_url
def get_context_data(self, **kwargs): # return super(OutlookLoginResultView, self).get_context_data(**kwargs) # param = retrieve_param(self.request) token_storage = LoginTokenStorage(self.request.user) c = OutlookConnection( get_local_key("o365_login_app_settings.o365_app_client_id"), get_local_key("o365_login_app_settings.o365_app_secret"), token_storage, redirect_url='https://%s/django_outlook/login_result/' % self.request.get_host() ) token_url = "%s/?%s" % ("https://localhost", self.request.META['QUERY_STRING']) param = retrieve_param(self.request) res = c.update_extra_data(token_url, param["state"]) return res
def __init__(self, mailbox_name_pattern=None, token_storage=None, target_mail=None): """ :param mailbox_name_pattern: not used, this parameter is only kept for be compatible with pywin32 implementation """ super(OutlookReaderForO365, self).__init__() o365_app_client_id = get_local_key("o365_login_app_settings.o365_app_client_id") o365_app_secret = get_local_key("o365_login_app_settings.o365_app_secret") self.connection = OutlookConnection(client_id=o365_app_client_id, client_secret=o365_app_secret, token_storage=token_storage, ) self.connection.load_token() self.target_mail = target_mail self.fluent_inbox = FluentInboxAdv(connection=self.connection, o365_url_generator=O365UrlGenerator(target_mail))
def init_evernote(self): self.auth_token = get_local_key("evernote_key.auth_token", "django_local_apps") # Real applications authenticate with Evernote using OAuth, but for the # purpose of exploring the API, you can get a developer token that allows # you to access your own Evernote account. To get a developer token, visit # https://sandbox.evernote.com/api/DeveloperToken.action if self.auth_token == "your developer token": print "Please fill in your developer token" print "To get a developer token, visit " \ "https://sandbox.evernote.com/api/DeveloperToken.action" exit(1) # Initial development is performed on our sandbox server. To use the production # service, change sandbox=False and replace your # developer token above with a token from # https://www.evernote.com/api/DeveloperToken.action client = EvernoteClient(token=self.auth_token, sandbox=False ) # Ref: https://github.com/evernote/evernote-sdk-python/issues/39 client.service_host = 'app.yinxiang.com' self.user_store = client.get_user_store() version_ok = self.user_store.checkVersion( "Evernote EDAMTest (Python)", UserStoreConstants.EDAM_VERSION_MAJOR, UserStoreConstants.EDAM_VERSION_MINOR ) print "Is my Evernote API version up to date? ", str(version_ok) print "" if not version_ok: exit(1) self.note_store = client.get_note_store()
def __init__(self, client_id, client_secret, token_storage, redirect_url="https://outlook.office365.com/owa/"): super(OutlookConnection, self).__init__() self.redirect_url = redirect_url self.client_id = client_id self.client_secret = client_secret self.client_id = self.client_id self.client_secret = self.client_secret self.token_storage = token_storage self.proxy_dict = None self.oauth = None # self.auth = None # Proxy call is required only if you are behind proxy self.set_proxy(url=get_local_key("proxy_setting.http_proxy_host"), port=8080, username=get_local_key("laptop_account.username"), password=get_local_key("laptop_account.password") )
def get_token_from_code(callback_url, expected_state): # Initialize the OAuth client try: from djangoautoconf.local_key_manager import get_local_key app_id = get_local_key("onedrive.client_id") app_secret = get_local_key("onedrive.client_secret") except ImportError: app_id = settings['app_id'] app_secret = settings['app_secret'] aad_auth = OAuth2Session(app_id, state=expected_state, scope=settings['scopes'], redirect_uri=settings['redirect']) token = aad_auth.fetch_token(token_url, client_secret=app_secret, authorization_response=callback_url) return token
def authenticate(self, request): data = retrieve_param(request) if ("password" in data) and ("username" in data): try: if data["password"] == get_local_key("req_auth_key.super_password", 'djangoautoconf.auth'): request.user = User.objects.get(username=data["username"]) request.user.backend = "django.contrib.auth.backends.ModelBackend" return request.user except: pass return None
def get_sign_in_url(): try: from djangoautoconf.local_key_manager import get_local_key app_id = get_local_key("onedrive.client_id") except: app_id = settings['app_id'] # Initialize the OAuth client aad_auth = OAuth2Session(app_id, scope=unicode(settings['scopes']), redirect_uri=settings['redirect']) sign_in_url, state = aad_auth.authorization_url(authorize_url, prompt='login') return sign_in_url, state
def __get_mailbox(self): """ Get the mailbox from outlook. Folder are below mailbox :param mailbox_name: The name of the mailbox, normally it is [email protected] :return: the mailbox for the name """ # target_folder_index = None if self.__mailbox_name_pattern is None: self.__mailbox_name_pattern = get_local_key("outlook_settings.mailbox_name_pattern") for mailbox_number in range(1, 100): # Admin print unicode(self.outlook.Folders.Item(mailbox_number).Name).encode("gbk", "replace") if self.__mailbox_name_pattern in self.outlook.Folders.Item(mailbox_number).Name: # print mailbox_number return self.outlook.Folders.Item(mailbox_number)
# coding=utf-8 # try: # from keys.local_keys.smtp_account import smtp_username, smtp_password # except: # from djangoautoconf.settings_templates.smtp_account_template import smtp_username, smtp_password from djangoautoconf.local_key_manager import get_local_key, ConfigurableAttributeGetter # getter = ConfigurableAttributeGetter("smtp_account") smtp_username = get_local_key("smtp_account.smtp_username") smtp_password = get_local_key("smtp_account.smtp_password") smtp_server = get_local_key("smtp_account.smtp_server") smtp_port = get_local_key("smtp_account.smtp_port") smtp_use_tls = get_local_key("smtp_account.smtp_use_tls") # 邮件配置 EMAIL_HOST = smtp_server # 'smtp.gmail.com' # SMTP地址 EMAIL_PORT = smtp_port # 25 # SMTP端口 EMAIL_HOST_USER = smtp_username # '*****@*****.**' # 我自己的邮箱 EMAIL_HOST_PASSWORD = smtp_password # '******' # 我的邮箱密码 # EMAIL_SUBJECT_PREFIX = u'[CoorCar网]' # 为邮件Subject-line前缀,默认是'[django]' EMAIL_USE_TLS = smtp_use_tls # 与SMTP服务器通信时,是否启动TLS链接(安全链接)。默认是false # 管理员站点 # SERVER_EMAIL = '*****@*****.**' # #The email address that error messages come from, such as those sent to ADMINS and MANAGERS.
from django_auth_ldap.config import LDAPSearch import ldap from djangoautoconf.local_key_manager import ConfigurableAttributeGetter, get_local_key AUTHENTICATION_BACKENDS = ( 'djangoautoconf.auth.ldap_backend_wrapper.LDAPBackendWrapper', #'django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend', ) # !!!!!Do not uncomment the following codes, it is just used to find the LDAPBackend module. Uncomment # the following line will cause django mis configure and it will not start. # from django_auth_ldap.backend import LDAPBackend getter = ConfigurableAttributeGetter("ldap_settings", "webmanager.keys_defaults") AUTH_LDAP_SERVER_URI = getter.get_attr("auth_ldap_server_uri") # ldap.set_option(ldap.OPT_DEBUG_LEVEL, 4095) AUTH_LDAP_BIND_PASSWORD = get_local_key("ldap_settings.ldap_bind_password") AUTH_LDAP_BIND_DN = get_local_key("ldap_settings.ldap_dn") search_str = getter.get_attr("search_str") AUTH_LDAP_USER_SEARCH = LDAPSearch(search_str, ldap.SCOPE_SUBTREE, "uid=%(user)s")
def __init__(self, full_path, callback=None): self.full_path = full_path self.https_proxy_server = get_local_key("proxy_setting.https_proxy_server", "django_git") self.connectivity_manager = ConnectivityManager() self.sync_msg = None self.call_back = callback
def init_connection(self): username = get_local_key("office365_account.account") password = get_local_key("office365_account.app_password") s = sharepy.connect(self.domain_url+self.site, username=username, password=password) return s
def get_admin_username(): return get_local_key("admin_account.admin_username", "djangoautoconf.keys_default")
def get_admin_password(): return get_local_key("admin_account.admin_password", "djangoautoconf.keys_default")
def add_git_to_path(): folders = get_local_key("git_path.git_folder", "django_git") folders.append('C:\\Program Files (x86)\\Git\\bin') os.environ['PATH'] += ";"+find_app_in_folders(folders, "git.exe")