소스 검색

DocType Social Login Keys, to make it easy for setting up Social Logins. Fixes in Module View for Setup

version-14
Anand Doshi 11 년 전
부모
커밋
2ff4d34fba
11개의 변경된 파일265개의 추가작업 그리고 18개의 파일을 삭제
  1. +13
    -2
      frappe/config/setup.py
  2. +93
    -0
      frappe/config/website.py
  3. +0
    -0
      frappe/core/doctype/social_login_keys/__init__.py
  4. +11
    -0
      frappe/core/doctype/social_login_keys/social_login_keys.py
  5. +98
    -0
      frappe/core/doctype/social_login_keys/social_login_keys.txt
  6. +3
    -3
      frappe/data/sample_site_config.json
  7. +7
    -7
      frappe/templates/pages/login.html
  8. +19
    -4
      frappe/templates/pages/login.py
  9. +1
    -1
      frappe/website/doctype/website_group/website_group.py
  10. +2
    -1
      frappe/website/doctype/website_group/website_group.txt
  11. +18
    -0
      frappe/widgets/moduleview.py

+ 13
- 2
frappe/config/setup.py 파일 보기

@@ -1,4 +1,5 @@
from frappe import _
from frappe.widgets.moduleview import add_setup_section

data = [
{
@@ -28,7 +29,7 @@ data = [
"label": _("User Permission Restrictions"),
"icon": "icon-user",
"description": _("Set Defaults and Restrictions for Users")
}
},
]
},
{
@@ -132,6 +133,11 @@ data = [
"description": _("Install Applications."),
"icon": "icon-download"
},
{
"type": "doctype",
"name": "Social Login Keys",
"description": _("Enter keys to enable login via Facebook, Google, GitHub."),
},
{
"type": "doctype",
"name": "Backup Manager",
@@ -144,4 +150,9 @@ data = [
},
]
}
]
]

def get_data():
out = list(data)
add_setup_section(out, "frappe", "website", _("Website"), "icon-globe")
return out

+ 93
- 0
frappe/config/website.py 파일 보기

@@ -0,0 +1,93 @@
from frappe import _

data = [
{
"label": _("Documents"),
"icon": "icon-star",
"items": [
{
"type": "doctype",
"name": "Web Page",
"description": _("Content web page."),
},
{
"type": "doctype",
"name": "Blog Post",
"description": _("Single Post (article)."),
},
{
"type": "doctype",
"name": "Blogger",
"description": _("Profile of a blog writer."),
},
{
"type": "doctype",
"name": "Website Group",
"description": _("Web Site Forum Page."),
},
{
"type": "doctype",
"name": "Post",
"description": _("List of Web Site Forum's Posts."),
},
{
"type": "doctype",
"name": "Website Slideshow",
"description": _("Embed image slideshows in website pages."),
},
]
},
{
"label": _("Setup"),
"icon": "icon-cog",
"items": [
{
"type": "doctype",
"name": "Website Settings",
"description": _("Setup of top navigation bar, footer and logo."),
},
{
"type": "page",
"name":"sitemap-browser",
"label": _("Sitemap Browser"),
"description": _("View or manage Website Route tree."),
"icon": "icon-sitemap"
},
{
"type": "doctype",
"name": "Style Settings",
"description": _("Setup of fonts and background."),
},
{
"type": "doctype",
"name": "Website Script",
"description": _("Javascript to append to the head section of the page."),
},
{
"type": "doctype",
"name": "Blog Settings",
"description": _("Write titles and introductions to your blog."),
},
{
"type": "doctype",
"name": "Blog Category",
"description": _("Categorize blog posts."),
},
{
"type": "doctype",
"name": "About Us Settings",
"description": _("Settings for About Us Page."),
},
{
"type": "doctype",
"name": "Contact Us Settings",
"description": _("Settings for Contact Us Page."),
},
{
"type": "doctype",
"name": "Website Page Permission",
"description": _("Define read, write, admin permissions for a Website Page."),
},
]
},
]

+ 0
- 0
frappe/core/doctype/social_login_keys/__init__.py 파일 보기


+ 11
- 0
frappe/core/doctype/social_login_keys/social_login_keys.py 파일 보기

@@ -0,0 +1,11 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

# For license information, please see license.txt

from __future__ import unicode_literals
import frappe

class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl

+ 98
- 0
frappe/core/doctype/social_login_keys/social_login_keys.txt 파일 보기

@@ -0,0 +1,98 @@
[
{
"creation": "2014-03-04 08:29:52",
"docstatus": 0,
"modified": "2014-03-04 08:47:32",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "DocType",
"document_type": "System",
"icon": "icon-signin",
"issingle": 1,
"module": "Core",
"name": "__common__"
},
{
"doctype": "DocField",
"name": "__common__",
"parent": "Social Login Keys",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0
},
{
"create": 1,
"doctype": "DocPerm",
"name": "__common__",
"parent": "Social Login Keys",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"role": "System Manager",
"write": 1
},
{
"doctype": "DocType",
"name": "Social Login Keys"
},
{
"doctype": "DocField",
"fieldname": "facebook",
"fieldtype": "Section Break",
"label": "Facebook"
},
{
"doctype": "DocField",
"fieldname": "facebook_client_id",
"fieldtype": "Data",
"label": "Facebook Client ID"
},
{
"doctype": "DocField",
"fieldname": "facebook_client_secret",
"fieldtype": "Data",
"label": "Facebook Client Secret"
},
{
"doctype": "DocField",
"fieldname": "google",
"fieldtype": "Section Break",
"label": "Google"
},
{
"doctype": "DocField",
"fieldname": "google_client_id",
"fieldtype": "Data",
"label": "Google Client ID"
},
{
"doctype": "DocField",
"fieldname": "google_client_secret",
"fieldtype": "Data",
"label": "Google Client Secret"
},
{
"doctype": "DocField",
"fieldname": "github",
"fieldtype": "Section Break",
"label": "GitHub"
},
{
"doctype": "DocField",
"fieldname": "github_client_id",
"fieldtype": "Data",
"label": "GitHub Client ID"
},
{
"doctype": "DocField",
"fieldname": "github_client_secret",
"fieldtype": "Data",
"label": "GitHub Client Secret"
},
{
"doctype": "DocPerm"
}
]

+ 3
- 3
frappe/data/sample_site_config.json 파일 보기

@@ -15,15 +15,15 @@
"use_ssl": 0,
"auto_email_id": "hello@example.com",
"google_sign_in": {
"google_login": {
"client_id": "google_client_id",
"client_secret": "google_client_secret"
},
"github_sign_in": {
"github_login": {
"client_id": "github_client_id",
"client_secret": "github_client_secret"
},
"facebook_sign_in": {
"facebook_login": {
"client_id": "facebook_client_id",
"client_secret": "facebook_client_secret"
}

+ 7
- 7
frappe/templates/pages/login.html 파일 보기

@@ -13,21 +13,21 @@
</label> -->
<br>
<button class="btn btn-lg btn-primary btn-block btn-login" type="submit">{{ _("Sign in") }}</button>
{%- if third_party_sign_in -%}
{%- if social_login -%}
<p class="text-muted text-center" style="margin: 10px;">or login via</p>
<p class="text-muted text-center" style="margin: 10px;">
{%- if facebook_sign_in is defined %}
<a href="{{ facebook_sign_in }}" class="btn btn-lg btn-block btn-primary btn-facebook">
{%- if facebook_login is defined %}
<a href="{{ facebook_login }}" class="btn btn-lg btn-block btn-primary btn-facebook">
<i class="icon-facebook-sign"></i> {{ _("Facebook") }}</a>
{%- endif -%}
{%- if google_sign_in is defined %}
<a href="{{ google_sign_in }}" class="btn btn-lg btn-block btn-primary btn-google">
{%- if google_login is defined %}
<a href="{{ google_login }}" class="btn btn-lg btn-block btn-primary btn-google">
<i class="icon-google-plus-sign"></i> {{ _("Google") }}</a>
{%- endif -%}
{%- if github_sign_in is defined %}
<a href="{{ github_sign_in }}" class="btn btn-lg btn-block btn-primary btn-github">
{%- if github_login is defined %}
<a href="{{ github_login }}" class="btn btn-lg btn-block btn-primary btn-github">
<i class="icon-github-sign"></i> {{ _("GitHub") }}</a>
{%- endif -%}
</p>


+ 19
- 4
frappe/templates/pages/login.py 파일 보기

@@ -16,8 +16,8 @@ def get_context(context):
for provider in ("google", "github", "facebook"):
if get_oauth_keys(provider):
context["{provider}_sign_in".format(provider=provider)] = get_oauth2_authorize_url(provider)
context["third_party_sign_in"] = True
context["{provider}_login".format(provider=provider)] = get_oauth2_authorize_url(provider)
context["social_login"] = True
return context
@@ -77,8 +77,23 @@ oauth2_providers = {
}

def get_oauth_keys(provider):
# get client_id and client_secret from conf
return frappe.conf.get("{provider}_sign_in".format(provider=provider))
"""get client_id and client_secret from database or conf"""
# try conf
keys = frappe.conf.get("{provider}_login".format(provider=provider))

if not keys:
# try database
social = frappe.doc("Social Login Keys", "Social Login Keys")
keys = {}
for fieldname in ("client_id", "client_secret"):
value = social.fields.get("{provider}_{fieldname}".format(provider=provider, fieldname=fieldname))
if not value:
keys = {}
break
keys[fieldname] = value

return keys

def get_oauth2_authorize_url(provider):
flow = get_oauth2_flow(provider)


+ 1
- 1
frappe/website/doctype/website_group/website_group.py 파일 보기

@@ -19,4 +19,4 @@ class DocType(WebsiteGenerator):
clear_cache(website_group=self.doc.name)
def after_insert(self):
clear_cache(path=self.doc.parent_website_route)
clear_cache(path=self.doc.parent_website_route)

+ 2
- 1
frappe/website/doctype/website_group/website_group.txt 파일 보기

@@ -2,7 +2,7 @@
{
"creation": "2014-01-29 15:57:42",
"docstatus": 0,
"modified": "2014-03-03 14:52:19",
"modified": "2014-03-04 09:36:30",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -22,6 +22,7 @@
"permlevel": 0
},
{
"cancel": 0,
"create": 1,
"delete": 1,
"doctype": "DocPerm",


+ 18
- 0
frappe/widgets/moduleview.py 파일 보기

@@ -73,6 +73,24 @@ def build_standard_config(module):
def get_config(app, module):
config = frappe.get_module("{app}.config.{module}".format(app=app, module=module))
return config.get_data() if hasattr(config, "get_data") else config.data

def add_setup_section(config, app, module, label, icon):
try:
setup_section = get_setup_section(app, module, label, icon)
if setup_section:
config.append(setup_section)
except ImportError:
pass

def get_setup_section(app, module, label, icon):
config = get_config(app, module)
for section in config:
if section.get("label")==_("Setup"):
return {
"label": label,
"icon": icon,
"items": section["items"]
}
def get_doctypes(data):
doctypes = []


불러오는 중...
취소
저장